diff --git a/src/sound/i_sound.cpp b/src/sound/i_sound.cpp index c2478ffef..f657182ef 100644 --- a/src/sound/i_sound.cpp +++ b/src/sound/i_sound.cpp @@ -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 SoundDecoder::readAll() +{ + std::vector 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; +} diff --git a/src/sound/i_sound.h b/src/sound/i_sound.h index adce8796b..fa419cf02 100644 --- a/src/sound/i_sound.h +++ b/src/sound/i_sound.h @@ -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; diff --git a/src/sound/i_soundinternal.h b/src/sound/i_soundinternal.h index b0f42913a..c0282ee6b 100644 --- a/src/sound/i_soundinternal.h +++ b/src/sound/i_soundinternal.h @@ -1,6 +1,8 @@ #ifndef __SNDINT_H #define __SNDINT_H +#include + #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 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