aboutsummaryrefslogtreecommitdiff
path: root/sound
diff options
context:
space:
mode:
Diffstat (limited to 'sound')
-rw-r--r--sound/mixer.cpp29
-rw-r--r--sound/mixer.h24
2 files changed, 24 insertions, 29 deletions
diff --git a/sound/mixer.cpp b/sound/mixer.cpp
index d73ad86958..ccbe3e354c 100644
--- a/sound/mixer.cpp
+++ b/sound/mixer.cpp
@@ -64,10 +64,10 @@ int SoundMixer::play_raw(PlayingSoundHandle *handle, void *sound, uint32 size, u
int SoundMixer::play_mp3(PlayingSoundHandle *handle, void *sound, uint32 size, byte flags) {
return insert(handle, new Channel_MP3(this, sound, size, flags));
}
-void SoundMixer::play_mp3_cdtrack(PlayingSoundHandle *handle, FILE* file, void *buffer, uint32 buffer_size, mad_timer_t duration) {
- if (*handle)
- stop(*handle);
- insert(handle, new Channel_MP3_CDMUSIC(this, file, buffer, buffer_size, duration));
+int SoundMixer::play_mp3_cdtrack(PlayingSoundHandle *handle, int index, FILE* file, mad_timer_t duration) {
+ /* Stop the previously playing CD track (if any) */
+ stop(index);
+ return insert(handle, new Channel_MP3_CDMUSIC(this, file, duration));
}
#endif
@@ -113,6 +113,10 @@ void SoundMixer::stop(PlayingSoundHandle psh) {
_channels[psh-1]->destroy();
}
+void SoundMixer::stop(int index) {
+ if (_channels[index])
+ _channels[index]->destroy();
+}
bool SoundMixer::has_active_channel() {
for(int i=0; i!=NUM_CHANNELS; i++)
@@ -327,15 +331,15 @@ void SoundMixer::Channel_MP3::real_destroy() {
}
/* MP3 CD music */
+#define MP3CD_BUFFERING_SIZE 131072
-SoundMixer::Channel_MP3_CDMUSIC::Channel_MP3_CDMUSIC(SoundMixer *mixer, FILE* file, void *buffer, uint32 buffer_size, mad_timer_t duration) {
+SoundMixer::Channel_MP3_CDMUSIC::Channel_MP3_CDMUSIC(SoundMixer *mixer, FILE* file, mad_timer_t duration) {
_mixer = mixer;
_file = file;
_duration = duration;
_initialized = false;
- _buffer_size = buffer_size;
- _ptr = buffer;
- _flags = 0;
+ _buffer_size = MP3CD_BUFFERING_SIZE;
+ _ptr = malloc(MP3CD_BUFFERING_SIZE);
_to_be_destroyed = false;
mad_stream_init(&_stream);
@@ -345,8 +349,6 @@ SoundMixer::Channel_MP3_CDMUSIC::Channel_MP3_CDMUSIC(SoundMixer *mixer, FILE* fi
#endif
mad_frame_init(&_frame);
mad_synth_init(&_synth);
-
- //debug(1, "CRE %d", getpid());
}
void SoundMixer::Channel_MP3_CDMUSIC::mix(int16 *data, uint len) {
@@ -358,8 +360,6 @@ void SoundMixer::Channel_MP3_CDMUSIC::mix(int16 *data, uint len) {
return;
}
- //debug(1, "MIX %d", getpid());
-
if (!_initialized) {
int skip_loop;
// just skipped
@@ -451,15 +451,12 @@ void SoundMixer::Channel_MP3_CDMUSIC::mix(int16 *data, uint len) {
}
void SoundMixer::Channel_MP3_CDMUSIC::real_destroy() {
- if (_flags & FLAG_AUTOFREE)
- free(_ptr);
+ free(_ptr);
_mixer->uninsert(this);
mad_synth_finish(&_synth);
mad_frame_finish(&_frame);
mad_stream_finish(&_stream);
- //debug(1, "DES %d", getpid());
-
delete this;
}
diff --git a/sound/mixer.h b/sound/mixer.h
index 4f7bb6568e..7986f384a6 100644
--- a/sound/mixer.h
+++ b/sound/mixer.h
@@ -78,22 +78,19 @@ private:
class Channel_MP3_CDMUSIC : public Channel {
SoundMixer *_mixer;
void *_ptr;
- struct mad_stream _stream;
- struct mad_frame _frame;
- struct mad_synth _synth;
- uint32 _pos_in_frame;
- uint32 _size;
- uint32 _buffer_size;
- mad_timer_t _duration;
- FILE *_file;
+ struct mad_stream _stream;
+ struct mad_frame _frame;
+ struct mad_synth _synth;
+ uint32 _pos_in_frame;
+ uint32 _size;
+ uint32 _buffer_size;
+ mad_timer_t _duration;
+ FILE *_file;
bool _initialized;
- byte _flags;
public:
void mix(int16 *data, uint len);
- Channel_MP3_CDMUSIC(SoundMixer *mixer, FILE* file, void *buffer, uint32 buffer_size, mad_timer_t duration);
+ Channel_MP3_CDMUSIC(SoundMixer *mixer, FILE* file, mad_timer_t duration);
void real_destroy();
-
-
};
#endif
@@ -129,7 +126,7 @@ public:
int play_raw(PlayingSoundHandle *handle, void *sound, uint32 size, uint rate, byte flags);
#ifdef COMPRESSED_SOUND_FILE
int play_mp3(PlayingSoundHandle *handle, void *sound, uint32 size, byte flags);
- void play_mp3_cdtrack(PlayingSoundHandle *handle, FILE* file, void *buffer, uint32 buffer_size, mad_timer_t duration);
+ int play_mp3_cdtrack(PlayingSoundHandle *handle, int index, FILE* file, mad_timer_t duration);
#endif
/* Premix procedure, useful when using fmopl adlib */
@@ -143,6 +140,7 @@ public:
/* stop playing a specific sound */
void stop(PlayingSoundHandle psh);
+ void stop(int index);
/* is any channel active? */
bool has_active_channel();