aboutsummaryrefslogtreecommitdiff
path: root/sound/decoders
diff options
context:
space:
mode:
Diffstat (limited to 'sound/decoders')
-rw-r--r--sound/decoders/raw.cpp51
-rw-r--r--sound/decoders/raw.h46
-rw-r--r--sound/decoders/voc.cpp4
3 files changed, 83 insertions, 18 deletions
diff --git a/sound/decoders/raw.cpp b/sound/decoders/raw.cpp
index cf114a25cc..f726d91cc5 100644
--- a/sound/decoders/raw.cpp
+++ b/sound/decoders/raw.cpp
@@ -370,29 +370,31 @@ AudioStream *makeRawMemoryStream_OLD(const byte *ptr, uint32 len,
}
}
-
-
#define MAKE_LINEAR_DISK(STEREO, UNSIGNED) \
if (is16Bit) { \
if (isLE) \
- return new RawDiskStream<STEREO, true, UNSIGNED, true>(rate, disposeStream, stream, blocks); \
+ return new RawDiskStream<STEREO, true, UNSIGNED, true>(rate, disposeAfterUse, stream, blockList); \
else \
- return new RawDiskStream<STEREO, true, UNSIGNED, false>(rate, disposeStream, stream, blocks); \
+ return new RawDiskStream<STEREO, true, UNSIGNED, false>(rate, disposeAfterUse, stream, blockList); \
} else \
- return new RawDiskStream<STEREO, false, UNSIGNED, false>(rate, disposeStream, stream, blocks)
-
+ return new RawDiskStream<STEREO, false, UNSIGNED, false>(rate, disposeAfterUse, stream, blockList)
-SeekableAudioStream *makeRawDiskStream(Common::SeekableReadStream *stream, RawDiskStreamAudioBlock *block, int numBlocks,
- int rate, byte flags, DisposeAfterUse::Flag disposeStream) {
+SeekableAudioStream *makeRawStream(Common::SeekableReadStream *stream,
+ const RawStreamBlockList &blockList,
+ int rate,
+ byte flags,
+ DisposeAfterUse::Flag disposeAfterUse) {
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;
- assert(numBlocks > 0);
- RawStreamBlockList blocks;
- for (int i = 0; i < numBlocks; ++i)
- blocks.push_back(block[i]);
+ if (blockList.empty()) {
+ warning("Empty block list passed to makeRawStream");
+ if (disposeAfterUse == DisposeAfterUse::YES)
+ delete stream;
+ return 0;
+ }
if (isStereo) {
if (isUnsigned) {
@@ -409,4 +411,29 @@ SeekableAudioStream *makeRawDiskStream(Common::SeekableReadStream *stream, RawDi
}
}
+SeekableAudioStream *makeRawStream(Common::SeekableReadStream *stream,
+ int rate, byte flags,
+ DisposeAfterUse::Flag disposeAfterUse) {
+ RawStreamBlockList blocks;
+ RawDiskStreamAudioBlock block;
+ block.pos = 0;
+
+ const bool is16Bit = (flags & Audio::FLAG_16BITS) != 0;
+
+ block.len = stream->size() / (is16Bit ? 2 : 1);
+ blocks.push_back(block);
+
+ return makeRawStream(stream, blocks, rate, flags, disposeAfterUse);
+}
+
+SeekableAudioStream *makeRawDiskStream_OLD(Common::SeekableReadStream *stream, RawDiskStreamAudioBlock *block, int numBlocks,
+ int rate, byte flags, DisposeAfterUse::Flag disposeStream) {
+ assert(numBlocks > 0);
+ RawStreamBlockList blocks;
+ for (int i = 0; i < numBlocks; ++i)
+ blocks.push_back(block[i]);
+
+ return makeRawStream(stream, blocks, rate, flags, disposeStream);
+}
+
} // End of namespace Audio
diff --git a/sound/decoders/raw.h b/sound/decoders/raw.h
index 4136c9953e..c3be9f16a1 100644
--- a/sound/decoders/raw.h
+++ b/sound/decoders/raw.h
@@ -76,7 +76,7 @@ enum RawFlags {
* @param len length of the buffer in bytes
* @param rate sample rate of the data
* @param flags audio format flags combination
- * @see Mixer::RawFlags
+ * @see RawFlags
* @param autofreeBuffer whether the data buffer should be destroyed after playback
* @return The new SeekableAudioStream (or 0 on failure).
*/
@@ -108,15 +108,53 @@ AudioStream *makeRawMemoryStream_OLD(const byte *ptr, uint32 len,
*/
struct RawDiskStreamAudioBlock {
int32 pos; ///< Position in stream of the block (in bytes of course!)
- int32 len; ///< Length of the block (in samples)
+ int32 len; ///< Length of the block (in sample (pairs))
};
/**
* List containing all blocks of a raw stream.
+ * @see RawDiskStreamAudioBlock
*/
typedef Common::List<RawDiskStreamAudioBlock> RawStreamBlockList;
/**
+ * Creates an audio stream, which plays from the given stream.
+ *
+ * @param stream Stream object to play from.
+ * @param size Size of the buffer.
+ * @param rate Rate of the sound data.
+ * @param flags Audio flags combination.
+ * @see RawFlags
+ * @param disposeAfterUse Whether to delete the stream after use.
+ * @return The new SeekableAudioStream (or 0 on failure).
+ */
+SeekableAudioStream *makeRawStream(Common::SeekableReadStream *stream,
+ int rate, byte flags,
+ DisposeAfterUse::Flag disposeAfterUse = DisposeAfterUse::YES);
+
+/**
+ * Creates an audio stream, which plays from the given stream.
+ *
+ * @param stream Stream object to play from.
+ * @param blockList List of blocks to play.
+ * @see RawDiskStreamAudioBlock
+ * @see RawStreamBlockList
+ * @param rate Rate of the sound data.
+ * @param flags Audio flags combination.
+ * @see RawFlags
+ * @param disposeAfterUse Whether to delete the stream after use.
+ * @return The new SeekableAudioStream (or 0 on failure).
+ */
+SeekableAudioStream *makeRawStream(Common::SeekableReadStream *stream,
+ const RawStreamBlockList &blockList,
+ int rate,
+ byte flags,
+ DisposeAfterUse::Flag disposeAfterUse = DisposeAfterUse::YES);
+
+/**
+ * NOTE:
+ * This API is considered deprecated.
+ *
* Creates a audio stream, which plays from given stream.
*
* @param stream Stream to play from
@@ -125,11 +163,11 @@ typedef Common::List<RawDiskStreamAudioBlock> RawStreamBlockList;
* @param numBlocks Number of blocks.
* @param rate The rate
* @param flags Flags combination.
- * @see Mixer::RawFlags
+ * @see RawFlags
* @param disposeStream Whether the "stream" object should be destroyed after playback.
* @return The new SeekableAudioStream (or 0 on failure).
*/
-SeekableAudioStream *makeRawDiskStream(Common::SeekableReadStream *stream,
+SeekableAudioStream *makeRawDiskStream_OLD(Common::SeekableReadStream *stream,
RawDiskStreamAudioBlock *block, int numBlocks,
int rate, byte flags,
DisposeAfterUse::Flag disposeStream);
diff --git a/sound/decoders/voc.cpp b/sound/decoders/voc.cpp
index 65dd1a3998..23accb010c 100644
--- a/sound/decoders/voc.cpp
+++ b/sound/decoders/voc.cpp
@@ -312,7 +312,7 @@ AudioStream *makeVOCDiskStream(Common::SeekableReadStream &stream, byte flags, D
// Create an audiostream from the data. Note the numBlocks may be 0,
// e.g. when invalid data is encountered. See bug #2890038.
if (numBlocks)
- audioStream = makeRawDiskStream(&stream, block, numBlocks, rate, flags, takeOwnership, begin_loop, end_loop);
+ audioStream = makeRawDiskStream_OLD(&stream, block, numBlocks, rate, flags, takeOwnership/*, begin_loop, end_loop*/);
delete[] block;
@@ -332,7 +332,7 @@ SeekableAudioStream *makeVOCDiskStreamNoLoop(Common::SeekableReadStream &stream,
// Create an audiostream from the data. Note the numBlocks may be 0,
// e.g. when invalid data is encountered. See bug #2890038.
if (numBlocks)
- audioStream = makeRawDiskStream(&stream, block, numBlocks, rate, flags, takeOwnership);
+ audioStream = makeRawDiskStream_OLD(&stream, block, numBlocks, rate, flags, takeOwnership);
delete[] block;