New Movement Audio


Today's build has two new things.

A: I removed the water wave sound from the game as I think it was just annoying (like I suspicioned in yesterday's build). I don't know if any of ya'll thought it was annoying too though, as no one told me. But, in my own tests, it was annoying so yea.

(Where the actual tech post starts)
B: I added a boat movement sound today.
I originally wanted to have this sound clip slowly ramp up over time to a "full rev" type of audio clip. A good example would be really any racing or car game that's been released and has had someone on their team that knew audio programming / sound waves really well.

So me not knowing the whole world of audio programming lead me to just doing a simple thing. What I mean is that I just simply linearly interpolate between 0 and whatever direction the current audio sample is going by some amount. The amount in this case is just how much velocity the boat has and is ultimately clamped between zero and one which that 0 to 1 value is then used as the interpolation value between the previously mentioned 0 to sample point.

So if you don't know how audio works, you basically have a rate at which you need to play N samples otherwise your audio gets glitchy and what not. For example: if your audio's sample rate is 48000, this should mean 48000 samples PER SECOND. When translating this into the actual code / your engine, you need to divide that 48000 up into N frames where N's max is the total number of frames you can output in 1 second. So for example, I want to run at 60 frames per second so I have 16.6666666 miliseconds PER FRAME to do everything for one frame's worth of game data transforms (rendering, audio playing, gameplay, collision, etc).
Particular to audio, I simply just take the total number of frames that's suppose to play in 1 second and divide that by the rate at which i'm outputing frames, so you'd get: 48000 / 60 = 800 frames of audio, for one game frame.

Now back to what I was writing before I sidetracked randomly to describe how audio works. Per sample of the 800 you're going to play this frame, you just do a lerp between 0 and samples height / direction from 0 up or down (so 0 -> 32767 or -32767 <- 0 as you're making sound so you gotta oscillate). I think people refer to this as "pitch shifting" but it really is just lowering the volume up and down. Because of this, I get some notion that the speed of the boat is revving up.

Now one way I did want to do this was by actually figuring out how to slow down and speed up the audio clip. This is all my own brain's guess on how you'd do this so take this with a grain of salt (or correct me please if you're an audio person). If you want to slow down a clip, you'd need to still output your 800 samples in one game frame but those 800 samples would have duplicates of some audio samples. Let's say the first audio sample is 50, you'd then have another 50 before it jumps down to -60 and then you'd have another -60 again. As for the speedup, i'm not really sure to be honest. I think you'd just have to say that your base clip is the fastest and you'd just slowdown to some minimum and speedup by slowly removing the number of  duplicate audio samples. Another way you could do the slowdown perhaps is by just lerping between samples instead of just duplicating the same 50 again or whatever which would probably give you a more natural sound. But yea, this is total brain theory of which has already been discovered by others and i'm just simply too tired to link to some wiki page or whatever paper as I don't know where that would be / i'm not qualfied to judge the quality of such a thing since i've never implemented this. In other words, i'm writing this paragraph to add more content to the post / give you a small inspection into my naive brain :]

Thank you for reading! If you have time, try out the game and let me know what you love / hate please!

Files

Funmi_Zip.7z 2.4 MB
Oct 24, 2021

Get Funmi

Download NowName your own price

Leave a comment

Log in with itch.io to leave a comment.