How to change sound effects transparently to give changing tone/frequency impression? eg motor engine

How can one best create a dynamically changing sound effect which is triggered programmatically during the game. For example a car engine who’s sound changes as the speed increases/decreases?

[import]uid: 140210 topic_id: 30310 reply_id: 330310[/import]

I used the hints in this post :

http://www.coronalabs.com/blog/2011/07/27/the-secretundocumented-audio-apis-in-corona-sdk/

I too have a motor engine that changes pitch according to certain values etc … if you need any more help, let me know and I’ll post my code although it’s pretty straightforward. [import]uid: 87794 topic_id: 30310 reply_id: 121422[/import]

Thanks digitaloranges - that would be great to have a look at your code [import]uid: 140210 topic_id: 30310 reply_id: 121424[/import]

Hiya,

Basically, when you call audio.play, it returns 2 values, the channel and the sound source object stuff (my audio stuff is wrapped in my own framework so it would be useless to show you the code really) but audio.play returns the channel and the sound object (you’ll need to loop the sound forever if it was an engine sound for instance) :

local mySound = audio.loadSound(soundFileName);  
local channel, sound\_object = audio.play(mySound, { loops = -1})  

Then, to adjust the pitch of the sound, every frame I look at the calculated velocity of my physics object (or you may want to use a ‘revs’ value which would change the pitch according to engine revs - it all depends on how you wish to do it)

 local m = 0.005;  
 local n = velocityOfObject \* m;  
 al.Source( sound\_object, al.PITCH, 1 + n);  

Of course, it may not need to be called every frame, but it works for me. You’d need to experiment with the velocityOfObject and m to get the sound change you’re looking for.

I hope that helps!

[import]uid: 87794 topic_id: 30310 reply_id: 121425[/import]

excellent thanks

The only other question would be if at some point the pitch change was getting unrealistic and you have to swap over (transparently) to a new sound how to do this? Would the best way (only way) be just to do something like:

  • play sound 1
  • load sound 2 on separate channel (e.g. use audio.freeChannels)
  • start fading out sound 1
  • play sound 2

i.e. there’s no Corona API to automatically fade from one sound to another sound is there? [import]uid: 140210 topic_id: 30310 reply_id: 121431[/import]

is this “hidden” API for iOS only, or universal? [import]uid: 160496 topic_id: 30310 reply_id: 121436[/import]

It’s available on all the platforms. (Mac, iOS, Android, Windows) [import]uid: 7563 topic_id: 30310 reply_id: 121456[/import]

Windows? It gave me error messages in console when I used it in simulator… [import]uid: 160496 topic_id: 30310 reply_id: 121457[/import]

dupe (I hate my Toshiba Thrive tablet sometimes) [import]uid: 160496 topic_id: 30310 reply_id: 121458[/import]

Here is the error I get on Windows Simulator: (including the misspellings)

08Testing errpr before unqueue because getting stuff, for OS X this is expected: Invalid Name

and, of course, the pitch doesn’t change.

On edit: no, my fault. It all works, I was giving it a nil value for the source and getting that error. [import]uid: 160496 topic_id: 30310 reply_id: 121459[/import]

Something triggered an OpenAL error. I’m not sure what. That could break pitch, but I think it should work despite that.

Can you try a very basic test:

local mySound = audio.loadSound(“some_mono_sound.wav”)
local channel, sound_object = audio.play(mySound)
al.Source(sound_object, al.PITCH, 2.0)

Make sure your sounds are mono. OpenAL will not apply effects to stereo sounds.
[import]uid: 7563 topic_id: 30310 reply_id: 121462[/import]

Glad to hear it is working after all.
[import]uid: 7563 topic_id: 30310 reply_id: 121463[/import]

I used the hints in this post :

http://www.coronalabs.com/blog/2011/07/27/the-secretundocumented-audio-apis-in-corona-sdk/

I too have a motor engine that changes pitch according to certain values etc … if you need any more help, let me know and I’ll post my code although it’s pretty straightforward. [import]uid: 87794 topic_id: 30310 reply_id: 121422[/import]

Thanks digitaloranges - that would be great to have a look at your code [import]uid: 140210 topic_id: 30310 reply_id: 121424[/import]

Hiya,

Basically, when you call audio.play, it returns 2 values, the channel and the sound source object stuff (my audio stuff is wrapped in my own framework so it would be useless to show you the code really) but audio.play returns the channel and the sound object (you’ll need to loop the sound forever if it was an engine sound for instance) :

local mySound = audio.loadSound(soundFileName);  
local channel, sound\_object = audio.play(mySound, { loops = -1})  

Then, to adjust the pitch of the sound, every frame I look at the calculated velocity of my physics object (or you may want to use a ‘revs’ value which would change the pitch according to engine revs - it all depends on how you wish to do it)

 local m = 0.005;  
 local n = velocityOfObject \* m;  
 al.Source( sound\_object, al.PITCH, 1 + n);  

Of course, it may not need to be called every frame, but it works for me. You’d need to experiment with the velocityOfObject and m to get the sound change you’re looking for.

I hope that helps!

[import]uid: 87794 topic_id: 30310 reply_id: 121425[/import]

excellent thanks

The only other question would be if at some point the pitch change was getting unrealistic and you have to swap over (transparently) to a new sound how to do this? Would the best way (only way) be just to do something like:

  • play sound 1
  • load sound 2 on separate channel (e.g. use audio.freeChannels)
  • start fading out sound 1
  • play sound 2

i.e. there’s no Corona API to automatically fade from one sound to another sound is there? [import]uid: 140210 topic_id: 30310 reply_id: 121431[/import]

is this “hidden” API for iOS only, or universal? [import]uid: 160496 topic_id: 30310 reply_id: 121436[/import]

It’s available on all the platforms. (Mac, iOS, Android, Windows) [import]uid: 7563 topic_id: 30310 reply_id: 121456[/import]

Windows? It gave me error messages in console when I used it in simulator… [import]uid: 160496 topic_id: 30310 reply_id: 121457[/import]

dupe (I hate my Toshiba Thrive tablet sometimes) [import]uid: 160496 topic_id: 30310 reply_id: 121458[/import]