aboutsummaryrefslogtreecommitdiff
path: root/sound
diff options
context:
space:
mode:
authorMax Horn2004-11-27 17:09:05 +0000
committerMax Horn2004-11-27 17:09:05 +0000
commitc51b1266c07d3fbd1d5236a6e5d1dbc1a685203b (patch)
tree5e6e8cb3068fa30a202ed1061b3733773d3bb11c /sound
parent573e02bb4cd733c97caf850b805c25d6691ba718 (diff)
downloadscummvm-rg350-c51b1266c07d3fbd1d5236a6e5d1dbc1a685203b.tar.gz
scummvm-rg350-c51b1266c07d3fbd1d5236a6e5d1dbc1a685203b.tar.bz2
scummvm-rg350-c51b1266c07d3fbd1d5236a6e5d1dbc1a685203b.zip
Removed the (highly SCUMM specific) 'appendable stream' API from SoundMixer; SCUMM now uses the appendable stream directly
svn-id: r15919
Diffstat (limited to 'sound')
-rw-r--r--sound/audiostream.cpp15
-rw-r--r--sound/mixer.cpp88
-rw-r--r--sound/mixer.h16
3 files changed, 14 insertions, 105 deletions
diff --git a/sound/audiostream.cpp b/sound/audiostream.cpp
index 81c051221f..348b4084f7 100644
--- a/sound/audiostream.cpp
+++ b/sound/audiostream.cpp
@@ -186,6 +186,8 @@ int LinearMemoryStream<stereo, is16Bit, isUnsigned, isLE>::readBuffer(int16 *buf
template<bool stereo, bool is16Bit, bool isUnsigned, bool isLE>
class AppendableMemoryStream : public AppendableAudioStream {
protected:
+ OSystem::MutexRef _mutex;
+
byte *_bufferStart;
byte *_bufferEnd;
byte *_pos;
@@ -196,7 +198,7 @@ protected:
inline bool eosIntern() const { return _end == _pos; };
public:
AppendableMemoryStream(int rate, uint bufferSize);
- ~AppendableMemoryStream() { free(_bufferStart); }
+ ~AppendableMemoryStream();
int readBuffer(int16 *buffer, const int numSamples);
bool isStereo() const { return stereo; }
@@ -222,10 +224,20 @@ AppendableMemoryStream<stereo, is16Bit, isUnsigned, isLE>::AppendableMemoryStrea
_bufferStart = (byte *)malloc(bufferSize);
_pos = _end = _bufferStart;
_bufferEnd = _bufferStart + bufferSize;
+
+ _mutex = g_system->createMutex();
+}
+
+template<bool stereo, bool is16Bit, bool isUnsigned, bool isLE>
+AppendableMemoryStream<stereo, is16Bit, isUnsigned, isLE>::~AppendableMemoryStream() {
+ free(_bufferStart);
+ g_system->deleteMutex(_mutex);
}
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);
+
int samples = 0;
while (samples < numSamples && !eosIntern()) {
// Wrap around?
@@ -246,6 +258,7 @@ int AppendableMemoryStream<stereo, is16Bit, isUnsigned, isLE>::readBuffer(int16
template<bool stereo, bool is16Bit, bool isUnsigned, bool isLE>
void AppendableMemoryStream<stereo, is16Bit, isUnsigned, isLE>::append(const byte *data, uint32 len) {
+ Common::StackLock lock(_mutex);
// Verify the buffer size is sane
if (is16Bit && stereo)
diff --git a/sound/mixer.cpp b/sound/mixer.cpp
index cc6164ab0a..64c748adcb 100644
--- a/sound/mixer.cpp
+++ b/sound/mixer.cpp
@@ -90,14 +90,6 @@ public:
uint32 getElapsedTime();
};
-class ChannelStream : public Channel {
-public:
- ChannelStream(SoundMixer *mixer, PlayingSoundHandle *handle, uint rate, byte flags, uint32 buffer_size);
- void append(void *sound, uint32 size);
-
- void finish();
-};
-
#pragma mark -
#pragma mark --- SoundMixer ---
@@ -155,68 +147,6 @@ void SoundMixer::setupPremix(AudioStream *stream) {
_premixChannel = new Channel(this, 0, stream, false, false);
}
-void SoundMixer::newStream(PlayingSoundHandle *handle, uint rate, byte flags, uint32 buffer_size, byte volume, int8 balance) {
- Common::StackLock lock(_mutex);
-
- Channel *chan = new ChannelStream(this, handle, rate, flags, buffer_size);
- chan->setVolume(volume);
- chan->setBalance(balance);
- insertChannel(handle, chan);
-}
-
-void SoundMixer::appendStream(PlayingSoundHandle handle, void *sound, uint32 size) {
- Common::StackLock lock(_mutex);
-
- if (!handle.isActive())
- return;
-
- int index = handle.getIndex();
-
- if ((index < 0) || (index >= NUM_CHANNELS)) {
- warning("soundMixer::appendStream has invalid index %d", index);
- return;
- }
-
- ChannelStream *chan;
-#if !defined(_WIN32_WCE) && !defined(__PALM_OS__)
- chan = dynamic_cast<ChannelStream *>(_channels[index]);
-#else
- chan = (ChannelStream*)_channels[index];
-#endif
- if (!chan) {
- error("Trying to append to nonexistant stream : %d", index);
- } else {
- chan->append(sound, size);
- }
-}
-
-void SoundMixer::endStream(PlayingSoundHandle handle) {
- Common::StackLock lock(_mutex);
-
- // Simply ignore stop requests for handles of sounds that already terminated
- if (!handle.isActive())
- return;
-
- int index = handle.getIndex();
-
- if ((index < 0) || (index >= NUM_CHANNELS)) {
- warning("soundMixer::endStream has invalid index %d", index);
- return;
- }
-
- ChannelStream *chan;
-#if !defined(_WIN32_WCE) && !defined(__PALM_OS__)
- chan = dynamic_cast<ChannelStream *>(_channels[index]);
-#else
- chan = (ChannelStream*)_channels[index];
-#endif
- if (!chan) {
- error("Trying to end a nonexistant streamer : %d", index);
- } else {
- chan->finish();
- }
-}
-
void SoundMixer::insertChannel(PlayingSoundHandle *handle, Channel *chan) {
int index = -1;
@@ -586,21 +516,3 @@ uint32 Channel::getElapsedTime() {
// FIXME: This won't work very well if the sound is paused.
return 1000 * seconds + milliseconds + delta;
}
-
-ChannelStream::ChannelStream(SoundMixer *mixer, PlayingSoundHandle *handle,
- uint rate, byte flags, uint32 buffer_size)
- : Channel(mixer, handle, false) {
- // Create the input stream
- _input = makeAppendableAudioStream(rate, flags, buffer_size);
-
- // Get a rate converter instance
- _converter = makeRateConverter(_input->getRate(), mixer->getOutputRate(), _input->isStereo(), (flags & SoundMixer::FLAG_REVERSE_STEREO) != 0);
-}
-
-void ChannelStream::finish() {
- ((AppendableAudioStream *)_input)->finish();
-}
-
-void ChannelStream::append(void *data, uint32 len) {
- ((AppendableAudioStream *)_input)->append((const byte *)data, len);
-}
diff --git a/sound/mixer.h b/sound/mixer.h
index 4f89d20666..b51f4976b1 100644
--- a/sound/mixer.h
+++ b/sound/mixer.h
@@ -135,22 +135,6 @@ public:
- /** Start a new stream. */
- void newStream(PlayingSoundHandle *handle, uint rate, byte flags, uint32 buffer_size, byte volume = 255, int8 balance = 0);
-
- /** Append to an existing stream. */
- void appendStream(PlayingSoundHandle handle, void *sound, uint32 size);
-
- /**
- * Mark a stream as finished.
- * Where stopHandle() would stop the sound immediately, when using this
- * method, the stream will first finish playing all its data before it
- * finally stops.
- */
- void endStream(PlayingSoundHandle handle);
-
-
-
/**
* Stop all currently playing sounds.
*/