Move the generic DecodeSample implementation to the base class

This commit is contained in:
Chris Robinson 2014-06-19 22:40:45 -07:00
parent 72ddc0d935
commit 9f493fca5f
3 changed files with 19 additions and 24 deletions

View File

@ -48,6 +48,7 @@ extern HINSTANCE g_hInst;
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <stdarg.h> #include <stdarg.h>
#include <memory>
#include "doomtype.h" #include "doomtype.h"
#include <math.h> #include <math.h>
@ -338,9 +339,25 @@ FString SoundRenderer::GatherStats ()
return "No stats for this sound renderer."; 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<SoundDecoder> 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) void SoundRenderer::DrawWaveDebug(int mode)

View File

@ -1053,26 +1053,6 @@ void OpenALSoundRenderer::UnloadSound(SoundHandle sfx)
delete ((ALuint*)sfx.data); 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<SoundDecoder> 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) SoundStream *OpenALSoundRenderer::CreateStream(SoundStreamCallback callback, int buffbytes, int flags, int samplerate, void *userdata)
{ {

View File

@ -112,8 +112,6 @@ public:
virtual void UpdateListener(SoundListener *); virtual void UpdateListener(SoundListener *);
virtual void UpdateSounds(); virtual void UpdateSounds();
virtual short *DecodeSample(int outlen, const void *coded, int sizebytes, ECodecType type);
virtual void MarkStartTime(FISoundChannel*); virtual void MarkStartTime(FISoundChannel*);
virtual float GetAudibility(FISoundChannel*); virtual float GetAudibility(FISoundChannel*);