[Scummvm-cvs-logs] CVS: scummvm/sound mixer.cpp,1.21,1.22 mixer.h,1.13,1.14
James Brown
ender at users.sourceforge.net
Sun May 12 09:54:01 CEST 2002
Update of /cvsroot/scummvm/scummvm/sound
In directory usw-pr-cvs1:/tmp/cvs-serv24309/sound
Modified Files:
mixer.cpp mixer.h
Log Message:
Add new mixer 'append' function to allow pseudo-streaming for SMUSH
Index: mixer.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/sound/mixer.cpp,v
retrieving revision 1.21
retrieving revision 1.22
diff -u -d -r1.21 -r1.22
--- mixer.cpp 4 May 2002 00:10:01 -0000 1.21
+++ mixer.cpp 12 May 2002 16:53:13 -0000 1.22
@@ -38,6 +38,18 @@
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,7 +175,36 @@
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) {
Index: mixer.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/sound/mixer.h,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -d -r1.13 -r1.14
--- mixer.h 1 May 2002 22:22:22 -0000 1.13
+++ mixer.h 12 May 2002 16:53:13 -0000 1.14
@@ -36,6 +36,7 @@
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 @@
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 @@
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 @@
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 @@
};
-
struct MP3OffsetTable { /* Compressed Sound (.SO3) */
int org_offset;
int new_offset;
@@ -172,56 +178,9 @@
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 */
More information about the Scummvm-git-logs
mailing list