2007-05-30 21:56:52 +00:00
|
|
|
/* ScummVM - Graphic Adventure Engine
|
|
|
|
*
|
|
|
|
* ScummVM is the legal property of its developers, whose names
|
|
|
|
* are too numerous to list here. Please refer to the COPYRIGHT
|
|
|
|
* file distributed with this source distribution.
|
2003-07-25 13:42:05 +00:00
|
|
|
*
|
|
|
|
* 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
|
2005-10-18 01:30:26 +00:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
2003-07-25 13:42:05 +00:00
|
|
|
*
|
2006-02-11 10:05:31 +00:00
|
|
|
* $URL$
|
|
|
|
* $Id$
|
2003-07-25 13:42:05 +00:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2006-03-29 15:59:37 +00:00
|
|
|
#include "common/endian.h"
|
2003-07-31 01:21:38 +00:00
|
|
|
#include "common/file.h"
|
2007-02-28 14:48:26 +00:00
|
|
|
#include "common/list.h"
|
2003-07-29 01:37:03 +00:00
|
|
|
#include "common/util.h"
|
2006-03-29 15:59:37 +00:00
|
|
|
|
2003-12-19 00:32:47 +00:00
|
|
|
#include "sound/audiostream.h"
|
|
|
|
#include "sound/mixer.h"
|
2004-02-22 14:11:16 +00:00
|
|
|
#include "sound/mp3.h"
|
|
|
|
#include "sound/vorbis.h"
|
|
|
|
#include "sound/flac.h"
|
2003-08-07 22:19:55 +00:00
|
|
|
|
2006-04-29 22:33:31 +00:00
|
|
|
|
2007-02-28 12:54:59 +00:00
|
|
|
// This used to be an inline template function, but
|
|
|
|
// buggy template function handling in MSVC6 forced
|
|
|
|
// us to go with the macro approach. So far this is
|
|
|
|
// the only template function that MSVC6 seemed to
|
|
|
|
// compile incorrectly. Knock on wood.
|
|
|
|
#define READ_ENDIAN_SAMPLE(is16Bit, isUnsigned, ptr, isLE) \
|
|
|
|
((is16Bit ? (isLE ? READ_LE_UINT16(ptr) : READ_BE_UINT16(ptr)) : (*ptr << 8)) ^ (isUnsigned ? 0x8000 : 0))
|
|
|
|
|
|
|
|
|
2006-04-29 22:33:31 +00:00
|
|
|
namespace Audio {
|
|
|
|
|
2004-02-22 14:11:16 +00:00
|
|
|
struct StreamFileFormat {
|
|
|
|
/** Decodername */
|
|
|
|
const char* decoderName;
|
|
|
|
const char* fileExtension;
|
2005-07-30 21:11:48 +00:00
|
|
|
/**
|
2004-02-22 14:11:16 +00:00
|
|
|
* Pointer to a function which tries to open a file of type StreamFormat.
|
2005-07-30 21:11:48 +00:00
|
|
|
* Return NULL in case of an error (invalid/nonexisting file).
|
2004-02-22 14:11:16 +00:00
|
|
|
*/
|
2007-02-24 23:53:35 +00:00
|
|
|
AudioStream* (*openStreamFile)(Common::SeekableReadStream *stream, bool disposeAfterUse,
|
|
|
|
uint32 startTime, uint32 duration, uint numLoops);
|
2004-02-22 14:11:16 +00:00
|
|
|
};
|
|
|
|
|
2005-07-30 21:11:48 +00:00
|
|
|
static const StreamFileFormat STREAM_FILEFORMATS[] = {
|
|
|
|
/* decoderName, fileExt, openStreamFuntion */
|
2004-02-22 14:11:16 +00:00
|
|
|
#ifdef USE_FLAC
|
2007-04-14 17:12:43 +00:00
|
|
|
{ "Flac", ".flac", makeFlacStream },
|
|
|
|
{ "Flac", ".fla", makeFlacStream },
|
2005-08-10 06:16:26 +00:00
|
|
|
#endif
|
2005-08-10 12:42:56 +00:00
|
|
|
#ifdef USE_VORBIS
|
2007-04-14 17:12:43 +00:00
|
|
|
{ "Ogg Vorbis", ".ogg", makeVorbisStream },
|
2005-08-10 06:16:26 +00:00
|
|
|
#endif
|
2004-02-22 14:11:16 +00:00
|
|
|
#ifdef USE_MAD
|
2007-04-14 17:12:43 +00:00
|
|
|
{ "MPEG Layer 3", ".mp3", makeMP3Stream },
|
2005-08-10 06:16:26 +00:00
|
|
|
#endif
|
2004-02-22 14:11:16 +00:00
|
|
|
|
|
|
|
{ NULL, NULL, NULL } // Terminator
|
|
|
|
};
|
|
|
|
|
2007-04-14 17:12:43 +00:00
|
|
|
AudioStream* AudioStream::openStreamFile(const Common::String &basename, uint32 startTime, uint32 duration, uint numLoops) {
|
2004-02-22 14:11:16 +00:00
|
|
|
AudioStream* stream = NULL;
|
2005-05-10 22:56:25 +00:00
|
|
|
Common::File *fileHandle = new Common::File();
|
2004-02-22 14:11:16 +00:00
|
|
|
|
|
|
|
for (int i = 0; i < ARRAYSIZE(STREAM_FILEFORMATS)-1 && stream == NULL; ++i) {
|
2007-04-14 17:12:43 +00:00
|
|
|
Common::String filename = basename + STREAM_FILEFORMATS[i].fileExtension;
|
|
|
|
fileHandle->open(filename);
|
2007-02-24 23:53:35 +00:00
|
|
|
if (fileHandle->isOpen()) {
|
2007-04-14 17:12:43 +00:00
|
|
|
// Create the stream object
|
|
|
|
stream = STREAM_FILEFORMATS[i].openStreamFile(fileHandle, true, startTime, duration, numLoops);
|
2007-02-24 23:53:35 +00:00
|
|
|
fileHandle = 0;
|
|
|
|
break;
|
|
|
|
}
|
2004-02-22 14:11:16 +00:00
|
|
|
}
|
2005-07-30 21:11:48 +00:00
|
|
|
|
2007-02-24 23:53:35 +00:00
|
|
|
delete fileHandle;
|
2004-02-22 14:11:16 +00:00
|
|
|
|
|
|
|
if (stream == NULL) {
|
2007-04-14 17:12:43 +00:00
|
|
|
debug(1, "AudioStream: Could not open compressed AudioFile %s", basename.c_str());
|
2004-02-22 14:11:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return stream;
|
|
|
|
}
|
|
|
|
|
2003-07-28 17:28:29 +00:00
|
|
|
#pragma mark -
|
2003-07-28 18:01:56 +00:00
|
|
|
#pragma mark --- LinearMemoryStream ---
|
2003-07-28 17:28:29 +00:00
|
|
|
#pragma mark -
|
|
|
|
|
|
|
|
|
2003-12-21 00:26:36 +00:00
|
|
|
/**
|
|
|
|
* A simple raw audio stream, purely memory based. It operates on a single
|
2005-07-30 21:11:48 +00:00
|
|
|
* block of data, which is passed to it upon creation.
|
2003-12-21 00:26:36 +00:00
|
|
|
* Optionally supports looping the sound.
|
|
|
|
*
|
2007-03-01 13:51:04 +00:00
|
|
|
* Design note: This code tries to be as efficient as possible (without
|
2003-12-21 00:26:36 +00:00
|
|
|
* resorting to assembly, that is). To this end, it is written as a template
|
2007-03-01 13:51:04 +00:00
|
|
|
* class. This way the compiler can create optimized code for each special
|
|
|
|
* case. This results in a total of 12 versions of the code being generated.
|
2003-12-21 00:26:36 +00:00
|
|
|
*/
|
2003-12-16 02:11:04 +00:00
|
|
|
template<bool stereo, bool is16Bit, bool isUnsigned, bool isLE>
|
2004-01-03 14:10:13 +00:00
|
|
|
class LinearMemoryStream : public AudioStream {
|
2003-07-25 13:42:05 +00:00
|
|
|
protected:
|
|
|
|
const byte *_ptr;
|
|
|
|
const byte *_end;
|
2003-08-01 16:32:11 +00:00
|
|
|
const byte *_loopPtr;
|
|
|
|
const byte *_loopEnd;
|
2003-12-17 02:19:24 +00:00
|
|
|
const int _rate;
|
2003-12-21 00:26:36 +00:00
|
|
|
const byte *_origPtr;
|
2003-07-28 17:28:29 +00:00
|
|
|
|
2003-08-04 22:15:16 +00:00
|
|
|
public:
|
2003-12-21 00:26:36 +00:00
|
|
|
LinearMemoryStream(int rate, const byte *ptr, uint len, uint loopOffset, uint loopLen, bool autoFreeMemory)
|
2003-12-17 02:19:24 +00:00
|
|
|
: _ptr(ptr), _end(ptr+len), _loopPtr(0), _loopEnd(0), _rate(rate) {
|
2003-08-07 23:54:39 +00:00
|
|
|
|
|
|
|
// Verify the buffer sizes are sane
|
|
|
|
if (is16Bit && stereo)
|
|
|
|
assert((len & 3) == 0 && (loopLen & 3) == 0);
|
|
|
|
else if (is16Bit || stereo)
|
|
|
|
assert((len & 1) == 0 && (loopLen & 1) == 0);
|
|
|
|
|
2003-08-04 22:15:16 +00:00
|
|
|
if (loopLen) {
|
|
|
|
_loopPtr = _ptr + loopOffset;
|
|
|
|
_loopEnd = _loopPtr + loopLen;
|
|
|
|
}
|
|
|
|
if (stereo) // Stereo requires even sized data
|
|
|
|
assert(len % 2 == 0);
|
2005-07-30 21:11:48 +00:00
|
|
|
|
2003-12-21 00:26:36 +00:00
|
|
|
_origPtr = autoFreeMemory ? ptr : 0;
|
|
|
|
}
|
|
|
|
~LinearMemoryStream() {
|
|
|
|
free(const_cast<byte *>(_origPtr));
|
2003-07-28 17:28:29 +00:00
|
|
|
}
|
2003-08-07 22:19:55 +00:00
|
|
|
int readBuffer(int16 *buffer, const int numSamples);
|
2003-08-04 22:15:16 +00:00
|
|
|
|
|
|
|
bool isStereo() const { return stereo; }
|
2007-02-28 14:48:26 +00:00
|
|
|
bool endOfData() const { return _ptr >= _end; }
|
2003-12-17 02:19:24 +00:00
|
|
|
|
|
|
|
int getRate() const { return _rate; }
|
2003-07-25 13:42:05 +00:00
|
|
|
};
|
|
|
|
|
2003-12-16 02:11:04 +00:00
|
|
|
template<bool stereo, bool is16Bit, bool isUnsigned, bool isLE>
|
|
|
|
int LinearMemoryStream<stereo, is16Bit, isUnsigned, isLE>::readBuffer(int16 *buffer, const int numSamples) {
|
2007-06-24 17:42:36 +00:00
|
|
|
int samples = numSamples;
|
|
|
|
while (samples > 0 && _ptr < _end) {
|
2007-06-25 21:09:08 +00:00
|
|
|
int len = MIN(samples, (int)(_end - _ptr) / (is16Bit ? 2 : 1));
|
2007-06-24 17:42:36 +00:00
|
|
|
samples -= len;
|
|
|
|
do {
|
2003-12-16 02:11:04 +00:00
|
|
|
*buffer++ = READ_ENDIAN_SAMPLE(is16Bit, isUnsigned, _ptr, isLE);
|
2003-08-05 01:14:27 +00:00
|
|
|
_ptr += (is16Bit ? 2 : 1);
|
2007-06-24 17:42:36 +00:00
|
|
|
} while (--len);
|
2003-08-05 01:14:27 +00:00
|
|
|
// Loop, if looping was specified
|
2007-02-28 14:48:26 +00:00
|
|
|
if (_loopPtr && _ptr >= _end) {
|
2003-08-05 01:14:27 +00:00
|
|
|
_ptr = _loopPtr;
|
|
|
|
_end = _loopEnd;
|
|
|
|
}
|
|
|
|
}
|
2007-06-24 17:42:36 +00:00
|
|
|
return numSamples-samples;
|
2003-08-05 01:14:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-07-28 17:28:29 +00:00
|
|
|
#pragma mark -
|
2005-01-09 03:15:59 +00:00
|
|
|
#pragma mark --- Input stream factory ---
|
2003-07-28 17:28:29 +00:00
|
|
|
#pragma mark -
|
2003-07-25 13:42:05 +00:00
|
|
|
|
2003-12-21 00:26:36 +00:00
|
|
|
/* In the following, we use preprocessor / macro tricks to simplify the code
|
|
|
|
* which instantiates the input streams. We used to use template functions for
|
|
|
|
* this, but MSVC6 / EVC 3-4 (used for WinCE builds) are extremely buggy when it
|
|
|
|
* comes to this feature of C++... so as a compromise we use macros to cut down
|
|
|
|
* on the (source) code duplication a bit.
|
|
|
|
* So while normally macro tricks are said to make maintenance harder, in this
|
|
|
|
* particular case it should actually help it :-)
|
|
|
|
*/
|
2003-07-25 13:42:05 +00:00
|
|
|
|
2003-12-21 00:26:36 +00:00
|
|
|
#define MAKE_LINEAR(STEREO, UNSIGNED) \
|
|
|
|
if (is16Bit) { \
|
|
|
|
if (isLE) \
|
2003-12-26 01:32:29 +00:00
|
|
|
return new LinearMemoryStream<STEREO, true, UNSIGNED, true>(rate, ptr, len, loopOffset, loopLen, autoFree); \
|
2003-12-21 00:26:36 +00:00
|
|
|
else \
|
2003-12-26 01:32:29 +00:00
|
|
|
return new LinearMemoryStream<STEREO, true, UNSIGNED, false>(rate, ptr, len, loopOffset, loopLen, autoFree); \
|
2003-12-21 00:26:36 +00:00
|
|
|
} else \
|
2003-12-26 01:32:29 +00:00
|
|
|
return new LinearMemoryStream<STEREO, false, UNSIGNED, false>(rate, ptr, len, loopOffset, loopLen, autoFree)
|
2003-12-21 00:26:36 +00:00
|
|
|
|
2007-03-02 15:26:22 +00:00
|
|
|
AudioStream *makeLinearInputStream(const byte *ptr, uint32 len, int rate, byte flags, uint loopStart, uint loopEnd) {
|
2005-05-10 23:48:48 +00:00
|
|
|
const bool isStereo = (flags & Audio::Mixer::FLAG_STEREO) != 0;
|
|
|
|
const bool is16Bit = (flags & Audio::Mixer::FLAG_16BITS) != 0;
|
|
|
|
const bool isUnsigned = (flags & Audio::Mixer::FLAG_UNSIGNED) != 0;
|
|
|
|
const bool isLE = (flags & Audio::Mixer::FLAG_LITTLE_ENDIAN) != 0;
|
|
|
|
const bool autoFree = (flags & Audio::Mixer::FLAG_AUTOFREE) != 0;
|
2005-07-30 21:11:48 +00:00
|
|
|
|
2007-03-02 15:26:22 +00:00
|
|
|
uint loopOffset = 0, loopLen = 0;
|
|
|
|
if (flags & Audio::Mixer::FLAG_LOOP) {
|
|
|
|
if (loopEnd == 0)
|
|
|
|
loopEnd = len;
|
|
|
|
assert(loopStart <= loopEnd);
|
|
|
|
assert(loopEnd <= len);
|
2007-06-24 17:42:36 +00:00
|
|
|
|
2007-03-02 15:26:22 +00:00
|
|
|
loopOffset = loopStart;
|
|
|
|
loopLen = loopEnd - loopStart;
|
|
|
|
}
|
|
|
|
|
2003-12-21 00:26:36 +00:00
|
|
|
if (isStereo) {
|
|
|
|
if (isUnsigned) {
|
|
|
|
MAKE_LINEAR(true, true);
|
|
|
|
} else {
|
|
|
|
MAKE_LINEAR(true, false);
|
|
|
|
}
|
2003-07-28 18:01:56 +00:00
|
|
|
} else {
|
2003-12-21 00:26:36 +00:00
|
|
|
if (isUnsigned) {
|
|
|
|
MAKE_LINEAR(false, true);
|
|
|
|
} else {
|
|
|
|
MAKE_LINEAR(false, false);
|
|
|
|
}
|
2003-07-28 18:01:56 +00:00
|
|
|
}
|
|
|
|
}
|
2006-04-29 22:33:31 +00:00
|
|
|
|
|
|
|
|
2006-05-18 21:46:07 +00:00
|
|
|
#pragma mark -
|
|
|
|
#pragma mark --- Appendable audio stream ---
|
|
|
|
#pragma mark -
|
|
|
|
|
2007-02-28 14:48:26 +00:00
|
|
|
struct Buffer {
|
|
|
|
byte *start;
|
|
|
|
byte *end;
|
|
|
|
};
|
2006-05-18 21:46:07 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Wrapped memory stream.
|
|
|
|
*/
|
|
|
|
template<bool stereo, bool is16Bit, bool isUnsigned, bool isLE>
|
|
|
|
class AppendableMemoryStream : public AppendableAudioStream {
|
|
|
|
protected:
|
2007-02-28 14:48:26 +00:00
|
|
|
|
|
|
|
// A mutex to avoid access problems (causing e.g. corruption of
|
|
|
|
// the linked list) in thread aware environments.
|
2006-05-18 21:46:07 +00:00
|
|
|
Common::Mutex _mutex;
|
|
|
|
|
2007-06-24 17:42:36 +00:00
|
|
|
// List of all queued buffers
|
2007-02-28 14:48:26 +00:00
|
|
|
Common::List<Buffer> _bufferQueue;
|
|
|
|
|
|
|
|
// Position in the front buffer, if any
|
2006-05-18 21:46:07 +00:00
|
|
|
bool _finalized;
|
|
|
|
const int _rate;
|
2007-02-28 14:48:26 +00:00
|
|
|
byte *_pos;
|
2006-05-18 21:46:07 +00:00
|
|
|
|
2007-02-28 14:48:26 +00:00
|
|
|
inline bool eosIntern() const { return _bufferQueue.empty(); };
|
2006-05-18 21:46:07 +00:00
|
|
|
public:
|
2007-02-28 14:48:26 +00:00
|
|
|
AppendableMemoryStream(int rate);
|
2006-05-18 21:46:07 +00:00
|
|
|
~AppendableMemoryStream();
|
|
|
|
int readBuffer(int16 *buffer, const int numSamples);
|
|
|
|
|
|
|
|
bool isStereo() const { return stereo; }
|
|
|
|
bool endOfStream() const { return _finalized && eosIntern(); }
|
|
|
|
bool endOfData() const { return eosIntern(); }
|
|
|
|
|
|
|
|
int getRate() const { return _rate; }
|
|
|
|
|
2007-02-28 14:48:26 +00:00
|
|
|
void queueBuffer(byte *data, uint32 size);
|
2006-05-18 21:46:07 +00:00
|
|
|
void finish() { _finalized = true; }
|
|
|
|
};
|
|
|
|
|
|
|
|
template<bool stereo, bool is16Bit, bool isUnsigned, bool isLE>
|
2007-02-28 14:48:26 +00:00
|
|
|
AppendableMemoryStream<stereo, is16Bit, isUnsigned, isLE>::AppendableMemoryStream(int rate)
|
|
|
|
: _finalized(false), _rate(rate), _pos(0) {
|
2006-06-19 21:08:34 +00:00
|
|
|
|
2006-05-18 21:46:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
template<bool stereo, bool is16Bit, bool isUnsigned, bool isLE>
|
|
|
|
AppendableMemoryStream<stereo, is16Bit, isUnsigned, isLE>::~AppendableMemoryStream() {
|
2007-02-28 14:48:26 +00:00
|
|
|
// Clear the queue
|
|
|
|
Common::List<Buffer>::iterator iter;
|
|
|
|
for (iter = _bufferQueue.begin(); iter != _bufferQueue.end(); ++iter)
|
|
|
|
delete[] iter->start;
|
2006-05-18 21:46:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
template<bool stereo, bool is16Bit, bool isUnsigned, bool isLE>
|
|
|
|
int AppendableMemoryStream<stereo, is16Bit, isUnsigned, isLE>::readBuffer(int16 *buffer, const int numSamples) {
|
|
|
|
Common::StackLock lock(_mutex);
|
|
|
|
|
2007-06-24 17:42:36 +00:00
|
|
|
int samples = numSamples;
|
|
|
|
while (samples > 0 && !eosIntern()) {
|
2007-02-28 14:48:26 +00:00
|
|
|
Buffer buf = *_bufferQueue.begin();
|
|
|
|
if (_pos == 0)
|
|
|
|
_pos = buf.start;
|
|
|
|
|
|
|
|
assert(buf.start <= _pos && _pos <= buf.end);
|
|
|
|
const int samplesLeftInCurBuffer = buf.end - _pos;
|
|
|
|
if (samplesLeftInCurBuffer == 0) {
|
2007-04-09 19:49:03 +00:00
|
|
|
delete [] buf.start;
|
2007-02-28 14:48:26 +00:00
|
|
|
_bufferQueue.erase(_bufferQueue.begin());
|
|
|
|
_pos = 0;
|
|
|
|
continue;
|
|
|
|
}
|
2006-05-18 21:46:07 +00:00
|
|
|
|
2007-06-24 17:42:36 +00:00
|
|
|
int len = MIN(samples, samplesLeftInCurBuffer / (is16Bit ? 2 : 1));
|
|
|
|
samples -= len;
|
|
|
|
do {
|
2006-05-18 21:46:07 +00:00
|
|
|
*buffer++ = READ_ENDIAN_SAMPLE(is16Bit, isUnsigned, _pos, isLE);
|
|
|
|
_pos += (is16Bit ? 2 : 1);
|
2007-06-24 17:42:36 +00:00
|
|
|
} while (--len);
|
2006-05-18 21:46:07 +00:00
|
|
|
}
|
|
|
|
|
2007-06-24 17:42:36 +00:00
|
|
|
return numSamples-samples;
|
2006-05-18 21:46:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
template<bool stereo, bool is16Bit, bool isUnsigned, bool isLE>
|
2007-02-28 14:48:26 +00:00
|
|
|
void AppendableMemoryStream<stereo, is16Bit, isUnsigned, isLE>::queueBuffer(byte *data, uint32 size) {
|
2006-05-18 21:46:07 +00:00
|
|
|
Common::StackLock lock(_mutex);
|
|
|
|
|
|
|
|
// Verify the buffer size is sane
|
|
|
|
if (is16Bit && stereo)
|
2007-02-28 14:48:26 +00:00
|
|
|
assert((size & 3) == 0);
|
2006-05-18 21:46:07 +00:00
|
|
|
else if (is16Bit || stereo)
|
2007-02-28 14:48:26 +00:00
|
|
|
assert((size & 1) == 0);
|
2006-05-18 21:46:07 +00:00
|
|
|
|
|
|
|
// Verify that the stream has not yet been finalized (by a call to finish())
|
|
|
|
assert(!_finalized);
|
|
|
|
|
2007-02-28 14:48:26 +00:00
|
|
|
// Queue the buffer
|
|
|
|
Buffer buf = {data, data+size};
|
|
|
|
_bufferQueue.push_back(buf);
|
|
|
|
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
// Output some stats
|
|
|
|
uint totalSize = 0;
|
|
|
|
Common::List<Buffer>::iterator iter;
|
|
|
|
for (iter = _bufferQueue.begin(); iter != _bufferQueue.end(); ++iter)
|
|
|
|
totalSize += iter->end - iter->start;
|
|
|
|
printf("AppendableMemoryStream::queueBuffer: added a %d byte buf, a total of %d bytes are queued\n",
|
|
|
|
size, totalSize);
|
|
|
|
#endif
|
2006-05-18 21:46:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#define MAKE_WRAPPED(STEREO, UNSIGNED) \
|
|
|
|
if (is16Bit) { \
|
|
|
|
if (isLE) \
|
2007-02-28 14:48:26 +00:00
|
|
|
return new AppendableMemoryStream<STEREO, true, UNSIGNED, true>(rate); \
|
2006-05-18 21:46:07 +00:00
|
|
|
else \
|
2007-02-28 14:48:26 +00:00
|
|
|
return new AppendableMemoryStream<STEREO, true, UNSIGNED, false>(rate); \
|
2006-05-18 21:46:07 +00:00
|
|
|
} else \
|
2007-02-28 14:48:26 +00:00
|
|
|
return new AppendableMemoryStream<STEREO, false, UNSIGNED, false>(rate)
|
2006-05-18 21:46:07 +00:00
|
|
|
|
2007-02-28 14:48:26 +00:00
|
|
|
AppendableAudioStream *makeAppendableAudioStream(int rate, byte _flags) {
|
2006-05-18 21:46:07 +00:00
|
|
|
const bool isStereo = (_flags & Audio::Mixer::FLAG_STEREO) != 0;
|
|
|
|
const bool is16Bit = (_flags & Audio::Mixer::FLAG_16BITS) != 0;
|
|
|
|
const bool isUnsigned = (_flags & Audio::Mixer::FLAG_UNSIGNED) != 0;
|
|
|
|
const bool isLE = (_flags & Audio::Mixer::FLAG_LITTLE_ENDIAN) != 0;
|
|
|
|
|
|
|
|
if (isStereo) {
|
|
|
|
if (isUnsigned) {
|
|
|
|
MAKE_WRAPPED(true, true);
|
|
|
|
} else {
|
|
|
|
MAKE_WRAPPED(true, false);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (isUnsigned) {
|
|
|
|
MAKE_WRAPPED(false, true);
|
|
|
|
} else {
|
|
|
|
MAKE_WRAPPED(false, false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-04-29 22:33:31 +00:00
|
|
|
} // End of namespace Audio
|