Add new mixer 'append' function to allow pseudo-streaming for SMUSH

svn-id: r4291
This commit is contained in:
James Brown 2002-05-12 16:53:13 +00:00
parent 38af71139f
commit 0d60185a88
3 changed files with 54 additions and 55 deletions

View File

@ -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));

View File

@ -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;

View File

@ -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 */