aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMax Horn2003-07-31 01:36:24 +0000
committerMax Horn2003-07-31 01:36:24 +0000
commitf74197ce8b777422aabad0302292fc043b47e3d5 (patch)
tree708e619007e919f967390b0c11ff6c3e3d52b9d1
parent9b2d4f92aab4ecf52afd49865a3b7efa879391b8 (diff)
downloadscummvm-rg350-f74197ce8b777422aabad0302292fc043b47e3d5.tar.gz
scummvm-rg350-f74197ce8b777422aabad0302292fc043b47e3d5.tar.bz2
scummvm-rg350-f74197ce8b777422aabad0302292fc043b47e3d5.zip
make use of the new MP3InputStream in ChannelMP3CDMusic - but disabled by default, because it is still quite buggy (e.g. crashes at end of stream etc)
svn-id: r9314
-rw-r--r--sound/mixer.cpp56
1 files changed, 56 insertions, 0 deletions
diff --git a/sound/mixer.cpp b/sound/mixer.cpp
index a93d434e66..6fc7e79df5 100644
--- a/sound/mixer.cpp
+++ b/sound/mixer.cpp
@@ -29,6 +29,7 @@
#define SOX_HACK
#ifdef SOX_HACK
+//#define BUGGY_NEW_MP3_PLAYER
#include "rate.h"
#endif
@@ -144,13 +145,20 @@ public:
bool isMusicChannel() { return false; }
};
+#ifdef BUGGY_NEW_MP3_PLAYER
+class ChannelMP3CDMusic : public Channel {
+ RateConverter *_converter;
+ MP3InputStream *_input;
+#else
class ChannelMP3CDMusic : public ChannelMP3Common {
uint32 _bufferSize;
mad_timer_t _duration;
File *_file;
+#endif
public:
ChannelMP3CDMusic(SoundMixer *mixer, PlayingSoundHandle *handle, File *file, mad_timer_t duration);
+ ~ChannelMP3CDMusic();
void mix(int16 *data, uint len);
bool isActive();
@@ -993,6 +1001,17 @@ void ChannelMP3::mix(int16 *data, uint len) {
#define MP3CD_BUFFERING_SIZE 131072
+#ifdef BUGGY_NEW_MP3_PLAYER
+ChannelMP3CDMusic::ChannelMP3CDMusic(SoundMixer *mixer, PlayingSoundHandle *handle, File *file, mad_timer_t duration)
+ : Channel(mixer, handle) {
+ // Create the input stream
+ _input = new MP3InputStream(file, duration);
+
+ // Get a rate converter instance
+printf("ChannelMP3CDMusic: inrate %d, outrate %d, stereo %d\n", _input->getRate(), mixer->getOutputRate(), _input->isStereo());
+ _converter = makeRateConverter(_input->getRate(), mixer->getOutputRate(), _input->isStereo());
+}
+#else
ChannelMP3CDMusic::ChannelMP3CDMusic(SoundMixer *mixer, PlayingSoundHandle *handle, File *file, mad_timer_t duration)
: ChannelMP3Common(mixer, handle) {
_file = file;
@@ -1000,8 +1019,35 @@ ChannelMP3CDMusic::ChannelMP3CDMusic(SoundMixer *mixer, PlayingSoundHandle *hand
_bufferSize = MP3CD_BUFFERING_SIZE;
_ptr = (byte *)malloc(MP3CD_BUFFERING_SIZE);
}
+#endif
+
+ChannelMP3CDMusic::~ChannelMP3CDMusic() {
+#ifdef BUGGY_NEW_MP3_PLAYER
+ delete _converter;
+ delete _input;
+#endif
+}
void ChannelMP3CDMusic::mix(int16 *data, uint len) {
+#ifdef BUGGY_NEW_MP3_PLAYER
+ assert(_input);
+ assert(_converter);
+
+ 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;
+ }
+
+ const int volume = _mixer->getVolume();
+ uint tmpLen = len;
+ _converter->flow(*_input, data, &tmpLen, volume);
+#else
mad_timer_t frame_duration;
const int volume = _mixer->getMusicVolume();
@@ -1103,10 +1149,15 @@ void ChannelMP3CDMusic::mix(int16 *data, uint len) {
mad_synth_frame(&_synth, &_frame);
_posInFrame = 0;
}
+#endif
}
bool ChannelMP3CDMusic::isActive() {
+#ifdef BUGGY_NEW_MP3_PLAYER
+ return !_input->eof();
+#else
return mad_timer_compare(_duration, mad_timer_zero) > 0;
+#endif
}
#endif
@@ -1156,6 +1207,11 @@ void ChannelVorbis::mix(int16 *data, uint len) {
if (_input->eof() && !_is_cd_track) {
// 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;
}