Add a SoundDecoder base class and a stub method to create one

This commit is contained in:
Chris Robinson 2014-06-19 01:00:46 -07:00
parent b94a2949e5
commit 5370a1cb46
3 changed files with 64 additions and 0 deletions

View file

@ -520,3 +520,26 @@ SoundHandle SoundRenderer::LoadSoundVoc(BYTE *sfxdata, int length)
return retval;
}
SoundDecoder *SoundRenderer::CreateDecoder(BYTE *sfxdata, int length)
{
return NULL;
}
// Default readAll implementation, for decoders that can't do anything better
std::vector<char> SoundDecoder::readAll()
{
std::vector<char> output;
size_t total = 0;
size_t got;
output.resize(total+32768);
while((got=read(&output[total], output.size()-total)) > 0)
{
total += got;
output.resize(total*2);
}
output.resize(total);
return output;
}

View file

@ -82,6 +82,8 @@ public:
typedef bool (*SoundStreamCallback)(SoundStream *stream, void *buff, int len, void *userdata);
struct SoundDecoder;
class SoundRenderer
{
public:
@ -150,6 +152,9 @@ public:
virtual short *DecodeSample(int outlen, const void *coded, int sizebytes, ECodecType type);
virtual void DrawWaveDebug(int mode);
protected:
virtual SoundDecoder *CreateDecoder(BYTE *sfxdata, int length);
};
extern SoundRenderer *GSnd;

View file

@ -1,6 +1,8 @@
#ifndef __SNDINT_H
#define __SNDINT_H
#include <vector>
#include "basictypes.h"
// For convenience, this structure matches FMOD_REVERB_PROPERTIES.
@ -101,5 +103,39 @@ struct FISoundChannel
};
enum SampleType
{
SampleType_UInt8,
SampleType_Int16,
SampleType_Float32
};
enum ChannelConfig
{
ChannelConfig_Mono,
ChannelConfig_Stereo,
ChannelConfig_Quad,
ChannelConfig_5point1,
ChannelConfig_7point1
};
struct SoundDecoder
{
virtual bool open(const char *data, size_t length) = 0;
virtual void getInfo(int *samplerate, ChannelConfig *chans, SampleType *type) = 0;
virtual size_t read(char *buffer, size_t bytes) = 0;
virtual std::vector<char> readAll();
virtual bool seek(size_t ms_offset) = 0;
virtual size_t getSampleOffset() = 0;
SoundDecoder() { }
virtual ~SoundDecoder() { }
private:
// Make non-copyable
SoundDecoder(const SoundDecoder &rhs);
SoundDecoder& operator=(const SoundDecoder &rhs);
};
#endif