diff options
author | Paweł Kołodziejski | 2004-04-13 05:57:52 +0000 |
---|---|---|
committer | Paweł Kołodziejski | 2004-04-13 05:57:52 +0000 |
commit | 6680c5368dbbe605b6beb7314b4609f5dea1c5ca (patch) | |
tree | f87272024d1362560c81db3b8d7cf67f3bf72b5d /sound | |
parent | e42c1f0483b2bf7dd5af4a3473232fa1019618cc (diff) | |
download | scummvm-rg350-6680c5368dbbe605b6beb7314b4609f5dea1c5ca.tar.gz scummvm-rg350-6680c5368dbbe605b6beb7314b4609f5dea1c5ca.tar.bz2 scummvm-rg350-6680c5368dbbe605b6beb7314b4609f5dea1c5ca.zip |
added CustomProcInputStream
svn-id: r13570
Diffstat (limited to 'sound')
-rw-r--r-- | sound/audiostream.cpp | 28 | ||||
-rw-r--r-- | sound/audiostream.h | 25 |
2 files changed, 53 insertions, 0 deletions
diff --git a/sound/audiostream.cpp b/sound/audiostream.cpp index 7a0164c1d5..0c31a65f0e 100644 --- a/sound/audiostream.cpp +++ b/sound/audiostream.cpp @@ -336,6 +336,34 @@ public: }; #endif +CustomProcInputStream::CustomProcInputStream(int rate, byte flags, CustomInputProc proc, void *refCon) { + _refCon = refCon; + _refStream = this; + _rate = rate; + _proc = proc; + _finished = false; + _isStereo = (flags & SoundMixer::FLAG_STEREO) != 0; + _is16Bit = (flags & SoundMixer::FLAG_16BITS) != 0; + _isUnsigned = (flags & SoundMixer::FLAG_UNSIGNED) != 0; + assert(!(flags & SoundMixer::FLAG_LITTLE_ENDIAN)); + assert(!(flags & SoundMixer::FLAG_AUTOFREE)); +} + +int CustomProcInputStream::readBuffer(int16 *buffer, const int numSamples) { + int numBytes = numSamples; + numBytes *= (_is16Bit ? 2 : 1); + byte *tmpBuffer = (byte *)malloc(numBytes); + int gotSamples = (_proc)(_refCon, _refStream, tmpBuffer, numBytes) / (_is16Bit ? 2 : 1); + + const byte *ptr = tmpBuffer; + for (int samples = 0; samples < gotSamples; samples++) { + *buffer++ = READSAMPLE(_is16Bit, _isUnsigned, ptr); + ptr += (_is16Bit ? 2 : 1); + } + + free(tmpBuffer); + return gotSamples; +} #pragma mark - #pragma mark --- Input stream factories --- diff --git a/sound/audiostream.h b/sound/audiostream.h index ae549afba9..5e6c41fdfc 100644 --- a/sound/audiostream.h +++ b/sound/audiostream.h @@ -113,6 +113,31 @@ public: int getRate() const { return -1; } }; +class CustomProcInputStream : public AudioStream { +public: + typedef int (*CustomInputProc)(void *refCon, CustomProcInputStream *stream, byte *data, uint len); + +private: + bool _isStereo; + bool _is16Bit; + bool _isUnsigned; + int _rate; + CustomInputProc _proc; + CustomProcInputStream *_refStream; + void *_refCon; + bool _finished; + +public: + + CustomProcInputStream(int rate, byte flags, CustomInputProc proc, void *refCon); + + int readBuffer(int16 *buffer, const int numSamples); + bool isStereo() const { return _isStereo; } + bool endOfData() const { return _finished; } + void finish() { _finished = true; } + int getRate() const { return _rate; } +}; + AudioStream *makeLinearInputStream(int rate, byte _flags, const byte *ptr, uint32 len, uint loopOffset, uint loopLen); AppendableAudioStream *makeAppendableAudioStream(int rate, byte _flags, uint32 len); |