aboutsummaryrefslogtreecommitdiff
path: root/sound/audiostream.h
diff options
context:
space:
mode:
authorMax Horn2003-07-24 18:20:12 +0000
committerMax Horn2003-07-24 18:20:12 +0000
commit1622ac31dafee837cb3011c558dfcd93c5bb1ca6 (patch)
tree82920cac2266e5b8a6fddc021590c10718ef3cb8 /sound/audiostream.h
parent8146de769395ffacf5483260ce69be31f0612808 (diff)
downloadscummvm-rg350-1622ac31dafee837cb3011c558dfcd93c5bb1ca6.tar.gz
scummvm-rg350-1622ac31dafee837cb3011c558dfcd93c5bb1ca6.tar.bz2
scummvm-rg350-1622ac31dafee837cb3011c558dfcd93c5bb1ca6.zip
added RateConverter classes as thin wrappers around st_* functions; renamed InputStream -> AudioInputStream and cleaned up the hierarchy of its subclasses; added makeInputStream() auxillary function
svn-id: r9179
Diffstat (limited to 'sound/audiostream.h')
-rw-r--r--sound/audiostream.h72
1 files changed, 55 insertions, 17 deletions
diff --git a/sound/audiostream.h b/sound/audiostream.h
index c3d43d6b2a..a913e892a7 100644
--- a/sound/audiostream.h
+++ b/sound/audiostream.h
@@ -22,14 +22,19 @@
#ifndef AUDIOSTREAM_H
#define AUDIOSTREAM_H
+#include "mixer.h"
+
+// TODO:
+// * maybe make readIntern return 16.16 or 24.8 fixed point values
+// since MAD (and maybe OggVorbis?) gives us those -> higher quality.
+// The rate converters should be able to deal with those just fine, too.
+// * possibly add MADInputStream and VorbisInputStream
+
/**
* Generic input stream for the resampling code.
*/
-class InputStream {
-public:
- byte *_ptr;
- byte *_end;
- InputStream(byte *ptr, uint len) : _ptr(ptr), _end(ptr+len) { }
+class AudioInputStream {
+protected:
virtual int16 readIntern() = 0;
virtual void advance() = 0;
public:
@@ -39,53 +44,86 @@ public:
bool eof() { return size() <= 0; }
};
-class ZeroInputStream : public InputStream {
+class ZeroInputStream : public AudioInputStream {
protected:
+ uint _len;
int16 readIntern() { return 0; }
- void advance() { _ptr++; }
+ void advance() { _len--; }
public:
- ZeroInputStream(uint len) : InputStream(0, len) { }
- virtual int size() { return _end - _ptr; }
+ ZeroInputStream(uint len) : _len(len) { }
+ virtual int size() { return _len; }
};
+class MemoryAudioInputStream : public AudioInputStream {
+protected:
+ const byte *_ptr;
+ const byte *_end;
+public:
+ MemoryAudioInputStream(const byte *ptr, uint len) : _ptr(ptr), _end(ptr+len) { }
+};
+
+
template<int channels>
-class Input8bitSignedStream : public InputStream {
+class Input8bitSignedStream : public MemoryAudioInputStream {
protected:
int16 readIntern() { int8 v = (int8)*_ptr; return v << 8; }
void advance() { _ptr += channels; }
public:
- Input8bitSignedStream(byte *ptr, int len) : InputStream(ptr, len) { }
+ Input8bitSignedStream(const byte *ptr, int len) : MemoryAudioInputStream(ptr, len) { }
virtual int size() { return (_end - _ptr) / channels; }
};
template<int channels>
-class Input8bitUnsignedStream : public InputStream {
+class Input8bitUnsignedStream : public MemoryAudioInputStream {
protected:
int16 readIntern() { int8 v = (int8)(*_ptr ^ 0x80); return v << 8; }
void advance() { _ptr += channels; }
public:
- Input8bitUnsignedStream(byte *ptr, int len) : InputStream(ptr, len) { }
+ Input8bitUnsignedStream(const byte *ptr, int len) : MemoryAudioInputStream(ptr, len) { }
virtual int size() { return (_end - _ptr) / channels; }
};
template<int channels>
-class Input16bitSignedStream : public InputStream {
+class Input16bitSignedStream : public MemoryAudioInputStream {
protected:
int16 readIntern() { return (int16)READ_BE_UINT16(_ptr); }
void advance() { _ptr += 2*channels; }
public:
- Input16bitSignedStream(byte *ptr, int len) : InputStream(ptr, len) { }
+ Input16bitSignedStream(const byte *ptr, int len) : MemoryAudioInputStream(ptr, len) { }
virtual int size() { return (_end - _ptr) / (2 * channels); }
};
template<int channels>
-class Input16bitUnsignedStream : public InputStream {
+class Input16bitUnsignedStream : public MemoryAudioInputStream {
protected:
int16 readIntern() { return (int16)(READ_BE_UINT16(_ptr) ^ 0x8000); }
void advance() { _ptr += 2*channels; }
public:
- Input16bitUnsignedStream(byte *ptr, int len) : InputStream(ptr, len) { }
+ Input16bitUnsignedStream(const byte *ptr, int len) : MemoryAudioInputStream(ptr, len) { }
virtual int size() { return (_end - _ptr) / (2 * channels); }
};
+
+template<int channels>
+static AudioInputStream *makeInputStream(const byte *ptr, uint32 len, bool isUnsigned, bool is16Bit) {
+ if (isUnsigned) {
+ if (is16Bit)
+ return new Input16bitUnsignedStream<channels>(ptr, len);
+ else
+ return new Input8bitUnsignedStream<channels>(ptr, len);
+ } else {
+ if (is16Bit)
+ return new Input16bitSignedStream<channels>(ptr, len);
+ else
+ return new Input8bitSignedStream<channels>(ptr, len);
+ }
+}
+
+static inline AudioInputStream *makeInputStream(byte _flags, const byte *ptr, uint32 len) {
+ if (_flags & SoundMixer::FLAG_STEREO)
+ return makeInputStream<2>(ptr, len, _flags & SoundMixer::FLAG_UNSIGNED, _flags & SoundMixer::FLAG_16BITS);
+ else
+ return makeInputStream<1>(ptr, len, _flags & SoundMixer::FLAG_UNSIGNED, _flags & SoundMixer::FLAG_16BITS);
+}
+
#endif