From 81481ad6da949340fc0e886b08d404b7cd3d7b77 Mon Sep 17 00:00:00 2001 From: Max Horn Date: Sat, 3 Jan 2004 01:25:45 +0000 Subject: more MAD MP3 / Ogg Vorbis cleanup: try not to expose anything about the libs used for MP3/Vorbis support -> this eases changing the implementations, and reduces header dependencies (and thus compile time) :-) svn-id: r12097 --- sound/audiocd.cpp | 4 ++-- sound/mixer.cpp | 5 ----- sound/mixer.h | 5 ----- sound/mp3.cpp | 30 ++++++++++++++++++++++++++++-- sound/mp3.h | 18 ++---------------- sound/vorbis.cpp | 40 ++++++++++++++++++++++++++++++++++++---- sound/vorbis.h | 19 ++----------------- 7 files changed, 70 insertions(+), 51 deletions(-) (limited to 'sound') diff --git a/sound/audiocd.cpp b/sound/audiocd.cpp index f2b243b843..2f3e68b229 100644 --- a/sound/audiocd.cpp +++ b/sound/audiocd.cpp @@ -132,7 +132,7 @@ int AudioCDManager::getCachedTrack(int track) { file->open(track_name, g_engine->getGameDataPath()); if (file->isOpen()) { - _track_info[current_index] = new MP3TrackInfo(file); + _track_info[current_index] = makeMP3TrackInfo(file); if (_track_info[current_index]->error()) { delete _track_info[current_index]; _track_info[current_index] = NULL; @@ -147,7 +147,7 @@ int AudioCDManager::getCachedTrack(int track) { file->open(track_name, g_engine->getGameDataPath()); if (file->isOpen()) { - _track_info[current_index] = new VorbisTrackInfo(file); + _track_info[current_index] = makeVorbisTrackInfo(file); if (_track_info[current_index]->error()) { delete _track_info[current_index]; _track_info[current_index] = NULL; diff --git a/sound/mixer.cpp b/sound/mixer.cpp index ed277ad06a..1312e11c38 100644 --- a/sound/mixer.cpp +++ b/sound/mixer.cpp @@ -260,11 +260,6 @@ void SoundMixer::playVorbis(PlayingSoundHandle *handle, File *file, uint32 size, AudioInputStream *input = makeVorbisStream(file, size); playInputStream(handle, input, false, volume, pan, id); } -void SoundMixer::playVorbis(PlayingSoundHandle *handle, OggVorbis_File *ov_file, int duration, bool is_cd_track, byte volume, int8 pan, int id) { - // Create the input stream - AudioInputStream *input = makeVorbisStream(ov_file, duration); - playInputStream(handle, input, is_cd_track, volume, pan, id); -} #endif void SoundMixer::playInputStream(PlayingSoundHandle *handle, AudioInputStream *input, bool isMusic, byte volume, int8 pan, int id, bool autofreeStream) { diff --git a/sound/mixer.h b/sound/mixer.h index 67c82f7364..6e88b11069 100644 --- a/sound/mixer.h +++ b/sound/mixer.h @@ -27,10 +27,6 @@ #include "common/scummsys.h" #include "common/system.h" -#ifdef USE_VORBIS -#include -#endif - class AudioInputStream; class Channel; @@ -115,7 +111,6 @@ public: #endif #ifdef USE_VORBIS void playVorbis(PlayingSoundHandle *handle, File *file, uint32 size, byte volume = 255, int8 pan = 0, int id = -1); - void playVorbis(PlayingSoundHandle *handle, OggVorbis_File *ov_file, int duration, bool is_cd_track, byte volume = 255, int8 pan = 0, int id = -1); #endif void playInputStream(PlayingSoundHandle *handle, AudioInputStream *input, bool isMusic, byte volume = 255, int8 pan = 0, int id = -1, bool autofreeStream = true); diff --git a/sound/mp3.cpp b/sound/mp3.cpp index 95ca098a2d..6c74c27d7f 100644 --- a/sound/mp3.cpp +++ b/sound/mp3.cpp @@ -20,11 +20,17 @@ */ #include "sound/mp3.h" -#include "sound/audiostream.h" + +#ifdef USE_MAD + #include "common/file.h" #include "common/util.h" -#ifdef USE_MAD +#include "sound/audiocd.h" +#include "sound/audiostream.h" + +#include + #pragma mark - #pragma mark --- MP3 (MAD) stream --- @@ -264,6 +270,22 @@ AudioInputStream *makeMP3Stream(File *file, uint size) { #pragma mark --- MP3 Audio CD emulation --- #pragma mark - + +class MP3TrackInfo : public DigitalTrackInfo { +private: + struct mad_header _mad_header; + long _size; + File *_file; + bool _error_flag; + +public: + MP3TrackInfo(File *file); + ~MP3TrackInfo(); + bool error() { return _error_flag; } + void play(SoundMixer *mixer, PlayingSoundHandle *handle, int startFrame, int duration); +}; + + MP3TrackInfo::MP3TrackInfo(File *file) { struct mad_stream stream; struct mad_frame frame; @@ -363,5 +385,9 @@ MP3TrackInfo::~MP3TrackInfo() { _file->close(); } +DigitalTrackInfo *makeMP3TrackInfo(File *file) { + return new MP3TrackInfo(file); +} + #endif diff --git a/sound/mp3.h b/sound/mp3.h index d39ebc1391..b0a1ee323d 100644 --- a/sound/mp3.h +++ b/sound/mp3.h @@ -27,25 +27,11 @@ #ifdef USE_MAD -#include "sound/audiocd.h" -#include - class AudioInputStream; +class DigitalTrackInfo; class File; -class MP3TrackInfo : public DigitalTrackInfo { -private: - struct mad_header _mad_header; - long _size; - File *_file; - bool _error_flag; - -public: - MP3TrackInfo(File *file); - ~MP3TrackInfo(); - bool error() { return _error_flag; } - void play(SoundMixer *mixer, PlayingSoundHandle *handle, int startFrame, int duration); -}; +DigitalTrackInfo *makeMP3TrackInfo(File *file); AudioInputStream *makeMP3Stream(File *file, uint size); diff --git a/sound/vorbis.cpp b/sound/vorbis.cpp index d5fcb47526..bcee8b792b 100644 --- a/sound/vorbis.cpp +++ b/sound/vorbis.cpp @@ -20,11 +20,38 @@ */ #include "sound/vorbis.h" -#include "sound/audiostream.h" + +#ifdef USE_VORBIS + #include "common/file.h" #include "common/util.h" -#ifdef USE_VORBIS +#include "sound/audiostream.h" +#include "sound/audiocd.h" + +#include + + +AudioInputStream *makeVorbisStream(OggVorbis_File *file, int duration); + + +#pragma mark - +#pragma mark --- Ogg Vorbis Audio CD emulation --- +#pragma mark - + +class VorbisTrackInfo : public DigitalTrackInfo { +private: + File *_file; + OggVorbis_File _ov_file; + bool _error_flag; + +public: + VorbisTrackInfo(File *file); + ~VorbisTrackInfo(); + bool error() { return _error_flag; } + void play(SoundMixer *mixer, PlayingSoundHandle *handle, int startFrame, int duration); +}; + // These are wrapper functions to allow using a File object to // provide data to the OggVorbis_File object. @@ -117,8 +144,9 @@ void VorbisTrackInfo::play(SoundMixer *mixer, PlayingSoundHandle *handle, int st #else ov_time_seek(&_ov_file, startFrame / 75.0); #endif - mixer->playVorbis(handle, &_ov_file, - duration * ov_info(&_ov_file, -1)->rate / 75, true); + + AudioInputStream *input = makeVorbisStream(&_ov_file, duration * ov_info(&_ov_file, -1)->rate / 75); + mixer->playInputStream(handle, input, true); } VorbisTrackInfo::~VorbisTrackInfo() { @@ -128,6 +156,10 @@ VorbisTrackInfo::~VorbisTrackInfo() { } } +DigitalTrackInfo *makeVorbisTrackInfo(File *file) { + return new VorbisTrackInfo(file); +} + #pragma mark - #pragma mark --- Ogg Vorbis stream --- #pragma mark - diff --git a/sound/vorbis.h b/sound/vorbis.h index 8b4fd0d11f..3241f884ae 100644 --- a/sound/vorbis.h +++ b/sound/vorbis.h @@ -27,27 +27,12 @@ #ifdef USE_VORBIS -#include "sound/audiocd.h" -#include - class AudioInputStream; +class DigitalTrackInfo; class File; -class VorbisTrackInfo : public DigitalTrackInfo { -private: - File *_file; - OggVorbis_File _ov_file; - bool _error_flag; - -public: - VorbisTrackInfo(File *file); - ~VorbisTrackInfo(); - bool error() { return _error_flag; } - void play(SoundMixer *mixer, PlayingSoundHandle *handle, int startFrame, int duration); -}; - +DigitalTrackInfo *makeVorbisTrackInfo(File *file); -AudioInputStream *makeVorbisStream(OggVorbis_File *file, int duration); AudioInputStream *makeVorbisStream(File *file, uint32 size); #endif -- cgit v1.2.3