Modifying sound

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
User avatar
georgeprosser
Citizen
Posts: 68
Joined: Fri Mar 28, 2014 5:55 pm

Modifying sound

Post 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?
User avatar
pgimeno
Party member
Posts: 3672
Joined: Sun Oct 18, 2015 2:58 pm

Re: Modifying sound

Post 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
Last edited by pgimeno on Sat Sep 17, 2016 5:32 pm, edited 1 time in total.
User avatar
zorg
Party member
Posts: 3468
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

Re: Modifying sound

Post 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)
Me and my stuff :3True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.
Skeletonxf
Citizen
Posts: 87
Joined: Tue Dec 30, 2014 6:07 pm

Re: Modifying sound

Post 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.
User avatar
georgeprosser
Citizen
Posts: 68
Joined: Fri Mar 28, 2014 5:55 pm

Re: Modifying sound

Post 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?
User avatar
pgimeno
Party member
Posts: 3672
Joined: Sun Oct 18, 2015 2:58 pm

Re: Modifying sound

Post 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.
User avatar
zorg
Party member
Posts: 3468
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

Re: Modifying sound

Post 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.
Me and my stuff :3True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.
Post Reply

Who is online

Users browsing this forum: Google [Bot] and 10 guests