aboutsummaryrefslogtreecommitdiff
path: root/sound/audiostream.h
diff options
context:
space:
mode:
authorMax Horn2003-07-24 17:46:38 +0000
committerMax Horn2003-07-24 17:46:38 +0000
commitb9d380bba43b25e1654b320a42b05499c060656c (patch)
treea882712c93b94c0e984c801f1a6ff8bcee515a40 /sound/audiostream.h
parentbecd70d243d456af9595ae0cc37e72b1489736c5 (diff)
downloadscummvm-rg350-b9d380bba43b25e1654b320a42b05499c060656c.tar.gz
scummvm-rg350-b9d380bba43b25e1654b320a42b05499c060656c.tar.bz2
scummvm-rg350-b9d380bba43b25e1654b320a42b05499c060656c.zip
new files, based on SoX (http://sox.sf.net): better resampling code. Note that my mixer.cpp changes are on purpose not yet in CVS since they are not complete. Only reasons I checkin these files is that it's much more comfortable to have CVS, since I need to rewrite parts of resample.cpp now (I already have lots of modifications in). Also expect more OO in the future
svn-id: r9176
Diffstat (limited to 'sound/audiostream.h')
-rw-r--r--sound/audiostream.h91
1 files changed, 91 insertions, 0 deletions
diff --git a/sound/audiostream.h b/sound/audiostream.h
new file mode 100644
index 0000000000..c3d43d6b2a
--- /dev/null
+++ b/sound/audiostream.h
@@ -0,0 +1,91 @@
+/* ScummVM - Scumm Interpreter
+ * Copyright (C) 2001-2003 The ScummVM project
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ * $Header$
+ *
+ */
+
+#ifndef AUDIOSTREAM_H
+#define AUDIOSTREAM_H
+
+/**
+ * Generic input stream for the resampling code.
+ */
+class InputStream {
+public:
+ byte *_ptr;
+ byte *_end;
+ InputStream(byte *ptr, uint len) : _ptr(ptr), _end(ptr+len) { }
+ virtual int16 readIntern() = 0;
+ virtual void advance() = 0;
+public:
+ int16 read() { assert(size() > 0); int16 val = readIntern(); advance(); return val; }
+ int16 peek() { assert(size() > 0); return readIntern(); }
+ virtual int size() = 0;
+ bool eof() { return size() <= 0; }
+};
+
+class ZeroInputStream : public InputStream {
+protected:
+ int16 readIntern() { return 0; }
+ void advance() { _ptr++; }
+public:
+ ZeroInputStream(uint len) : InputStream(0, len) { }
+ virtual int size() { return _end - _ptr; }
+};
+
+template<int channels>
+class Input8bitSignedStream : public InputStream {
+protected:
+ int16 readIntern() { int8 v = (int8)*_ptr; return v << 8; }
+ void advance() { _ptr += channels; }
+public:
+ Input8bitSignedStream(byte *ptr, int len) : InputStream(ptr, len) { }
+ virtual int size() { return (_end - _ptr) / channels; }
+};
+
+template<int channels>
+class Input8bitUnsignedStream : public InputStream {
+protected:
+ int16 readIntern() { int8 v = (int8)(*_ptr ^ 0x80); return v << 8; }
+ void advance() { _ptr += channels; }
+public:
+ Input8bitUnsignedStream(byte *ptr, int len) : InputStream(ptr, len) { }
+ virtual int size() { return (_end - _ptr) / channels; }
+};
+
+template<int channels>
+class Input16bitSignedStream : public InputStream {
+protected:
+ int16 readIntern() { return (int16)READ_BE_UINT16(_ptr); }
+ void advance() { _ptr += 2*channels; }
+public:
+ Input16bitSignedStream(byte *ptr, int len) : InputStream(ptr, len) { }
+ virtual int size() { return (_end - _ptr) / (2 * channels); }
+};
+
+template<int channels>
+class Input16bitUnsignedStream : public InputStream {
+protected:
+ int16 readIntern() { return (int16)(READ_BE_UINT16(_ptr) ^ 0x8000); }
+ void advance() { _ptr += 2*channels; }
+public:
+ Input16bitUnsignedStream(byte *ptr, int len) : InputStream(ptr, len) { }
+ virtual int size() { return (_end - _ptr) / (2 * channels); }
+};
+
+#endif