diff options
-rw-r--r-- | insane.cpp | 11 | ||||
-rw-r--r-- | sound/mixer.cpp | 41 | ||||
-rw-r--r-- | sound/mixer.h | 57 |
3 files changed, 54 insertions, 55 deletions
diff --git a/insane.cpp b/insane.cpp index a9788d036b..3126ce8272 100644 --- a/insane.cpp +++ b/insane.cpp @@ -36,6 +36,7 @@ void invalidblock(uint32 tag) } int _frameChanged; +int _mixer_num; uint32 SmushPlayer::nextBE32() { @@ -645,8 +646,7 @@ void SmushPlayer::parseFOBJ() void SmushPlayer::parsePSAD() // FIXME: Needs to append to { // a sound buffer unsigned int pos, sublen, tag, idx, trk; - byte * buf; - + byte * buf; pos = 0; trk = READ_LE_UINT16(_cur + pos); /* FIXME: is this correct ? */ @@ -712,10 +712,8 @@ void SmushPlayer::parsePSAD() // FIXME: Needs to append to debug(3, "trk %d: SDAT part len 0x%x rate %d", trk, sublen, _strkRate[idx]); - g_scumm->_mixer->play_raw(NULL, buf, - sublen, _strkRate[idx], - SoundMixer::FLAG_UNSIGNED | - SoundMixer::FLAG_AUTOFREE); + g_scumm->_mixer->append(idx, buf, sublen, + _strkRate[idx], SoundMixer::FLAG_UNSIGNED | SoundMixer::FLAG_AUTOFREE); break; case 'SMRK' : _psadTrk[idx] = 0; @@ -808,6 +806,7 @@ void SmushPlayer::init() _renderBitmap = sm->_videoBuffer; codec37_init(&pcd37, 320, 200); + _mixer_num = -1; memset(_saudSize, 0, sizeof(_saudSize)); memset(_saudSubSize, 0, sizeof(_saudSubSize)); memset(_psadTrk, 0, sizeof(_psadTrk)); diff --git a/sound/mixer.cpp b/sound/mixer.cpp index 0f0de7e201..9473ddd69d 100644 --- a/sound/mixer.cpp +++ b/sound/mixer.cpp @@ -38,6 +38,18 @@ void SoundMixer::uninsert(Channel *chan) { error("SoundMixer::channel_deleted chan not found"); } +int SoundMixer::append(int index, void *sound, uint32 size, uint rate, byte flags) { + Channel *chan = _channels[index]; + if (!chan) { + chan = new Channel_RAW(this, sound, size, rate, flags); + _channels[index] = chan; + return 0; + } + + chan->append(sound, size); + return 1; +} + int SoundMixer::insert(PlayingSoundHandle *handle, Channel *chan) { for(int i=0; i!=NUM_CHANNELS; i++) { if (_channels[i] == NULL) { @@ -163,9 +175,38 @@ SoundMixer::Channel_RAW::Channel_RAW(SoundMixer *mixer, void *sound, uint32 size while (size & 0xFFFF0000) size >>= 1, rate = (rate>>1) + 1; + _realsize = size; + _rate = rate; _size = size * mixer->_output_rate / rate; } +void SoundMixer::Channel_RAW::append(void *data, uint32 len) { + int _cur_size; + void *holder; + + _mixer->_paused = true; /* Don't mix while we do this */ + + /* Init our variables */ + _cur_size = _realsize - _pos; + holder = malloc(len + _cur_size); + + /* Prepare the new buffer */ + memcpy(holder, (byte*)_ptr + _pos, _cur_size); + memcpy((byte *)holder + _cur_size, data, len); + + /* Quietly slip in the new data */ + if (_flags & FLAG_AUTOFREE) free(_ptr); + _ptr = holder; + + /* Reset sizes */ + _realsize = _cur_size + len; + _size = _realsize * _mixer->_output_rate / _rate; + _pos = 0; + _fp_pos = 0; + + _mixer->_paused = false; /* Mix again now */ +} + void SoundMixer::Channel_RAW::mix(int16 *data, uint len) { byte *s, *s_org = NULL; uint32 fp_pos; diff --git a/sound/mixer.h b/sound/mixer.h index 319c6e6979..5aba9c6add 100644 --- a/sound/mixer.h +++ b/sound/mixer.h @@ -36,6 +36,7 @@ private: virtual void mix(int16 *data, uint len) = 0; void destroy() { _to_be_destroyed = true; } virtual void real_destroy() = 0; + virtual void append(void *sound, uint32 size) = 0; #ifdef COMPRESSED_SOUND_FILE virtual bool sound_finished(); #endif @@ -48,10 +49,12 @@ private: uint32 _size; uint32 _fp_speed; uint32 _fp_pos; + uint32 _realsize, _rate; byte _flags; public: + void append(void *sound, uint32 size); void mix(int16 *data, uint len); Channel_RAW(SoundMixer *mixer, void *sound, uint32 size, uint rate, byte flags); void real_destroy(); @@ -121,6 +124,7 @@ public: PlayingSoundHandle *_handles[NUM_CHANNELS]; int insert(PlayingSoundHandle *handle, Channel *chan); + void append(void *data, uint32 len); void uninsert(Channel *chan); /* start playing a raw sound */ @@ -148,6 +152,9 @@ public: void stop(PlayingSoundHandle psh); void stop(int index); + /* append to existing sound */ + int append(int index, void *sound, uint32 size, uint rate, byte flags); + /* is any channel active? */ bool has_active_channel(); @@ -164,7 +171,6 @@ public: }; - struct MP3OffsetTable { /* Compressed Sound (.SO3) */ int org_offset; int new_offset; @@ -172,56 +178,9 @@ struct MP3OffsetTable { /* Compressed Sound (.SO3) */ int compressed_size; }; -struct BundleAudioTable { +struct BundleAudioTable { /* Dig/CMI .bun audio */ char filename[13]; int size; int offset; }; - -#if 0 -typedef enum { /* Mixer types */ - MIXER_STANDARD, - MIXER_MP3, - MIXER_MP3_CDMUSIC -} MixerType; - -struct MixerChannel { /* Mixer Channel */ - void *_sfx_sound; - MixerType type; - union { - struct { - uint32 _sfx_pos; - uint32 _sfx_size; - uint32 _sfx_fp_speed; - uint32 _sfx_fp_pos; - } standard; -#ifdef COMPRESSED_SOUND_FILE - struct { - struct mad_stream stream; - struct mad_frame frame; - struct mad_synth synth; - uint32 silence_cut; - uint32 pos_in_frame; - uint32 position; - uint32 size; - } mp3; - struct { - struct mad_stream stream; - struct mad_frame frame; - struct mad_synth synth; - uint32 pos_in_frame; - uint32 position; - uint32 size; - uint32 buffer_size; - mad_timer_t duration; - bool playing; - FILE *file; - } mp3_cdmusic; -#endif - } sound_data; - void mix(int16 *data, uint32 len); - void clear(); -}; -#endif - #endif /* _mixer_h_included */ |