Remove RawMemoryStream.
svn-id: r47717
This commit is contained in:
parent
a505d32eff
commit
3cc0ef6c1c
7 changed files with 6 additions and 144 deletions
|
@ -253,7 +253,7 @@ bool SubSeekableAudioStream::seek(const Timestamp &where) {
|
|||
|
||||
|
||||
void QueuingAudioStream::queueBuffer(byte *data, uint32 size, DisposeAfterUse::Flag disposeAfterUse, byte flags) {
|
||||
AudioStream *stream = makeRawMemoryStream(data, size, getRate(), flags, disposeAfterUse);
|
||||
AudioStream *stream = makeRawStream(data, size, getRate(), flags, disposeAfterUse);
|
||||
queueAudioStream(stream, DisposeAfterUse::YES);
|
||||
}
|
||||
|
||||
|
|
|
@ -173,7 +173,7 @@ SeekableAudioStream *makeAIFFStream(Common::SeekableReadStream &stream) {
|
|||
stream.read(data, size);
|
||||
|
||||
// Since we allocated our own buffer for the data, we must specify DisposeAfterUse::YES.
|
||||
return makeRawMemoryStream(data, size, rate, flags);
|
||||
return makeRawStream(data, size, rate, flags);
|
||||
}
|
||||
|
||||
} // End of namespace Audio
|
||||
|
|
|
@ -108,7 +108,7 @@ AudioStream *make8SVXStream(Common::ReadStream &input, bool loop) {
|
|||
A8SVXLoader loader;
|
||||
loader.load(input);
|
||||
|
||||
SeekableAudioStream *stream = Audio::makeRawMemoryStream((byte *)loader._data, loader._dataSize, loader._header.samplesPerSec, 0);
|
||||
SeekableAudioStream *stream = Audio::makeRawStream((byte *)loader._data, loader._dataSize, loader._header.samplesPerSec, 0);
|
||||
|
||||
uint32 loopStart = 0, loopEnd = 0;
|
||||
if (loop) {
|
||||
|
|
|
@ -41,87 +41,10 @@ namespace Audio {
|
|||
((is16Bit ? (isLE ? READ_LE_UINT16(ptr) : READ_BE_UINT16(ptr)) : (*ptr << 8)) ^ (isUnsigned ? 0x8000 : 0))
|
||||
|
||||
|
||||
#pragma mark -
|
||||
#pragma mark --- RawMemoryStream ---
|
||||
#pragma mark -
|
||||
|
||||
/**
|
||||
* A simple raw audio stream, purely memory based. It operates on a single
|
||||
* block of data, which is passed to it upon creation.
|
||||
* Optionally supports looping the sound.
|
||||
*
|
||||
* Design note: This code tries to be as efficient as possible (without
|
||||
* resorting to assembly, that is). To this end, it is written as a template
|
||||
* 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.
|
||||
*/
|
||||
template<bool stereo, bool is16Bit, bool isUnsigned, bool isLE>
|
||||
class RawMemoryStream : public SeekableAudioStream {
|
||||
protected:
|
||||
const byte *_ptr;
|
||||
const byte *_end;
|
||||
const int _rate;
|
||||
const byte *_origPtr;
|
||||
const DisposeAfterUse::Flag _disposeAfterUse;
|
||||
const Timestamp _playtime;
|
||||
|
||||
public:
|
||||
RawMemoryStream(int rate, const byte *ptr, uint len, DisposeAfterUse::Flag autoFreeMemory)
|
||||
: _ptr(ptr), _end(ptr+len), _rate(rate), _origPtr(ptr),
|
||||
_disposeAfterUse(autoFreeMemory),
|
||||
_playtime(0, len / (is16Bit ? 2 : 1) / (stereo ? 2 : 1), rate) {
|
||||
}
|
||||
|
||||
virtual ~RawMemoryStream() {
|
||||
if (_disposeAfterUse == DisposeAfterUse::YES)
|
||||
free(const_cast<byte *>(_origPtr));
|
||||
}
|
||||
|
||||
int readBuffer(int16 *buffer, const int numSamples);
|
||||
|
||||
bool isStereo() const { return stereo; }
|
||||
bool endOfData() const { return _ptr >= _end; }
|
||||
|
||||
int getRate() const { return _rate; }
|
||||
bool seek(const Timestamp &where);
|
||||
Timestamp getLength() const { return _playtime; }
|
||||
};
|
||||
|
||||
template<bool stereo, bool is16Bit, bool isUnsigned, bool isLE>
|
||||
int RawMemoryStream<stereo, is16Bit, isUnsigned, isLE>::readBuffer(int16 *buffer, const int numSamples) {
|
||||
int samples = numSamples;
|
||||
while (samples > 0 && _ptr < _end) {
|
||||
int len = MIN(samples, (int)(_end - _ptr) / (is16Bit ? 2 : 1));
|
||||
samples -= len;
|
||||
do {
|
||||
*buffer++ = READ_ENDIAN_SAMPLE(is16Bit, isUnsigned, _ptr, isLE);
|
||||
_ptr += (is16Bit ? 2 : 1);
|
||||
} while (--len);
|
||||
}
|
||||
return numSamples-samples;
|
||||
}
|
||||
|
||||
template<bool stereo, bool is16Bit, bool isUnsigned, bool isLE>
|
||||
bool RawMemoryStream<stereo, is16Bit, isUnsigned, isLE>::seek(const Timestamp &where) {
|
||||
const uint8 *ptr = _origPtr + convertTimeToStreamPos(where, getRate(), isStereo()).totalNumberOfFrames() * (is16Bit ? 2 : 1);
|
||||
if (ptr > _end) {
|
||||
_ptr = _end;
|
||||
return false;
|
||||
} else if (ptr == _end) {
|
||||
_ptr = _end;
|
||||
return true;
|
||||
} else {
|
||||
_ptr = ptr;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
#pragma mark -
|
||||
#pragma mark --- RawDiskStream ---
|
||||
#pragma mark -
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* RawDiskStream. This can stream raw PCM audio data from disk. The
|
||||
* function takes an pointer to an array of RawDiskStreamAudioBlock which defines the
|
||||
|
@ -153,7 +76,7 @@ protected:
|
|||
RawStreamBlockList::const_iterator _curBlock; ///< Current audio block number
|
||||
public:
|
||||
RawDiskStream(int rate, DisposeAfterUse::Flag disposeStream, Common::SeekableReadStream *stream, const RawStreamBlockList &blocks)
|
||||
: _rate(rate), _playtime(0, rate), _stream(stream), _disposeAfterUse(disposeStream), _blocks(blocks), _curBlock(blocks.begin()) {
|
||||
: _rate(rate), _playtime(0, rate), _stream(stream), _disposeAfterUse(disposeStream), _blocks(blocks), _curBlock(_blocks.begin()) {
|
||||
|
||||
assert(_blocks.size() > 0);
|
||||
|
||||
|
@ -299,46 +222,6 @@ bool RawDiskStream<stereo, is16Bit, isUnsigned, isLE>::seek(const Timestamp &whe
|
|||
* particular case it should actually help it :-)
|
||||
*/
|
||||
|
||||
#define MAKE_LINEAR(STEREO, UNSIGNED) \
|
||||
if (is16Bit) { \
|
||||
if (isLE) \
|
||||
return new RawMemoryStream<STEREO, true, UNSIGNED, true>(rate, ptr, len, autoFree); \
|
||||
else \
|
||||
return new RawMemoryStream<STEREO, true, UNSIGNED, false>(rate, ptr, len, autoFree); \
|
||||
} else \
|
||||
return new RawMemoryStream<STEREO, false, UNSIGNED, false>(rate, ptr, len, autoFree)
|
||||
|
||||
SeekableAudioStream *makeRawMemoryStream(const byte *ptr, uint32 len,
|
||||
int rate, byte flags,
|
||||
DisposeAfterUse::Flag autoFree
|
||||
) {
|
||||
const bool isStereo = (flags & Audio::FLAG_STEREO) != 0;
|
||||
const bool is16Bit = (flags & Audio::FLAG_16BITS) != 0;
|
||||
const bool isUnsigned = (flags & Audio::FLAG_UNSIGNED) != 0;
|
||||
const bool isLE = (flags & Audio::FLAG_LITTLE_ENDIAN) != 0;
|
||||
|
||||
// Verify the buffer sizes are sane
|
||||
if (is16Bit && isStereo) {
|
||||
assert((len & 3) == 0);
|
||||
} else if (is16Bit || isStereo) {
|
||||
assert((len & 1) == 0);
|
||||
}
|
||||
|
||||
if (isStereo) {
|
||||
if (isUnsigned) {
|
||||
MAKE_LINEAR(true, true);
|
||||
} else {
|
||||
MAKE_LINEAR(true, false);
|
||||
}
|
||||
} else {
|
||||
if (isUnsigned) {
|
||||
MAKE_LINEAR(false, true);
|
||||
} else {
|
||||
MAKE_LINEAR(false, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#define MAKE_LINEAR_DISK(STEREO, UNSIGNED) \
|
||||
if (is16Bit) { \
|
||||
if (isLE) \
|
||||
|
|
|
@ -64,27 +64,6 @@ enum RawFlags {
|
|||
};
|
||||
|
||||
|
||||
/**
|
||||
* Creates a audio stream, which plays the given raw data.
|
||||
*
|
||||
* The data pointer is assumed to have been allocated with malloc().
|
||||
* In particular, if autofreeBuffer is set to DisposeAfterUse::YES,
|
||||
* then this buffer will be deallocated using free(). So do not
|
||||
* use a buffer allocated with new[]!
|
||||
*
|
||||
* @param ptr pointer to a buffer containing audio data
|
||||
* @param len length of the buffer in bytes
|
||||
* @param rate sample rate of the data
|
||||
* @param flags audio format flags combination
|
||||
* @see RawFlags
|
||||
* @param autofreeBuffer whether the data buffer should be destroyed after playback
|
||||
* @return The new SeekableAudioStream (or 0 on failure).
|
||||
*/
|
||||
SeekableAudioStream *makeRawMemoryStream(const byte *ptr, uint32 len,
|
||||
int rate, byte flags,
|
||||
DisposeAfterUse::Flag autofreeBuffer = DisposeAfterUse::YES
|
||||
);
|
||||
|
||||
/**
|
||||
* Struct used to define the audio data to be played by a RawDiskStream.
|
||||
*/
|
||||
|
|
|
@ -390,7 +390,7 @@ SeekableAudioStream *makeVOCStream(Common::SeekableReadStream &stream, byte flag
|
|||
if (!data)
|
||||
return 0;
|
||||
|
||||
return makeRawMemoryStream(data, size, rate, flags);
|
||||
return makeRawStream(data, size, rate, flags);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
|
|
@ -188,7 +188,7 @@ RewindableAudioStream *makeWAVStream(Common::SeekableReadStream *stream, Dispose
|
|||
if (disposeAfterUse == DisposeAfterUse::YES)
|
||||
delete stream;
|
||||
|
||||
return makeRawMemoryStream(data, size, rate, flags);
|
||||
return makeRawStream(data, size, rate, flags);
|
||||
}
|
||||
|
||||
} // End of namespace Audio
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue