From 9f493fca5ff6dad77739362ea676082e5ec7316e Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Thu, 19 Jun 2014 22:40:45 -0700 Subject: [PATCH] Move the generic DecodeSample implementation to the base class --- src/sound/i_sound.cpp | 21 +++++++++++++++++++-- src/sound/oalsound.cpp | 20 -------------------- src/sound/oalsound.h | 2 -- 3 files changed, 19 insertions(+), 24 deletions(-) diff --git a/src/sound/i_sound.cpp b/src/sound/i_sound.cpp index af23b34c4f..b533ff2dd0 100644 --- a/src/sound/i_sound.cpp +++ b/src/sound/i_sound.cpp @@ -48,6 +48,7 @@ extern HINSTANCE g_hInst; #include #include #include +#include #include "doomtype.h" #include @@ -338,9 +339,25 @@ FString SoundRenderer::GatherStats () return "No stats for this sound renderer."; } -short *SoundRenderer::DecodeSample(int outlen, const void *coded, int sizebytes, ECodecType type) +short *SoundRenderer::DecodeSample(int outlen, const void *coded, int sizebytes, ECodecType ctype) { - return NULL; + short *samples = (short*)calloc(1, outlen); + ChannelConfig chans; + SampleType type; + int srate; + + std::auto_ptr decoder(CreateDecoder((const BYTE*)coded, sizebytes)); + if(!decoder.get()) return samples; + + decoder->getInfo(&srate, &chans, &type); + if(chans != ChannelConfig_Mono || type != SampleType_Int16) + { + DPrintf("Sample is not 16-bit mono\n"); + return samples; + } + + decoder->read((char*)samples, outlen); + return samples; } void SoundRenderer::DrawWaveDebug(int mode) diff --git a/src/sound/oalsound.cpp b/src/sound/oalsound.cpp index 166afb25c7..5383d34b1c 100644 --- a/src/sound/oalsound.cpp +++ b/src/sound/oalsound.cpp @@ -1053,26 +1053,6 @@ void OpenALSoundRenderer::UnloadSound(SoundHandle sfx) delete ((ALuint*)sfx.data); } -short *OpenALSoundRenderer::DecodeSample(int outlen, const void *coded, int sizebytes, ECodecType ctype) -{ - char *samples = (char*)calloc(1, outlen); - ChannelConfig chans; - SampleType type; - int srate; - - std::auto_ptr decoder(CreateDecoder((const BYTE*)coded, sizebytes)); - if(!decoder.get()) return (short*)samples; - - decoder->getInfo(&srate, &chans, &type); - if(chans != ChannelConfig_Mono || type != SampleType_Int16) - { - DPrintf("Sample is not 16-bit mono\n"); - return (short*)samples; - } - - decoder->read(samples, outlen); - return (short*)samples; -} SoundStream *OpenALSoundRenderer::CreateStream(SoundStreamCallback callback, int buffbytes, int flags, int samplerate, void *userdata) { diff --git a/src/sound/oalsound.h b/src/sound/oalsound.h index 2931e75316..3c3771358d 100644 --- a/src/sound/oalsound.h +++ b/src/sound/oalsound.h @@ -112,8 +112,6 @@ public: virtual void UpdateListener(SoundListener *); virtual void UpdateSounds(); - virtual short *DecodeSample(int outlen, const void *coded, int sizebytes, ECodecType type); - virtual void MarkStartTime(FISoundChannel*); virtual float GetAudibility(FISoundChannel*);