r1sc / Open76

Interstate '76 engine reimplementation
GNU General Public License v3.0
52 stars 3 forks source link

Added a GpwParser (sound effects) and a SoundManager #10

Closed JJJohan closed 5 years ago

JJJohan commented 5 years ago

After browsing through the game assets for a bit, both through the ZFS and the game directory, I noticed I couldn't find the sound effects anywhere (note: not the mission-specific sounds that are in the ZFS or the music)

I started to look at some of the file formats that we haven't parsed yet, and going by the file names I took a look at these 'GPW' files. Turns out these are storing the remaining sound effects (engine sounds, weapon sounds, explosions, radar beeps, etc.)

I tried to decipher what I could but unfortunately most of the surrounding bytes are completely alien to me for the time being. The best I could do was the first two bytes appear to be the audible range of the sound effect (-1 for global sounds). Most of the values are -1 and then there's the mystery 8 bytes at the end of the GPW file.

The good news is the WAV data was pretty easy to spot, and I've gone through the effort of mapping the sound files into a SoundEffects enum because they're otherwise quite tricky to read from filename alone (and unlikely to be directly referenced by vehicle or mission files anyway)

I tried to map the weapon sounds as best I could but sadly most of the weapon sounds aren't playing properly for me in the original game so some enum values may be pointing at the wrong file names in some places.

Two quick notes:

JJJohan commented 5 years ago

As a side note, I'm investigating sounds having a noticeable 'click' when they start/stop (especially bad for engine looping sounds). Most solutions I've found point at re-exporting the audio in an audio editor, which isn't really desirable. I'll keep looking!

r1sc commented 5 years ago

The "click" noise sounds like you're reading either too many or too few bytes from the RIFF section OR the output buffer may be too large or too small. I seem to remember "exporting" them manually to .WAV and they looped fine. Double check the buffer sizes.

I seem to recall that most sound effects are referenced by component files (*.GDF), so mapping them might not be necessary. I think we should research this first. I did a quick search for wlflame (which is a GDW file) and it's referenced in gflight.gdf and tflight.gdf (with a .wav extension though).

Also a lot of the sound effects are actually referenced by the mission files, but I guess you know this already. Those sounds are unnecessary to map ofc since they will be played dynamically by the mission scripts.

Regarding the duplicates; could there be multiple versions to support different sampling rates? This might be worth investigating.

In summary; investigate whether we can avoid explicit mapping if possible. I think the engine should be as dumb as possible. It would be nice to just parse a car, find out all of the sounds it make. Parse a weapon and find out all sounds that make and so on and so forth. That way, it's probably easier to support data-driven mods the community made over the years (custom cars and whatnot).

As always, I really appreciate your contributions! Keep 'em coming! :)

r1sc commented 5 years ago

I manually copied the RIFF-data from wlflame.gpw into a new file with a .wav extension and it loops perfectly. Do you have any example of a certain file that is problematic?

JJJohan commented 5 years ago

When I export all the .gpw sounds to .wav files on my disk and play them back in a loop they don't seem to click at all. Either I'm doing something weird in Unity or my Unity install might need a reinstall 😄.

I'll definitely look into the sounds being referenced by other data files. I wouldn't be surprised if there isn't something in the vehicle files that reference things like engine sounds based on which engine is in the car. Initially I mapped them just to test playback which was fun to play around with.

I do think there will still be a few game sounds that aren't referenced by component files etc. - mostly the UI things like the radar beeps, weapon switch/click. I might get rid of the SoundManager for now though as they can still be referenced by file name.