[Scummvm-cvs-logs] CVS: scummvm/sound mixer.cpp,1.88,1.89 mixer.h,1.35,1.36
Max Horn
fingolfin at users.sourceforge.net
Thu Jul 31 13:29:10 CEST 2003
Update of /cvsroot/scummvm/scummvm/sound
In directory sc8-pr-cvs1:/tmp/cvs-serv30942/sound
Modified Files:
mixer.cpp mixer.h
Log Message:
revamped MP3/Vorbis CD 'emulation' code to use a PlayingSoundHandle -> this allows to finally get rid of the hackish isChannelActive/isChannelUsed methods in SoundMixer
Index: mixer.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/sound/mixer.cpp,v
retrieving revision 1.88
retrieving revision 1.89
diff -u -d -r1.88 -r1.89
--- mixer.cpp 31 Jul 2003 01:36:24 -0000 1.88
+++ mixer.cpp 31 Jul 2003 20:24:10 -0000 1.89
@@ -59,7 +59,6 @@
_mixer->_channels[i] = 0;
delete this;
}
- virtual bool isActive();
virtual bool isMusicChannel() = 0;
};
@@ -161,7 +160,6 @@
~ChannelMP3CDMusic();
void mix(int16 *data, uint len);
- bool isActive();
bool isMusicChannel() { return true; }
};
@@ -175,7 +173,6 @@
#else
OggVorbis_File *_ov_file;
int _end_pos;
- bool _eof_flag;
#endif
bool _is_cd_track;
@@ -184,7 +181,6 @@
~ChannelVorbis();
void mix(int16 *data, uint len);
- bool isActive();
bool isMusicChannel() {
return _is_cd_track;
}
@@ -411,18 +407,6 @@
return false;
}
-bool SoundMixer::isChannelActive(int index) {
- StackLock lock(_mutex);
- if (_channels[index])
- return _channels[index]->isActive();
- return false;
-}
-
-bool SoundMixer::isChannelUsed(int index) {
- StackLock lock(_mutex);
- return (_channels[index] != NULL);
-}
-
void SoundMixer::setupPremix(void *param, PremixProc *proc) {
StackLock lock(_mutex);
_premixParam = param;
@@ -666,11 +650,6 @@
};
#endif
-bool Channel::isActive() {
- error("isActive should never be called on a non-MP3 mixer ");
- return true;
-}
-
/* RAW mixer */
ChannelRaw::ChannelRaw(SoundMixer *mixer, PlayingSoundHandle *handle, void *sound, uint32 size, uint rate, byte flags, int id)
: Channel(mixer, handle) {
@@ -1035,11 +1014,6 @@
if (_input->eof()) {
// TODO: call drain method
-
- // TODO: we probably shouldn't call destroy() here, this interfers
- // with the looping code in scumm/sound.cpp. But then that code
- // should be rewritten anyway (which would probably allow us to
- // get rid of the isActive() method, too.
destroy();
return;
}
@@ -1121,6 +1095,11 @@
frame_duration = _frame.header.duration;
mad_timer_negate(&frame_duration);
mad_timer_add(&_duration, frame_duration);
+
+ if (mad_timer_compare(_duration, mad_timer_zero) <= 0) {
+ destroy();
+ return;
+ }
if (mad_frame_decode(&_frame, &_stream) == -1) {
if (_stream.error == MAD_ERROR_BUFLEN) {
int not_decoded;
@@ -1152,14 +1131,6 @@
#endif
}
-bool ChannelMP3CDMusic::isActive() {
-#ifdef BUGGY_NEW_MP3_PLAYER
- return !_input->eof();
-#else
- return mad_timer_compare(_duration, mad_timer_zero) > 0;
-#endif
-}
-
#endif
#ifdef USE_VORBIS
@@ -1182,8 +1153,6 @@
_end_pos = ov_pcm_tell(ov_file) + duration;
else
_end_pos = 0;
-
- _eof_flag = false;
#endif
_is_cd_track = is_cd_track;
}
@@ -1205,13 +1174,8 @@
assert(_input);
assert(_converter);
- if (_input->eof() && !_is_cd_track) {
+ if (_input->eof()) {
// TODO: call drain method
-
- // TODO: we probably shouldn't call destroy() here, this interfers
- // with the looping code in scumm/sound.cpp. But then that code
- // should be rewritten anyway (which would probably allow us to
- // get rid of the isActive() method, too.
destroy();
return;
}
@@ -1220,7 +1184,8 @@
uint tmpLen = len;
_converter->flow(*_input, data, &tmpLen, volume);
#else
- if (_eof_flag) {
+ if (_end_pos > 0 && ov_pcm_tell(_ov_file) >= _end_pos) {
+ destroy();
return;
}
@@ -1228,7 +1193,8 @@
uint len_left = len * channels * 2;
int16 *samples = new int16[len_left / 2];
char *read_pos = (char *) samples;
- int volume = _is_cd_track ? _mixer->getMusicVolume() : _mixer->getVolume();
+ bool eof_flag = false;
+ int volume = isMusicChannel() ? _mixer->getMusicVolume() : _mixer->getVolume();
// Read the samples
while (len_left > 0) {
@@ -1243,19 +1209,17 @@
#endif
NULL);
if (result == 0) {
- _eof_flag = true;
+ eof_flag = true;
memset(read_pos, 0, len_left);
- len_left = 0;
+ break;
} else if (result == OV_HOLE) {
// Possibly recoverable, just warn about it
warning("Corrupted data in Vorbis file");
} else if (result < 0) {
debug(1, "Decode error %d in Vorbis file", result);
- // Don't delete it yet, that causes problems in
- // the CD player emulation code.
- _eof_flag = true;
+ eof_flag = true;
memset(read_pos, 0, len_left);
- len_left = 0;
+ break;
} else {
len_left -= result;
read_pos += result;
@@ -1264,25 +1228,17 @@
// Mix the samples in
for (uint i = 0; i < len; i++) {
- int16 sample = (int16) ((int32) samples[i * channels] * volume / 256);
+ int16 sample = (int16)(samples[i * channels] * volume / 256);
clamped_add_16(*data++, sample);
if (channels > 1)
- sample = (int16) ((int32) samples[i * channels + 1] * volume / 256);
+ sample = (int16)(samples[i * channels + 1] * volume / 256);
clamped_add_16(*data++, sample);
}
delete [] samples;
- if (_eof_flag && !_is_cd_track)
+ if (eof_flag)
destroy();
-#endif
-}
-
-bool ChannelVorbis::isActive() {
-#ifdef SOX_HACK
- return !_input->eof();
-#else
- return !_eof_flag && !(_end_pos > 0 && ov_pcm_tell(_ov_file) >= _end_pos);
#endif
}
Index: mixer.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/sound/mixer.h,v
retrieving revision 1.35
retrieving revision 1.36
diff -u -d -r1.35 -r1.36
--- mixer.h 29 Jul 2003 12:39:41 -0000 1.35
+++ mixer.h 31 Jul 2003 20:24:10 -0000 1.36
@@ -118,12 +118,6 @@
/** Check whether any SFX channel is active.*/
bool hasActiveSFXChannel();
- /** Check whether the specified channel is active. */
- bool isChannelActive(int index);
-
- /** Check whether the specified channel is in use. */
- bool isChannelUsed(int index);
-
/** bind to the OSystem object => mixer will be
* invoked automatically when samples need
* to be generated */
More information about the Scummvm-git-logs
mailing list