Skip to content

Commit

Permalink
- there's no need to let the XM Vorbis decoder run through the client…
Browse files Browse the repository at this point in the history
… - all related functionality is part of ZMusic itself.
  • Loading branch information
coelckers committed Jan 1, 2020
1 parent 47d70c8 commit 527fb40
Show file tree
Hide file tree
Showing 8 changed files with 42 additions and 51 deletions.
3 changes: 0 additions & 3 deletions libraries/dumb/include/dumb.h
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions libraries/dumb/src/it/readxm.c
Expand Up @@ -28,7 +28,7 @@
#include <stdlib.h>
#include <assert.h>

short * (*dumb_decode_vorbis)(int outlen, const void *oggstream, int sizebytes);
short * dumb_decode_vorbis(int outlen, const void *oggstream, int sizebytes);

/** TODO:
Expand Down Expand Up @@ -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);
Expand Down
36 changes: 36 additions & 0 deletions libraries/zmusic/decoder/sounddecoder.cpp
Expand Up @@ -79,3 +79,39 @@ std::vector<uint8_t> 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;
}

1 change: 0 additions & 1 deletion libraries/zmusic/zmusic/configuration.cpp
Expand Up @@ -56,7 +56,6 @@ Callbacks musicCallbacks;

DLL_EXPORT void ZMusic_SetCallbacks(const Callbacks* cb)
{
dumb_decode_vorbis = cb->DumbVorbisDecode;
musicCallbacks = *cb;
}

Expand Down
1 change: 1 addition & 0 deletions libraries/zmusic/zmusic/zmusic.cpp
Expand Up @@ -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
Expand Down
32 changes: 1 addition & 31 deletions src/sound/backend/i_sound.cpp
Expand Up @@ -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();
}
Expand Down Expand Up @@ -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)
{
}
Expand Down
1 change: 0 additions & 1 deletion src/sound/backend/i_sound.h
Expand Up @@ -165,7 +165,6 @@ class SoundRenderer
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);
};
Expand Down
15 changes: 2 additions & 13 deletions src/sound/music/i_music.cpp
Expand Up @@ -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<float>(self * relative_volume * snd_mastervolume, 0, 1));
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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();
Expand All @@ -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();
}
//==========================================================================
Expand Down

0 comments on commit 527fb40

Please sign in to comment.