Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use SDL_AudioCVT to convert sfx lumps #858

Closed
fabiangreffrath opened this issue Jan 2, 2023 · 7 comments
Closed

use SDL_AudioCVT to convert sfx lumps #858

fabiangreffrath opened this issue Jan 2, 2023 · 7 comments
Assignees

Comments

@fabiangreffrath
Copy link
Owner

Pros:

  • We could load sounds in about any sound format, including Ogg, FLAC and MP3. We could also do stereo to mono conversion on the fly.

Cons:

  • We would have one more library dependency.
  • This could make pitch-shifting a bit more complicated.

Neutrals:

  • Really needed? We already support Doom's native format as well as 8-bit and 16-bit mono WAVs. Are there any known cases of WADs using other formats?
@rfomin
Copy link
Collaborator

rfomin commented Jan 2, 2023

I like this idea, another dependency is not a big issue since we finally have a proper package/dependency manager for all builds.

  • as well as 8-bit and 16-bit mono WAVs

The WAV format is complex, so we only support a small part of it. I'm sure there are WADs with broken WAV files somewhere (by the way, GZDoom uses libsndfile). I also suggest using libsamplerate, maybe that way we get rid of the remaining click sounds. Although, there is a user who liked the current resampler.

@fabiangreffrath
Copy link
Owner Author

fabiangreffrath commented Jan 2, 2023

Although, there is a user who liked the current resampler.

I also like our current resampler! (That is, the way it sounds, not the way it works 😁)

However, I seem to be unable to find the code in libsndfile that is responsible for resampling. 🤷 (I'd like to see how far we come without libsamplerate)

@fabiangreffrath
Copy link
Owner Author

I also suggest using libsamplerate, maybe that way we get rid of the remaining click sounds. Although, there is a user who liked the current resampler.

Hm, libsamplerate only works with floats, so we need to convert the original 11kHz/U8 samples to 11kHz/F32 to feed them into libsamplerate, get them converted to 48kHz/F32 and then convert them back to 48kHz/S16 to please SDL2_Mixer.

@fabiangreffrath fabiangreffrath self-assigned this Jan 4, 2023
@fabiangreffrath
Copy link
Owner Author

So, it seems that while libsndfile is indeed able to convert the sound lump samples from U8 to S16 format (which is pretty much what this library is supposed to do), it is not able to do the samplerate conversion for us - which is okay since this is exactly what libsamplerate is for. But neither library seems to be able to do the mono to stereo conversion for us.

So, in the end we'd still have to do some manual conversion of the sound samples. And if we can't get rid of it entirely, we could just as well keep our current approach of doing all steps manually. Either this, or we link against a more powerful library (libsox?) that can do the whole necessary conversion chain for us.

@rfomin
Copy link
Collaborator

rfomin commented Jan 5, 2023

It seems SDL2 already uses libsamplerate: microsoft/vcpkg#28554 It can also be built on Windows with this feature. https://wiki.libsdl.org/SDL2/SDL_ConvertAudio

@fabiangreffrath
Copy link
Owner Author

Oh, that's new then. Chocolate Doom for example still holds the assumption that SDL2_Mixer can only do integer ratio conversions itself.

@fabiangreffrath
Copy link
Owner Author

Indeed:

  • Implemented non-power-of-two audio resampling, optionally using libsamplerate to perform the resampling
  • Added the hint SDL_HINT_AUDIO_RESAMPLING_MODE to control the quality of resampling

https://github.com/libsdl-org/SDL/blob/a0991727545967d9e4b54a16f12ae641991a1e76/WhatsNew.txt#L581-L582

I'll try to convert all sound samples using only SDL functions instead!

@fabiangreffrath fabiangreffrath changed the title random idea: use libsndfile to load and convert sfx lumps use SDL_AudioCVT to convert sfx lumps Jan 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants