aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--sound/audiostream.cpp7
-rw-r--r--sound/audiostream.h20
-rw-r--r--sound/mixer.cpp6
-rw-r--r--sound/mp3.cpp2
-rw-r--r--sound/rate.cpp2
-rw-r--r--sound/vorbis.cpp2
-rw-r--r--sword2/driver/d_sound.cpp2
-rw-r--r--sword2/driver/d_sound.h6
8 files changed, 34 insertions, 13 deletions
diff --git a/sound/audiostream.cpp b/sound/audiostream.cpp
index 8622255ff9..862c26d80f 100644
--- a/sound/audiostream.cpp
+++ b/sound/audiostream.cpp
@@ -82,7 +82,7 @@ public:
return val;
}
bool isStereo() const { return stereo; }
- bool eos() const { return eosIntern(); }
+ bool endOfData() const { return eosIntern(); }
int getRate() const { return _rate; }
};
@@ -131,7 +131,8 @@ public:
int16 read();
bool isStereo() const { return stereo; }
- bool eos() const { return _finalized && eosIntern(); }
+ bool endOfStream() const { return _finalized && eosIntern(); }
+ bool endOfData() const { return eosIntern(); }
int getRate() const { return _rate; }
@@ -276,7 +277,7 @@ public:
return *_pos++;
}
bool isStereo() const { return _isStereo; }
- bool eos() const { return false; }
+ bool endOfData() const { return false; }
int getRate() const { return _rate; }
};
diff --git a/sound/audiostream.h b/sound/audiostream.h
index 2a5934fb80..e31c3ac505 100644
--- a/sound/audiostream.h
+++ b/sound/audiostream.h
@@ -53,8 +53,24 @@ public:
/** Is this a stereo stream? */
virtual bool isStereo() const = 0;
- /** End of stream reached? */
- virtual bool eos() const = 0;
+ /**
+ * End of data reached? If this returns true, it means that at this
+ * time there is no data available in the stream. However there may be
+ * more data in the future.
+ * This is used by e.g. a rate converter to decide whether to keep on
+ * converting data or stop.
+ */
+ virtual bool endOfData() const = 0;
+
+ /**
+ * End of stream reached? If this returns true, it means that all data
+ * in this stream is used up and no additional data will appear in it
+ * in the future.
+ * This is used by the mixer to decide whether a given stream shall be
+ * removed from the list of active streams (and thus be destroyed).
+ * By default this maps to endOfData()
+ */
+ virtual bool endOfStream() const { return endOfData(); }
/** Sample rate of the stream. */
virtual int getRate() const = 0;
diff --git a/sound/mixer.cpp b/sound/mixer.cpp
index 5278071c1e..786c376099 100644
--- a/sound/mixer.cpp
+++ b/sound/mixer.cpp
@@ -485,9 +485,11 @@ void Channel::destroy() {
*/
void Channel::mix(int16 *data, uint len) {
assert(_input);
- if (_input->eos()) {
- // TODO: call drain method
+
+ if (_input->endOfStream()) {
destroy();
+ } else if (_input->endOfData()) {
+ // TODO: call drain method
} else {
assert(_converter);
diff --git a/sound/mp3.cpp b/sound/mp3.cpp
index f23a4e4248..96a096f3b8 100644
--- a/sound/mp3.cpp
+++ b/sound/mp3.cpp
@@ -152,7 +152,7 @@ public:
int readBuffer(int16 *buffer, const int numSamples);
int16 read();
- bool eos() const { return eosIntern(); }
+ bool endOfData() const { return eosIntern(); }
bool isStereo() const { return _isStereo; }
int getRate() const { return _frame.header.samplerate; }
diff --git a/sound/rate.cpp b/sound/rate.cpp
index 12584c4b7e..a30837248e 100644
--- a/sound/rate.cpp
+++ b/sound/rate.cpp
@@ -200,7 +200,7 @@ public:
int16 tmp[2];
st_size_t len = osamp;
assert(input.isStereo() == stereo);
- while (!input.eos() && len--) {
+ while (!input.endOfData() && len--) {
tmp[0] = tmp[1] = input.read();
if (stereo)
tmp[reverseStereo ? 0 : 1] = input.read();
diff --git a/sound/vorbis.cpp b/sound/vorbis.cpp
index fb8ec9274a..5633ba4d75 100644
--- a/sound/vorbis.cpp
+++ b/sound/vorbis.cpp
@@ -166,7 +166,7 @@ public:
int readBuffer(int16 *buffer, const int numSamples);
int16 read();
- bool eos() const { return eosIntern(); }
+ bool endOfData() const { return eosIntern(); }
bool isStereo() const { return _numChannels >= 2; }
int getRate() const { return ov_info(_ov_file, -1)->rate; }
diff --git a/sword2/driver/d_sound.cpp b/sword2/driver/d_sound.cpp
index 303fcb5893..696c85a36b 100644
--- a/sword2/driver/d_sound.cpp
+++ b/sword2/driver/d_sound.cpp
@@ -105,7 +105,7 @@ int16 MusicHandle::read() {
return out;
}
-bool MusicHandle::eos() const {
+bool MusicHandle::endOfData() const {
return (!_streaming || _filePos >= _fileEnd);
}
diff --git a/sword2/driver/d_sound.h b/sword2/driver/d_sound.h
index b36e402002..a62054853d 100644
--- a/sword2/driver/d_sound.h
+++ b/sword2/driver/d_sound.h
@@ -61,14 +61,16 @@ public:
virtual int readBuffer(int16 *buffer, const int numSamples) {
int samples;
- for (samples = 0; samples < numSamples && !eos(); samples++) {
+ for (samples = 0; samples < numSamples && !endOfData(); samples++) {
*buffer++ = read();
}
return samples;
}
int16 read();
- bool eos() const;
+ bool endOfData() const;
+ // This stream never 'ends'
+ bool endOfStream() const { return false; }
MusicHandle() : _firstTime(false),
_streaming(false), _paused(false), _looping(false),