diff --git a/engine/client/m_mp3.c b/engine/client/m_mp3.c index c52c0feff..f8fc007c9 100644 --- a/engine/client/m_mp3.c +++ b/engine/client/m_mp3.c @@ -1186,7 +1186,7 @@ qboolean Media_ShowFilm(void) fwrite(&size, sizeof(size), 1, f); fclose(f); */ - S_RawAudio(-1, roqfilm->audio, 22050, roqfilm->audio_size/roqfilm->audio_channels/2, roqfilm->audio_channels, 2); + S_RawAudio(-1, roqfilm->audio, 22050, roqfilm->audio_size/roqfilm->audio_channels, roqfilm->audio_channels, 2); } return true; @@ -1236,18 +1236,18 @@ qboolean Media_ShowFilm(void) { LONG lSize; LPBYTE pBuffer; - AVIStreamRead(pavisound, soundpos, AVISTREAMREAD_CONVENIENT, - NULL, 0, &lSize, NULL); + LONG samples; - soundpos+=lSize; + AVIStreamRead(pavisound, 0, AVISTREAMREAD_CONVENIENT, + NULL, 0, &lSize, &samples); + + soundpos+=samples; pBuffer = framedata; + AVIStreamRead(pavisound, soundpos, AVISTREAMREAD_CONVENIENT, pBuffer, lSize, NULL, &samples); - AVIStreamRead(pavisound, 0, AVISTREAMREAD_CONVENIENT, pBuffer, lSize, NULL, NULL); - - S_RawAudio(-1, pBuffer, pWaveFormat->nSamplesPerSec, lSize, pWaveFormat->nChannels, 2); - + S_RawAudio(-1, pBuffer, pWaveFormat->nSamplesPerSec, samples, pWaveFormat->nChannels, 2); } } return true; diff --git a/engine/client/roq.h b/engine/client/roq.h index d7390c8db..8bc813aa2 100644 --- a/engine/client/roq.h +++ b/engine/client/roq.h @@ -27,7 +27,7 @@ typedef struct { unsigned char *buf; roq_cell cells[256]; roq_qcell qcells[256]; - short snd_sqr_arr[260]; + short snd_sqr_arr[256]; long roq_start, aud_pos, vid_pos; long *frame_offset; unsigned long num_frames, num_audio_bytes; diff --git a/engine/client/roq_read.c b/engine/client/roq_read.c index 343f8e000..4c54c5cb3 100644 --- a/engine/client/roq_read.c +++ b/engine/client/roq_read.c @@ -569,7 +569,7 @@ int i, snd_left, snd_right; fseek(fp, chunk_size, SEEK_CUR); } - if(ri->audio_buf_size < chunk_size * 2) + if(ri->audio_buf_size < chunk_size*2) { if(ri->audio != NULL) BZ_Free(ri->audio); ri->audio=NULL; @@ -583,12 +583,12 @@ int i, snd_left, snd_right; if(chunk_id == RoQ_SOUND_MONO) { - ri->audio_size = chunk_size * 2; + ri->audio_size = chunk_size; snd_left = chunk_arg; for(i = 0; i < chunk_size; i++) { - snd_left += ri->snd_sqr_arr[(unsigned)fgetc(fp)]; - *(unsigned short *)&ri->audio[i * 2] = snd_left; + snd_left += (int)ri->snd_sqr_arr[(unsigned)fgetc(fp)]; + *(short *)&ri->audio[i * 2] = snd_left; } ri->aud_pos = ftell(fp); return chunk_size; @@ -596,18 +596,18 @@ int i, snd_left, snd_right; if(chunk_id == RoQ_SOUND_STEREO) { - ri->audio_size = chunk_size * 2; + ri->audio_size = chunk_size; snd_left = (chunk_arg & 0xFF00); snd_right = (chunk_arg & 0xFF) << 8; for(i = 0; i < chunk_size; i += 2) { - snd_left += ri->snd_sqr_arr[(unsigned)fgetc(fp)]; - snd_right += ri->snd_sqr_arr[(unsigned)fgetc(fp)]; - *(unsigned short *)&ri->audio[i * 2] = snd_left; - *(unsigned short *)&ri->audio[i * 2 + 2] = snd_right; + snd_left += (int)ri->snd_sqr_arr[(unsigned)fgetc(fp)]; + snd_right += (int)ri->snd_sqr_arr[(unsigned)fgetc(fp)]; + *(short *)&ri->audio[i * 2] = snd_left; + *(short *)&ri->audio[i * 2 + 2] = snd_right; } ri->aud_pos = ftell(fp); - return chunk_size/2; + return chunk_size; } ri->aud_pos = ftell(fp); diff --git a/engine/client/snd_dma.c b/engine/client/snd_dma.c index 301e062fd..b0a906b6c 100644 --- a/engine/client/snd_dma.c +++ b/engine/client/snd_dma.c @@ -1559,6 +1559,7 @@ void S_RawAudio(int sourceid, qbyte *data, int speed, int samples, int channels, int prepadl; int oldlength; int spare; + int outsamples; float speedfactor; sfxcache_t *newcache; streaming_t *s, *free=NULL; @@ -1589,7 +1590,6 @@ void S_RawAudio(int sourceid, qbyte *data, int speed, int samples, int channels, BZ_Free(s->sfxcache); return; } - samples/=channels; if (i == MAX_RAW_SOURCES) //whoops. { if (!free) @@ -1620,6 +1620,9 @@ void S_RawAudio(int sourceid, qbyte *data, int speed, int samples, int channels, // Con_Printf("Restarting raw stream\n"); } + speedfactor = (float)speed/snd_speed; + outsamples = samples/speedfactor; + oldlength = s->sfxcache->length; prepadl = 0x7fffffff; @@ -1652,7 +1655,7 @@ void S_RawAudio(int sourceid, qbyte *data, int speed, int samples, int channels, if (spare < 0) //remaining samples since last time spare = 0; - if (s->sfxcache->length > snd_speed) //more than a second already buffered + if (s->sfxcache->length > snd_speed*2) // more than 2 seconds of sound { Con_Printf("Sacrificed raw sound stream\n"); spare = 0; //too far out. sacrifice it all @@ -1674,16 +1677,16 @@ void S_RawAudio(int sourceid, qbyte *data, int speed, int samples, int channels, return; //let the slower sound cards catch up. (This shouldn't really happen, but it's possible two cards have slightly different timings but report the same speed) }*/ - newcache = BZ_Malloc(sizeof(sfxcache_t) + (spare+samples) * (s->sfxcache->stereo+1) * s->sfxcache->width); + newcache = BZ_Malloc(sizeof(sfxcache_t) + (spare+outsamples) * (s->sfxcache->stereo+1) * s->sfxcache->width); memcpy(newcache, s->sfxcache, sizeof(sfxcache_t)); memcpy(newcache->data, s->sfxcache->data + prepadl * (s->sfxcache->stereo+1) * s->sfxcache->width, spare * (s->sfxcache->stereo+1) * s->sfxcache->width); BZ_Free(s->sfxcache); s->sfxcache = s->sfx.cache.data = newcache; - newcache->length = spare + samples; + newcache->length = spare + outsamples; - speedfactor = (float)snd_speed/speed; + // move this whole operation to a seperate function? if (channels == 1) { if (width == 2) @@ -1704,9 +1707,9 @@ void S_RawAudio(int sourceid, qbyte *data, int speed, int samples, int channels, int src=0; int pos=0; - while (pos++ < samples) + while (pos++ < outsamples) { - src = pos/speedfactor; + src = pos*speedfactor; sample = indata[src]; *outpos++ = sample; } @@ -1730,9 +1733,9 @@ void S_RawAudio(int sourceid, qbyte *data, int speed, int samples, int channels, int src=0; int pos=0; - while (pos++ < samples) + while (pos++ < outsamples) { - src = pos/speedfactor; + src = pos*speedfactor; sample = indata[src]; *outpos++ = (int)( (unsigned char)(sample) - 128); } @@ -1764,9 +1767,9 @@ void S_RawAudio(int sourceid, qbyte *data, int speed, int samples, int channels, int src=0; int pos=0; - while (pos++ < samples) + while (pos++ < outsamples) { - src = pos/speedfactor; + src = pos*speedfactor; sample = indata[src*2]; *outpos++ = sample; @@ -1781,7 +1784,6 @@ void S_RawAudio(int sourceid, qbyte *data, int speed, int samples, int channels, s->sfxcache->loopstart = s->sfxcache->length; - for (si = sndcardinfo; si; si=si->next) { for (i = 0; i < MAX_CHANNELS; i++) @@ -1789,7 +1791,7 @@ void S_RawAudio(int sourceid, qbyte *data, int speed, int samples, int channels, { si->channel[i].pos -= prepadl; // si->channel[i].end -= prepadl; - si->channel[i].end += samples; + si->channel[i].end += outsamples; if (si->channel[i].end < si->paintedtime) {