Advertisement
matrefeytontias

Game-breaking pitch shifting

Nov 26th, 2016
3,179
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Haxe 0.83 KB | None | 0 0
  1. import com.haxepunk.Sfx;
  2. import lime.audio.openal.AL;
  3.  
  4. @:access(lime.audio.AudioSource)
  5. @:access(lime._backend.native.NativeAudioSource)
  6. @:access(openfl.media.SoundChannel)
  7. class LBSfx extends Sfx
  8. {
  9.     public function setPitch(v:Float) : Bool
  10.     {
  11.         #if (html5 || js)
  12.         return false;
  13.         #elseif flash
  14.         return false;
  15.         #else
  16.         var h = _channel.__source.backend.handle;
  17.         // This crashes the game on Scene.update()
  18.         // It doesn't have to be called, it just has to exist somewhere in the code (ie be compiled)
  19.         AL.sourcef(h, AL.PITCH, v);
  20.         return true;
  21.         #end
  22.     }
  23.    
  24.     public function getPitch() : Float
  25.     {
  26.         #if (html5 || js)
  27.         return 1.;
  28.         #elseif flash
  29.         return 1.;
  30.         #else // sys
  31.         var h = _channel.__source.backend.handle;
  32.         // same here
  33.         return AL.getSourcef(h, AL.PITCH);
  34.         #end
  35.     }
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement