[Scummvm-cvs-logs] CVS: scummvm/sound mixer.cpp,1.64,1.65 mixer.h,1.29,1.30
Max Horn
fingolfin at users.sourceforge.net
Sun Jul 6 09:53:05 CEST 2003
Update of /cvsroot/scummvm/scummvm/sound
In directory sc8-pr-cvs1:/tmp/cvs-serv31906
Modified Files:
mixer.cpp mixer.h
Log Message:
now that we mutex-protect everything properly, we can get rid of _toBeDestroyed; also, instead of keeping a global _handles array in the mixer, let each Channel manage its own handle
Index: mixer.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/sound/mixer.cpp,v
retrieving revision 1.64
retrieving revision 1.65
diff -u -d -r1.64 -r1.65
--- mixer.cpp 6 Jul 2003 15:57:33 -0000 1.64
+++ mixer.cpp 6 Jul 2003 16:52:09 -0000 1.65
@@ -30,14 +30,23 @@
class Channel {
protected:
SoundMixer *_mixer;
+ PlayingSoundHandle *_handle;
public:
- bool _toBeDestroyed;
int _id;
- Channel(SoundMixer *mixer) : _mixer(mixer), _toBeDestroyed(false), _id(-1) {}
- virtual ~Channel() {}
+ Channel(SoundMixer *mixer, PlayingSoundHandle *handle)
+ : _mixer(mixer), _handle(handle), _id(-1) {
+ assert(mixer);
+ }
+ virtual ~Channel() {
+ if (_handle)
+ *_handle = 0;
+ }
virtual void mix(int16 *data, uint len) = 0;
void destroy() {
- _toBeDestroyed = true;
+ for (int i = 0; i != SoundMixer::NUM_CHANNELS; i++)
+ if (_mixer->_channels[i] == this)
+ _mixer->_channels[i] = 0;
+ delete this;
}
virtual bool isActive();
virtual bool isMusicChannel() = 0;
@@ -55,12 +64,12 @@
uint32 _loop_size;
public:
- ChannelRaw(SoundMixer *mixer, void *sound, uint32 size, uint rate, byte flags, int id);
+ ChannelRaw(SoundMixer *mixer, PlayingSoundHandle *handle, void *sound, uint32 size, uint rate, byte flags, int id);
~ChannelRaw();
void mix(int16 *data, uint len);
bool isMusicChannel() {
- return false; // TODO: IS this correct? Or does any Scumm game us this for music?
+ return false; // TODO: Is this correct? Or does anything use ChannelRaw for music?
}
};
@@ -77,7 +86,7 @@
bool _finished;
public:
- ChannelStream(SoundMixer *mixer, void *sound, uint32 size, uint rate, byte flags, uint32 buffer_size);
+ ChannelStream(SoundMixer *mixer, PlayingSoundHandle *handle, void *sound, uint32 size, uint rate, byte flags, uint32 buffer_size);
~ChannelStream();
void mix(int16 *data, uint len);
@@ -101,7 +110,7 @@
uint32 _size;
public:
- ChannelMP3Common(SoundMixer *mixer);
+ ChannelMP3Common(SoundMixer *mixer, PlayingSoundHandle *handle);
~ChannelMP3Common();
};
@@ -110,7 +119,7 @@
uint32 _position;
public:
- ChannelMP3(SoundMixer *mixer, void *sound, uint size, byte flags);
+ ChannelMP3(SoundMixer *mixer, PlayingSoundHandle *handle, void *sound, uint size, byte flags);
void mix(int16 *data, uint len);
bool isMusicChannel() { return false; }
@@ -124,7 +133,7 @@
public:
- ChannelMP3CDMusic(SoundMixer *mixer, File *file, mad_timer_t duration);
+ ChannelMP3CDMusic(SoundMixer *mixer, PlayingSoundHandle *handle, File *file, mad_timer_t duration);
void mix(int16 *data, uint len);
bool isActive();
@@ -140,7 +149,7 @@
bool _eof_flag, _is_cd_track;
public:
- ChannelVorbis(SoundMixer *mixer, OggVorbis_File *ov_file, int duration, bool is_cd_track);
+ ChannelVorbis(SoundMixer *mixer, PlayingSoundHandle *handle, OggVorbis_File *ov_file, int duration, bool is_cd_track);
void mix(int16 *data, uint len);
bool isActive();
@@ -159,9 +168,6 @@
_premixProc = 0;
int i = 0;
- for (i = 0; i != NUM_CHANNELS; i++)
- _handles[i] = NULL;
-
_outputRate = 0;
_volumeTable = (int16 *)calloc(256 * sizeof(int16), 1);
@@ -219,7 +225,6 @@
}
_channels[index] = chan;
- _handles[index] = handle;
if (handle)
*handle = index + 1;
return index;
@@ -235,29 +240,29 @@
return -1;
}
- return insertChannel(handle, new ChannelRaw(this, sound, size, rate, flags, id));
+ return insertChannel(handle, new ChannelRaw(this, handle, sound, size, rate, flags, id));
}
int SoundMixer::newStream(void *sound, uint32 size, uint rate, byte flags, uint32 buffer_size) {
StackLock lock(_mutex);
- return insertChannel(NULL, new ChannelStream(this, sound, size, rate, flags, buffer_size));
+ return insertChannel(NULL, new ChannelStream(this, 0, sound, size, rate, flags, buffer_size));
}
#ifdef USE_MAD
int SoundMixer::playMP3(PlayingSoundHandle *handle, void *sound, uint32 size, byte flags) {
StackLock lock(_mutex);
- return insertChannel(handle, new ChannelMP3(this, sound, size, flags));
+ return insertChannel(handle, new ChannelMP3(this, handle, sound, size, flags));
}
int SoundMixer::playMP3CDTrack(PlayingSoundHandle *handle, File *file, mad_timer_t duration) {
StackLock lock(_mutex);
- return insertChannel(handle, new ChannelMP3CDMusic(this, file, duration));
+ return insertChannel(handle, new ChannelMP3CDMusic(this, handle, file, duration));
}
#endif
#ifdef USE_VORBIS
int SoundMixer::playVorbis(PlayingSoundHandle *handle, OggVorbis_File *ov_file, int duration, bool is_cd_track) {
StackLock lock(_mutex);
- return insertChannel(handle, new ChannelVorbis(this, ov_file, duration, is_cd_track));
+ return insertChannel(handle, new ChannelVorbis(this, handle, ov_file, duration, is_cd_track));
}
#endif
@@ -278,17 +283,8 @@
if (!_paused) {
// now mix all channels
for (int i = 0; i != NUM_CHANNELS; i++)
- if (_channels[i]) {
- if (_channels[i]->_toBeDestroyed) {
- if (_handles[i]) {
- *_handles[i] = 0;
- _handles[i] = NULL;
- }
- delete _channels[i];
- _channels[i] = NULL;
- } else
- _channels[i]->mix(buf, len);
- }
+ if (_channels[i])
+ _channels[i]->mix(buf, len);
}
}
@@ -627,8 +623,8 @@
}
/* RAW mixer */
-ChannelRaw::ChannelRaw(SoundMixer *mixer, void *sound, uint32 size, uint rate, byte flags, int id)
- : Channel(mixer) {
+ChannelRaw::ChannelRaw(SoundMixer *mixer, PlayingSoundHandle *handle, void *sound, uint32 size, uint rate, byte flags, int id)
+ : Channel(mixer, handle) {
_id = id;
_flags = flags;
_ptr = (byte *)sound;
@@ -689,9 +685,9 @@
#define WARP_WORKAROUND 50000
-ChannelStream::ChannelStream(SoundMixer *mixer, void *sound, uint32 size, uint rate,
+ChannelStream::ChannelStream(SoundMixer *mixer, PlayingSoundHandle *handle, void *sound, uint32 size, uint rate,
byte flags, uint32 buffer_size)
- : Channel(mixer) {
+ : Channel(mixer, handle) {
assert(size <= buffer_size);
_flags = flags;
_bufferSize = buffer_size;
@@ -792,8 +788,8 @@
#ifdef USE_MAD
-ChannelMP3Common::ChannelMP3Common(SoundMixer *mixer)
- : Channel(mixer) {
+ChannelMP3Common::ChannelMP3Common(SoundMixer *mixer, PlayingSoundHandle *handle)
+ : Channel(mixer, handle) {
mad_stream_init(&_stream);
#ifdef _WIN32_WCE
// 11 kHz on WinCE if necessary
@@ -812,8 +808,8 @@
mad_stream_finish(&_stream);
}
-ChannelMP3::ChannelMP3(SoundMixer *mixer, void *sound, uint size, byte flags)
- : ChannelMP3Common(mixer) {
+ChannelMP3::ChannelMP3(SoundMixer *mixer, PlayingSoundHandle *handle, void *sound, uint size, byte flags)
+ : ChannelMP3Common(mixer, handle) {
_posInFrame = 0xFFFFFFFF;
_position = 0;
_size = size;
@@ -905,8 +901,8 @@
#define MP3CD_BUFFERING_SIZE 131072
-ChannelMP3CDMusic::ChannelMP3CDMusic(SoundMixer *mixer, File *file, mad_timer_t duration)
- : ChannelMP3Common(mixer) {
+ChannelMP3CDMusic::ChannelMP3CDMusic(SoundMixer *mixer, PlayingSoundHandle *handle, File *file, mad_timer_t duration)
+ : ChannelMP3Common(mixer, handle) {
_file = file;
_duration = duration;
_initialized = false;
@@ -1017,8 +1013,8 @@
#endif
#ifdef USE_VORBIS
-ChannelVorbis::ChannelVorbis(SoundMixer *mixer, OggVorbis_File *ov_file, int duration, bool is_cd_track)
- : Channel(mixer) {
+ChannelVorbis::ChannelVorbis(SoundMixer *mixer, PlayingSoundHandle *handle, OggVorbis_File *ov_file, int duration, bool is_cd_track)
+ : Channel(mixer, handle) {
_ov_file = ov_file;
if (duration)
Index: mixer.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/sound/mixer.h,v
retrieving revision 1.29
retrieving revision 1.30
diff -u -d -r1.29 -r1.30
--- mixer.h 6 Jul 2003 01:43:40 -0000 1.29
+++ mixer.h 6 Jul 2003 16:52:09 -0000 1.30
@@ -59,8 +59,6 @@
void *_premixParam;
PremixProc *_premixProc;
- PlayingSoundHandle *_handles[NUM_CHANNELS];
-
public:
uint _outputRate;
More information about the Scummvm-git-logs
mailing list