Page 1 of 1

Modifying sound

Posted: Sat Sep 17, 2016 4:40 pm
by georgeprosser
Is it possible to change the pitch of a sound without changing its speed?

Is it possible to change the speed of a sound without changing its pitch?

Re: Modifying sound

Posted: Sat Sep 17, 2016 4:52 pm
by pgimeno
Short answer: no.

Long answer: LÖVE doesn't come with the audio processing library needed for that. See https://en.wikipedia.org/wiki/Audio_tim ... dification for what it requires. There may exist a multi-platform external library that does it but I'm not aware of it.

Edit: If you just want to pre-generate sounds and include them in your LÖVE file, Audacity and SoX do that.

Edit 2: Wait, SoX itself comes also as a library. Maybe you can look into using it with ffi. Here are the docs: http://sox.sourceforge.net/libsox.html

Re: Modifying sound

Posted: Sat Sep 17, 2016 5:11 pm
by zorg
Medium sized answer: Depending on the file format you're using for audio, you might have an intermittent choice; if it's not a steam-like source, like mp3, ogg, wav or similar formats, but a notational kind, like MIDI or various tracker formats, it might be possible to manipulate only one of the speed/tempo or pitch values during playback.

To be fair, by default, löve processes such files as if they were streams too, so this option is not available... unless you edit the pitch or speed values within the files themselves, then reload them.

On the other hand, one could write an efficient FFI implementation of a player for such formats, and that way, it would be possible to alter playback state, even in realtime. (and for the record, i'm doing just this)

Re: Modifying sound

Posted: Sat Sep 17, 2016 5:41 pm
by Skeletonxf
If you just need an altered sound and don't have to do it in real time with love you could just download Audacity to modify the sounds externally and maybe make a wrapper module to specify the speed/pitch to play out of preset files.

Re: Modifying sound

Posted: Sat Sep 17, 2016 8:25 pm
by georgeprosser
Skeletonxf wrote:If you just need an altered sound and don't have to do it in real time with love you could just download Audacity to modify the sounds externally and maybe make a wrapper module to specify the speed/pitch to play out of preset files.
I did exactly this for a recent music game.

Would it be possible to implement pitch/time shift using OpenAL? And is it even feasible to do this in real time?

Re: Modifying sound

Posted: Sat Sep 17, 2016 9:02 pm
by pgimeno
I've done it in real time with SoX. See my 2nd edit above.

No, OpenAL doesn't have that kind of audio processing.

Re: Modifying sound

Posted: Sat Sep 17, 2016 9:32 pm
by zorg
pgimeno wrote:
georgeprosser wrote:Would it be possible to implement pitch/time shift using OpenAL? And is it even feasible to do this in real time?
No, OpenAL doesn't have that kind of audio processing.
One can write code to mess with audio data, and then pass that to OpenAL for playback, so that's not an issue, but i'm not sure whether it'd be possible to actually implement pitch/time shifting to work fast enough though.