diff --git a/libraries/dumb/include/dumb.h b/libraries/dumb/include/dumb.h index fa65cb702..14cf184df 100644 --- a/libraries/dumb/include/dumb.h +++ b/libraries/dumb/include/dumb.h @@ -802,9 +802,6 @@ DUH *make_duh( void DUMBEXPORT duh_set_length(DUH *duh, int32 length); -extern short *(*dumb_decode_vorbis)(int outlen, const void *oggstream, int sizebytes); - - #ifdef __cplusplus } #endif diff --git a/libraries/dumb/src/it/readxm.c b/libraries/dumb/src/it/readxm.c index fde1838c8..e3c082e91 100644 --- a/libraries/dumb/src/it/readxm.c +++ b/libraries/dumb/src/it/readxm.c @@ -28,7 +28,7 @@ #include #include -short * (*dumb_decode_vorbis)(int outlen, const void *oggstream, int sizebytes); +short * dumb_decode_vorbis(int outlen, const void *oggstream, int sizebytes); /** TODO: @@ -830,7 +830,7 @@ static int it_xm_read_sample_data(IT_SAMPLE *sample, unsigned char roguebytes, D sample->loop_start >>= 1; sample->loop_end >>= 1; } - output = dumb_decode_vorbis? dumb_decode_vorbis(outlen, (char *)sample->data + 4, datasizebytes - 4) : NULL; + output = dumb_decode_vorbis(outlen, (char *)sample->data + 4, datasizebytes - 4); if (output != NULL) { free(sample->data); diff --git a/libraries/zmusic/decoder/sounddecoder.cpp b/libraries/zmusic/decoder/sounddecoder.cpp index 61600a83e..171b4b8cd 100644 --- a/libraries/zmusic/decoder/sounddecoder.cpp +++ b/libraries/zmusic/decoder/sounddecoder.cpp @@ -79,3 +79,39 @@ std::vector SoundDecoder::readAll() output.resize(total); return output; } + +//========================================================================== +// +// other callbacks +// +//========================================================================== +extern "C" +short* dumb_decode_vorbis(int outlen, const void* oggstream, int sizebytes) +{ + short* samples = (short*)calloc(1, outlen); + ChannelConfig chans; + SampleType type; + int srate; + + // The decoder will take ownership of the reader if it succeeds so this may not be a local variable. + MusicIO::MemoryReader* reader = new MusicIO::MemoryReader((const uint8_t*)oggstream, sizebytes); + + SoundDecoder* decoder = SoundDecoder::CreateDecoder(reader); + if (!decoder) + { + reader->close(); + return samples; + } + + decoder->getInfo(&srate, &chans, &type); + if (chans != ChannelConfig_Mono || type != SampleType_Int16) + { + delete decoder; + return samples; + } + + decoder->read((char*)samples, outlen); + delete decoder; + return samples; +} + diff --git a/libraries/zmusic/zmusic/configuration.cpp b/libraries/zmusic/zmusic/configuration.cpp index 16950fc38..e093baf80 100644 --- a/libraries/zmusic/zmusic/configuration.cpp +++ b/libraries/zmusic/zmusic/configuration.cpp @@ -56,7 +56,6 @@ Callbacks musicCallbacks; DLL_EXPORT void ZMusic_SetCallbacks(const Callbacks* cb) { - dumb_decode_vorbis = cb->DumbVorbisDecode; musicCallbacks = *cb; } diff --git a/libraries/zmusic/zmusic/zmusic.cpp b/libraries/zmusic/zmusic/zmusic.cpp index b8b0e0925..305c876ab 100644 --- a/libraries/zmusic/zmusic/zmusic.cpp +++ b/libraries/zmusic/zmusic/zmusic.cpp @@ -65,6 +65,7 @@ const char *GME_CheckFormat(uint32_t header); MusInfo* CDDA_OpenSong(MusicIO::FileInterface* reader); MusInfo* CD_OpenSong(int track, int id); MusInfo* CreateMIDIStreamer(MIDISource *source, EMidiDevice devtype, const char* args); + //========================================================================== // // ungzip diff --git a/src/sound/backend/i_sound.cpp b/src/sound/backend/i_sound.cpp index 3c6585a44..649673f97 100644 --- a/src/sound/backend/i_sound.cpp +++ b/src/sound/backend/i_sound.cpp @@ -92,7 +92,7 @@ CUSTOM_CVAR(Float, snd_mastervolume, 1.f, CVAR_ARCHIVE | CVAR_GLOBALCONFIG) else if (self > 1.f) self = 1.f; - ChangeMusicSetting(ZMusic::snd_mastervolume, nullptr, self); + ChangeMusicSetting(zmusic_snd_mastervolume, nullptr, self); snd_sfxvolume.Callback(); snd_musicvolume.Callback(); } @@ -325,36 +325,6 @@ FString SoundRenderer::GatherStats () return "No stats for this sound renderer."; } -short *SoundRenderer::DecodeSample(int outlen, const void *coded, int sizebytes, ECodecType ctype) -{ - short *samples = (short*)calloc(1, outlen); - ChannelConfig chans; - SampleType type; - int srate; - - // The decoder will take ownership of the reader if it succeeds so this may not be a local variable. - MusicIO::MemoryReader *reader = new MusicIO::MemoryReader((const uint8_t*)coded, sizebytes); - - SoundDecoder *decoder = SoundDecoder::CreateDecoder(reader); - if (!decoder) - { - reader->close(); - return samples; - } - - decoder->getInfo(&srate, &chans, &type); - if(chans != ChannelConfig_Mono || type != SampleType_Int16) - { - DPrintf(DMSG_WARNING, "Sample is not 16-bit mono\n"); - delete decoder; - return samples; - } - - decoder->read((char*)samples, outlen); - delete decoder; - return samples; -} - void SoundRenderer::DrawWaveDebug(int mode) { } diff --git a/src/sound/backend/i_sound.h b/src/sound/backend/i_sound.h index 40b8a1425..f6fed7553 100644 --- a/src/sound/backend/i_sound.h +++ b/src/sound/backend/i_sound.h @@ -165,7 +165,6 @@ public: virtual void PrintStatus () = 0; virtual void PrintDriversList () = 0; virtual FString GatherStats (); - virtual short *DecodeSample(int outlen, const void *coded, int sizebytes, ECodecType type); virtual void DrawWaveDebug(int mode); }; diff --git a/src/sound/music/i_music.cpp b/src/sound/music/i_music.cpp index ba330c723..edc5da424 100644 --- a/src/sound/music/i_music.cpp +++ b/src/sound/music/i_music.cpp @@ -123,7 +123,7 @@ CUSTOM_CVAR (Float, snd_musicvolume, 0.5f, CVAR_ARCHIVE|CVAR_GLOBALCONFIG) else { // Set general music volume. - ChangeMusicSetting(ZMusic::snd_musicvolume, nullptr, self); + ChangeMusicSetting(zmusic_snd_musicvolume, nullptr, self); if (GSnd != nullptr) { GSnd->SetMusicVolume(clamp(self * relative_volume * snd_mastervolume, 0, 1)); @@ -179,16 +179,6 @@ static void wm_printfunc(const char* wmfmt, va_list args) VPrintf(PRINT_HIGH, wmfmt, args); } -//========================================================================== -// -// other callbacks -// -//========================================================================== - -static short* dumb_decode_vorbis_(int outlen, const void* oggstream, int sizebytes) -{ - return GSnd->DecodeSample(outlen, oggstream, sizebytes, CODEC_Vorbis); -} static std::string mus_NicePath(const char* str) { @@ -283,7 +273,6 @@ void I_InitMusic (void) callbacks.NicePath = mus_NicePath; callbacks.PathForSoundfont = mus_pathToSoundFont; callbacks.OpenSoundFont = mus_openSoundFont; - callbacks.DumbVorbisDecode = dumb_decode_vorbis_; ZMusic_SetCallbacks(&callbacks); SetupGenMidi(); @@ -301,7 +290,7 @@ void I_InitMusic (void) void I_SetRelativeVolume(float vol) { relative_volume = (float)vol; - ChangeMusicSetting(ZMusic::relative_volume, nullptr, (float)vol); + ChangeMusicSetting(zmusic_relative_volume, nullptr, (float)vol); snd_musicvolume.Callback(); } //==========================================================================