aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--sound/audiostream.cpp41
-rw-r--r--sound/mixer.cpp55
2 files changed, 41 insertions, 55 deletions
diff --git a/sound/audiostream.cpp b/sound/audiostream.cpp
index efc143de4b..4bfafab0b1 100644
--- a/sound/audiostream.cpp
+++ b/sound/audiostream.cpp
@@ -51,16 +51,6 @@ protected:
const byte *_loopPtr;
const byte *_loopEnd;
- inline int16 readIntern() {
- //assert(_ptr < _end);
- int16 val = READ_ENDIAN_SAMPLE(is16Bit, isUnsigned, _ptr, isLE);
- _ptr += (is16Bit ? 2 : 1);
- if (_loopPtr && eosIntern()) {
- _ptr = _loopPtr;
- _end = _loopEnd;
- }
- return val;
- }
inline bool eosIntern() const { return _ptr >= _end; };
public:
LinearMemoryStream(const byte *ptr, uint len, uint loopOffset, uint loopLen)
@@ -81,7 +71,16 @@ public:
}
int readBuffer(int16 *buffer, const int numSamples);
- int16 read() { return readIntern(); }
+ int16 read() {
+ //assert(_ptr < _end);
+ int16 val = READ_ENDIAN_SAMPLE(is16Bit, isUnsigned, _ptr, isLE);
+ _ptr += (is16Bit ? 2 : 1);
+ if (_loopPtr && eosIntern()) {
+ _ptr = _loopPtr;
+ _end = _loopEnd;
+ }
+ return val;
+ }
bool eos() const { return eosIntern(); }
bool isStereo() const { return stereo; }
};
@@ -120,14 +119,13 @@ protected:
byte *_pos;
byte *_end;
- inline int16 readIntern();
inline bool eosIntern() const { return _end == _pos; };
public:
WrappedMemoryStream(uint bufferSize);
~WrappedMemoryStream() { free(_bufferStart); }
int readBuffer(int16 *buffer, const int numSamples);
- int16 read() { return readIntern(); }
+ int16 read();
bool eos() const { return eosIntern(); }
bool isStereo() const { return stereo; }
@@ -150,8 +148,11 @@ WrappedMemoryStream<stereo, is16Bit, isUnsigned>::WrappedMemoryStream(uint buffe
}
template<bool stereo, bool is16Bit, bool isUnsigned>
-inline int16 WrappedMemoryStream<stereo, is16Bit, isUnsigned>::readIntern() {
- //assert(_pos != _end);
+inline int16 WrappedMemoryStream<stereo, is16Bit, isUnsigned>::read() {
+ if (eosIntern()) {
+ // If the stream contains no more data, it is silent...
+ return 0;
+ }
int16 val = READSAMPLE(is16Bit, isUnsigned, _pos);
_pos += (is16Bit ? 2 : 1);
@@ -232,14 +233,13 @@ class MP3InputStream : public MusicStream {
bool init();
void refill(bool first = false);
- inline int16 readIntern();
inline bool eosIntern() const;
public:
MP3InputStream(File *file, mad_timer_t duration, uint size = 0);
~MP3InputStream();
int readBuffer(int16 *buffer, const int numSamples);
- int16 read() { return readIntern(); }
+ int16 read();
bool eos() const { return eosIntern(); }
bool isStereo() const { return _isStereo; }
@@ -397,7 +397,7 @@ static inline int scale_sample(mad_fixed_t sample) {
return sample >> (MAD_F_FRACBITS + 1 - 16);
}
-inline int16 MP3InputStream::readIntern() {
+inline int16 MP3InputStream::read() {
assert(!eosIntern());
int16 sample;
@@ -465,13 +465,12 @@ class VorbisInputStream : public MusicStream {
const int16 *_pos;
void refill();
- inline int16 readIntern();
inline bool eosIntern() const;
public:
VorbisInputStream(OggVorbis_File *file, int duration);
int readBuffer(int16 *buffer, const int numSamples);
- int16 read() { return readIntern(); }
+ int16 read();
bool eos() const { return eosIntern(); }
bool isStereo() const { return _numChannels >= 2; }
@@ -500,7 +499,7 @@ VorbisInputStream::VorbisInputStream(OggVorbis_File *file, int duration)
refill();
}
-inline int16 VorbisInputStream::readIntern() {
+inline int16 VorbisInputStream::read() {
assert(!eosIntern());
int16 sample = *_pos++;
diff --git a/sound/mixer.cpp b/sound/mixer.cpp
index 4937c91934..b47c598bad 100644
--- a/sound/mixer.cpp
+++ b/sound/mixer.cpp
@@ -38,20 +38,22 @@
* Channels used by the sound mixer.
*/
class Channel {
-protected:
+private:
SoundMixer *_mixer;
PlayingSoundHandle *_handle;
- RateConverter *_converter;
- AudioInputStream *_input;
byte _volume;
int8 _pan;
bool _paused;
+protected:
+ RateConverter *_converter;
+ AudioInputStream *_input;
+
public:
int _id;
- Channel(SoundMixer *mixer, PlayingSoundHandle *handle)
- : _mixer(mixer), _handle(handle), _converter(0), _input(0), _volume(0), _pan(0), _paused(false), _id(-1) {
+ Channel(SoundMixer *mixer, PlayingSoundHandle *handle, byte volume, int8 pan)
+ : _mixer(mixer), _handle(handle), _converter(0), _input(0), _volume(volume), _pan(pan), _paused(false), _id(-1) {
assert(mixer);
}
virtual ~Channel();
@@ -97,24 +99,20 @@ public:
#ifdef USE_MAD
class ChannelMP3 : public Channel {
+ const bool _isMusic;
public:
ChannelMP3(SoundMixer *mixer, PlayingSoundHandle *handle, File *file, uint size, byte volume, int8 pan);
- bool isMusicChannel() const { return false; }
-};
-
-class ChannelMP3CDMusic : public Channel {
-public:
- ChannelMP3CDMusic(SoundMixer *mixer, PlayingSoundHandle *handle, File *file, mad_timer_t duration, byte volume, int8 pan);
- bool isMusicChannel() const { return true; }
+ ChannelMP3(SoundMixer *mixer, PlayingSoundHandle *handle, File *file, mad_timer_t duration, byte volume, int8 pan);
+ bool isMusicChannel() const { return _isMusic; }
};
#endif // USE_MAD
#ifdef USE_VORBIS
class ChannelVorbis : public Channel {
- bool _is_cd_track;
+ const bool _isMusic;
public:
- ChannelVorbis(SoundMixer *mixer, PlayingSoundHandle *handle, OggVorbis_File *ov_file, int duration, bool is_cd_track, byte volume, int8 pan);
- bool isMusicChannel() const { return _is_cd_track; }
+ ChannelVorbis(SoundMixer *mixer, PlayingSoundHandle *handle, OggVorbis_File *ov_file, int duration, bool isMusic, byte volume, int8 pan);
+ bool isMusicChannel() const { return _isMusic; }
};
#endif // USE_VORBIS
@@ -266,7 +264,7 @@ int SoundMixer::playMP3(PlayingSoundHandle *handle, File *file, uint32 size, byt
}
int SoundMixer::playMP3CDTrack(PlayingSoundHandle *handle, File *file, mad_timer_t duration, byte volume, int8 pan) {
Common::StackLock lock(_mutex);
- return insertChannel(handle, new ChannelMP3CDMusic(this, handle, file, duration, volume, pan));
+ return insertChannel(handle, new ChannelMP3(this, handle, file, duration, volume, pan));
}
#endif
@@ -509,11 +507,9 @@ void Channel::mix(int16 *data, uint len) {
/* RAW mixer */
ChannelRaw::ChannelRaw(SoundMixer *mixer, PlayingSoundHandle *handle, void *sound, uint32 size, uint rate, byte flags, byte volume, int8 pan, int id, uint32 loopStart, uint32 loopEnd)
- : Channel(mixer, handle) {
+ : Channel(mixer, handle, volume, pan) {
_id = id;
_ptr = (byte *)sound;
- _volume = volume;
- _pan = pan;
// Create the input stream
if (flags & SoundMixer::FLAG_LOOP) {
@@ -541,9 +537,7 @@ ChannelRaw::~ChannelRaw() {
ChannelStream::ChannelStream(SoundMixer *mixer, PlayingSoundHandle *handle,
void *sound, uint32 size, uint rate,
byte flags, uint32 buffer_size, byte volume, int8 pan)
- : Channel(mixer, handle) {
- _volume = volume;
- _pan = pan;
+ : Channel(mixer, handle, volume, pan) {
assert(size <= buffer_size);
// Create the input stream
@@ -583,9 +577,7 @@ void ChannelStream::mix(int16 *data, uint len) {
#ifdef USE_MAD
ChannelMP3::ChannelMP3(SoundMixer *mixer, PlayingSoundHandle *handle, File *file, uint size, byte volume, int8 pan)
- : Channel(mixer, handle) {
- _volume = volume;
- _pan = pan;
+ : Channel(mixer, handle, volume, pan), _isMusic(false) {
// Create the input stream
_input = makeMP3Stream(file, mad_timer_zero, size);
@@ -593,10 +585,8 @@ ChannelMP3::ChannelMP3(SoundMixer *mixer, PlayingSoundHandle *handle, File *file
_converter = makeRateConverter(_input->getRate(), mixer->getOutputRate(), _input->isStereo());
}
-ChannelMP3CDMusic::ChannelMP3CDMusic(SoundMixer *mixer, PlayingSoundHandle *handle, File *file, mad_timer_t duration, byte volume, int8 pan)
- : Channel(mixer, handle) {
- _volume = volume;
- _pan = pan;
+ChannelMP3::ChannelMP3(SoundMixer *mixer, PlayingSoundHandle *handle, File *file, mad_timer_t duration, byte volume, int8 pan)
+ : Channel(mixer, handle, volume, pan), _isMusic(true) {
// Create the input stream
_input = makeMP3Stream(file, duration, 0);
@@ -606,15 +596,12 @@ ChannelMP3CDMusic::ChannelMP3CDMusic(SoundMixer *mixer, PlayingSoundHandle *hand
#endif // USE_MAD
#ifdef USE_VORBIS
-ChannelVorbis::ChannelVorbis(SoundMixer *mixer, PlayingSoundHandle *handle, OggVorbis_File *ov_file, int duration, bool is_cd_track, byte volume, int8 pan)
- : Channel(mixer, handle) {
- _volume = volume;
- _pan = pan;
+ChannelVorbis::ChannelVorbis(SoundMixer *mixer, PlayingSoundHandle *handle, OggVorbis_File *ov_file, int duration, bool isMusic, byte volume, int8 pan)
+ : Channel(mixer, handle, volume, pan), _isMusic(isMusic) {
// Create the input stream
_input = makeVorbisStream(ov_file, duration);
// Get a rate converter instance
_converter = makeRateConverter(_input->getRate(), mixer->getOutputRate(), _input->isStereo());
- _is_cd_track = is_cd_track;
}
#endif // USE_VORBIS