I’m looking at how to change the pitch or speed of an audio file that’s playing. I found some rather old looking topics so I’m seeing if it’s possible yet for both flash and iOS platforms.
sound.extract is not implemented on native targets so I’m not sure if it’s possible to change pitch/speed of audio file without using extensions on ios. As for flash you can check out this http://blog.andre-michelle.com/2009/pitch-mp3/
You’d have to rewrite as3 to haxe but it’s nothing difficult (change ints to Ints etc.).
Bummer. Thanks for the info man!
In the legacy target, there’s a hidden “pitch” value in the SoundChannel, I believe, which should work on OpenAL targets
Thanks for the response,
More than likely going to sound like a major noob here but how would I use that pitch value to change all the game sounds at once? Also will this method work on both Flash and iOS?
Sorry, going through the process of teaching myself how to do this.
After you call
sound.play it gives you a
SoundChannel object. This can be stopped, or can be channged to a new sound transform. If you want to control all playing sounds, you will need to register each sound channel when it is created into a list of kind so you can loop through them all later.
OpenAL should be used everywhere but Flash or HTML5, Flash has no pitch shifting without generating audio dynamically (which gets more complex)
How can I access the hidden “pitch” value from an external class? the set and get pitch functions are declared as “private” so they are not visible outside of the SoundChanel class.
#if lime_legacy soundChannel.pitch = 1; #end
For future reference: when you see something like “
function set_xyz(value),” check for a variable declared as “
public var xyz(get, set).” Assigning to the latter will call the
For more information, read this.
Thanks. Didn’t knew I had to enclose it into a “if lime_legacy” test. Actually I thought that by explicitly importing the legacy version of Soundchannel I would automatically have access to the pitch variable. But I doesn’t seems so:
source/MySound.hx:620: characters 2-16 : openfl._legacy.media.SoundChannel has no field pitch
with the lime_legacy test it doesn’t work either though. Even if there is no more error at compilation, it do not enter into the if block (I use HaxeFlixel that use openfl legacy so I thought it should). I put a trace inside the if block and outside it and only the outside trace is printed.
So how can I access the pitch value of SoundChannel using haxeflixel?
Are you running in legacy? It won’t work in HTML5, Flash or when not using -Dlegacy
Yes I am using legacy (Haxeflixel does by default).
However I was testing in flash (quicker to compile than for native targets), so it seems to be the issue. I thought it would be working on all targets as long as I use legacy openfl…
I would compile it on native target and see if it works (luckily my game is meant to be played on mobiles, so not really problematic if it isn’t working on flash, even if it would be usefull for quick tests )
“lime_legacy” is only meant to be defined on native, if it’s being defined on Flash, perhaps we could help adjust the HaxeFlixel include.xml, so we can prevent it from appearing in Flash or HTML5 targets