aboutsummaryrefslogtreecommitdiff
path: root/sound
diff options
context:
space:
mode:
authorJames Brown2002-05-12 16:53:13 +0000
committerJames Brown2002-05-12 16:53:13 +0000
commit0d60185a8839bbc1f6a49697b54784f71f08f34a (patch)
tree387f1b20ce0ed077e463e3ded7324cb2de458d2d /sound
parent38af71139fd98202d0e6888968e8e2f19c61ecce (diff)
downloadscummvm-rg350-0d60185a8839bbc1f6a49697b54784f71f08f34a.tar.gz
scummvm-rg350-0d60185a8839bbc1f6a49697b54784f71f08f34a.tar.bz2
scummvm-rg350-0d60185a8839bbc1f6a49697b54784f71f08f34a.zip
Add new mixer 'append' function to allow pseudo-streaming for SMUSH
svn-id: r4291
Diffstat (limited to 'sound')
-rw-r--r--sound/mixer.cpp41
-rw-r--r--sound/mixer.h57
2 files changed, 49 insertions, 49 deletions
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 */