nmlgc / ssg

秋霜玉 / Shuusou Gyoku
MIT License
20 stars 5 forks source link

Perfectly resample sound effects to the native sampling rate #50

Open nmlgc opened 10 months ago

nmlgc commented 10 months ago

The original DirectSound backend uses what seems to be a first-order low-pass filter when resampling the original sound effects to the native sampling rate. This adds a bunch of high-frequency content, which looks like this at 48000 Hz:

Frequency spectrum of all of Shuusou Gyoku's sound effects, resampled to 48000 Hz and recorded through the game's original DirectSound backend

For the miniaudio backend implemented in #49, I went for a first-order low-pass filter as well. That gets quite close possible to the original DirectSound spectrum, and only adds a slight bit of additional crispiness to the high end:

Frequency spectrum of all of Shuusou Gyoku's sound effects resampled to 48000 Hz, as rendered by the future miniaudio-based backend. Shows off the slight additional high-frequency content added by miniaudio's resampler in comparison to the original DirectSound backend.

However, some might argue that both are incorrect. If the original sound effects use sampling rates of 22050 Hz and 11025 Hz, shouldn't the spectrum look more like this?

Frequency spectrum of all of Shuusou Gyoku's sound effects if they were perfectly resampled

This issue would deploy such a perfect resampler into the game, and add a toggle to the sound option menu for switching between accurate and crispy modes. Since the crispy mode is closer to what the game originally sounded like (and also sounds a lot better in my opinion), this feature is highly optional, and pretty much only meant for people who strictly define "accurate sound playback" as "not adding any frequency content that wasn't present in the original files".