diff options
Diffstat (limited to 'sound')
-rw-r--r-- | sound/mixer.cpp | 7 | ||||
-rw-r--r-- | sound/mixer.h | 4 | ||||
-rw-r--r-- | sound/mp3.cpp | 207 | ||||
-rw-r--r-- | sound/mp3.h | 2 |
4 files changed, 108 insertions, 112 deletions
diff --git a/sound/mixer.cpp b/sound/mixer.cpp index 6882eb50bf..ed277ad06a 100644 --- a/sound/mixer.cpp +++ b/sound/mixer.cpp @@ -249,14 +249,9 @@ void SoundMixer::playRaw(PlayingSoundHandle *handle, void *sound, uint32 size, u #ifdef USE_MAD void SoundMixer::playMP3(PlayingSoundHandle *handle, File *file, uint32 size, byte volume, int8 pan, int id) { // Create the input stream - AudioInputStream *input = makeMP3Stream(file, mad_timer_zero, size); + AudioInputStream *input = makeMP3Stream(file, size); playInputStream(handle, input, false, volume, pan, id); } -void SoundMixer::playMP3CDTrack(PlayingSoundHandle *handle, File *file, mad_timer_t duration, byte volume, int8 pan, int id) { - // Create the input stream - AudioInputStream *input = makeMP3Stream(file, duration, 0); - playInputStream(handle, input, true, volume, pan, id); -} #endif #ifdef USE_VORBIS diff --git a/sound/mixer.h b/sound/mixer.h index 372bad4fc0..67c82f7364 100644 --- a/sound/mixer.h +++ b/sound/mixer.h @@ -27,9 +27,6 @@ #include "common/scummsys.h" #include "common/system.h" -#ifdef USE_MAD -#include <mad.h> -#endif #ifdef USE_VORBIS #include <vorbis/vorbisfile.h> #endif @@ -115,7 +112,6 @@ public: int id = -1, byte volume = 255, int8 pan = 0, uint32 loopStart = 0, uint32 loopEnd = 0); #ifdef USE_MAD void playMP3(PlayingSoundHandle *handle, File *file, uint32 size, byte volume = 255, int8 pan = 0, int id = -1); - void playMP3CDTrack(PlayingSoundHandle *handle, File *file, mad_timer_t duration, byte volume = 255, int8 pan = 0, int id = -1); #endif #ifdef USE_VORBIS void playVorbis(PlayingSoundHandle *handle, File *file, uint32 size, byte volume = 255, int8 pan = 0, int id = -1); diff --git a/sound/mp3.cpp b/sound/mp3.cpp index dbdd44da58..95ca098a2d 100644 --- a/sound/mp3.cpp +++ b/sound/mp3.cpp @@ -26,105 +26,6 @@ #ifdef USE_MAD -MP3TrackInfo::MP3TrackInfo(File *file) { - struct mad_stream stream; - struct mad_frame frame; - unsigned char buffer[8192]; - unsigned int buflen = 0; - int count = 0; - - // Check the format and bitrate - mad_stream_init(&stream); - mad_frame_init(&frame); - - while (1) { - if (buflen < sizeof(buffer)) { - int bytes; - - bytes = file->read(buffer + buflen, sizeof(buffer) - buflen); - if (bytes <= 0) { - if (bytes == -1) { - warning("Invalid file format"); - goto error; - } - break; - } - - buflen += bytes; - } - - mad_stream_buffer(&stream, buffer, buflen); - - while (1) { - if (mad_frame_decode(&frame, &stream) == -1) { - if (!MAD_RECOVERABLE(stream.error)) - break; - - if (stream.error != MAD_ERROR_BADCRC) - continue; - } - - if (count++) - break; - } - - if (count || stream.error != MAD_ERROR_BUFLEN) - break; - - memmove(buffer, stream.next_frame, - buflen = &buffer[buflen] - stream.next_frame); - } - - if (count) - memcpy(&_mad_header, &frame.header, sizeof(mad_header)); - else { - warning("Invalid file format"); - goto error; - } - - mad_frame_finish(&frame); - mad_stream_finish(&stream); - // Get file size - _size = file->size(); - _file = file; - _error_flag = false; - return; - -error: - mad_frame_finish(&frame); - mad_stream_finish(&stream); - _error_flag = true; - delete file; -} - -void MP3TrackInfo::play(SoundMixer *mixer, PlayingSoundHandle *handle, int startFrame, int duration) { - unsigned int offset; - mad_timer_t durationTime; - - // Calc offset. As all bitrates are in kilobit per seconds, the division by 200 is always exact - offset = (startFrame * (_mad_header.bitrate / (8 * 25))) / 3; - _file->seek(offset, SEEK_SET); - - // Calc delay - if (!duration) { - // FIXME: Using _size here is a problem if offset (or equivalently - // startFrame) is non-zero. - mad_timer_set(&durationTime, (_size * 8) / _mad_header.bitrate, - (_size * 8) % _mad_header.bitrate, _mad_header.bitrate); - } else { - mad_timer_set(&durationTime, duration / 75, duration % 75, 75); - } - - // Play it - mixer->playMP3CDTrack(handle, _file, durationTime); -} - -MP3TrackInfo::~MP3TrackInfo() { - if (! _error_flag) - _file->close(); -} - - #pragma mark - #pragma mark --- MP3 (MAD) stream --- #pragma mark - @@ -354,8 +255,112 @@ int MP3InputStream::readBuffer(int16 *buffer, const int numSamples) { return samples; } -AudioInputStream *makeMP3Stream(File *file, mad_timer_t duration, uint size) { - return new MP3InputStream(file, duration, size); +AudioInputStream *makeMP3Stream(File *file, uint size) { + return new MP3InputStream(file, mad_timer_zero, size); +} + + +#pragma mark - +#pragma mark --- MP3 Audio CD emulation --- +#pragma mark - + +MP3TrackInfo::MP3TrackInfo(File *file) { + struct mad_stream stream; + struct mad_frame frame; + unsigned char buffer[8192]; + unsigned int buflen = 0; + int count = 0; + + // Check the format and bitrate + mad_stream_init(&stream); + mad_frame_init(&frame); + + while (1) { + if (buflen < sizeof(buffer)) { + int bytes; + + bytes = file->read(buffer + buflen, sizeof(buffer) - buflen); + if (bytes <= 0) { + if (bytes == -1) { + warning("Invalid file format"); + goto error; + } + break; + } + + buflen += bytes; + } + + mad_stream_buffer(&stream, buffer, buflen); + + while (1) { + if (mad_frame_decode(&frame, &stream) == -1) { + if (!MAD_RECOVERABLE(stream.error)) + break; + + if (stream.error != MAD_ERROR_BADCRC) + continue; + } + + if (count++) + break; + } + + if (count || stream.error != MAD_ERROR_BUFLEN) + break; + + memmove(buffer, stream.next_frame, + buflen = &buffer[buflen] - stream.next_frame); + } + + if (count) + memcpy(&_mad_header, &frame.header, sizeof(mad_header)); + else { + warning("Invalid file format"); + goto error; + } + + mad_frame_finish(&frame); + mad_stream_finish(&stream); + // Get file size + _size = file->size(); + _file = file; + _error_flag = false; + return; + +error: + mad_frame_finish(&frame); + mad_stream_finish(&stream); + _error_flag = true; + delete file; +} + +void MP3TrackInfo::play(SoundMixer *mixer, PlayingSoundHandle *handle, int startFrame, int duration) { + unsigned int offset; + mad_timer_t durationTime; + + // Calc offset. As all bitrates are in kilobit per seconds, the division by 200 is always exact + offset = (startFrame * (_mad_header.bitrate / (8 * 25))) / 3; + _file->seek(offset, SEEK_SET); + + // Calc delay + if (!duration) { + // FIXME: Using _size here is a problem if offset (or equivalently + // startFrame) is non-zero. + mad_timer_set(&durationTime, (_size * 8) / _mad_header.bitrate, + (_size * 8) % _mad_header.bitrate, _mad_header.bitrate); + } else { + mad_timer_set(&durationTime, duration / 75, duration % 75, 75); + } + + // Play it + AudioInputStream *input = new MP3InputStream(_file, durationTime, 0); + mixer->playInputStream(handle, input, true); +} + +MP3TrackInfo::~MP3TrackInfo() { + if (! _error_flag) + _file->close(); } diff --git a/sound/mp3.h b/sound/mp3.h index c5e93d290d..d39ebc1391 100644 --- a/sound/mp3.h +++ b/sound/mp3.h @@ -47,7 +47,7 @@ public: void play(SoundMixer *mixer, PlayingSoundHandle *handle, int startFrame, int duration); }; -AudioInputStream *makeMP3Stream(File *file, mad_timer_t duration, uint size = 0); +AudioInputStream *makeMP3Stream(File *file, uint size); #endif |