reaction game

Home Read the Story Download Credits

Can they hear you in space?

30 November 2019

Well, not yet they can’t :)

Seriously, sound turns out to be way more involved than I had expected. The ramble at the end of my previous post looks a bit silly now. Ah well, previously I’ve encountered sound in two cases, once playing a sound file on a specific event, and once back in the days of the Spectrum 48K playing pure tones. Thankfully I’m not the first person to want to use sound in C#; there is a fantastic open-source library available called NAudio. Even better, the author of the library created a Pluralsight course on how it works, and how to get started using it. That has been a great help, and now I think I’m ready to lay out a basic plan and have a go.

To start, I’ve identified four types of sound that I care about; Background music, continuous effects, menu effects, and positional sound effects. Each one of these has different properties and will need different handling.

To simplify the game logic, I will pre-adjust all the samples to be in the same format with the same sample rate. Music will be in stereo, everything else in mono. Again, I’m lucky in that the Audacity tool is free and can do this for me. Furthermore, I decided to only consider stereo speaker systems. Surround sound could give a much better result, but the complexity is too much for this project.

Every screen in the game needs background music. It will be in the form of stereo samples that loop continuously. It will start when the screen is shown and stop when the screen is hidden. Apart from starting and stopping, the only effect that will need to be applied is to adjust the volume.

The game screen will also need continuous effects. For example, the thrust of the ship will need to start when the user applies thrust and not stop until the thrust stops. The volume will need to be adjusted depending on the strength of the thrust. To provide the effect, I will use a short looping sample with a single mono channel. Depending on the direction of the thrust, different amounts of the signal will need to be mixed into the left and right stereo channels. Other continuous effects might be things like the event horizon.

Then there are sound effects for elements of the game world that are discrete, such as the bloop of the plasma. These will need to play based on a trigger event, then stop. They will need converting to stereo based on their relative position to the ship.

For the positional effects, only sounds for game elements that are within the maximum visible distance will be played at all. Within that radius sounds closer to the ship will be played louder. When converting to stereo, the effects will be mixed around the vertical centre of the ship.

photo

(sound interactions)

Finally, there are sound effects for the menus, things like click effects on buttons. These can be just fire and forget effects without any kind of positional logic.

This gives me an effects chain something like:

photo

(effects chain)

That’s quite a bit to build, but my confidence is high that it will give a much more immersive experience.