mirror of
https://github.com/nzp-team/fteqw.git
synced 2024-11-13 07:47:45 +00:00
roq fixes, but timing is still way off
an attempt to fix avi playback.. but it's still busted git-svn-id: https://svn.code.sf.net/p/fteqw/code/trunk@1227 fc73d0e0-1445-4013-8a0c-d673dee63da5
This commit is contained in:
parent
0511e3bcbf
commit
027032a304
4 changed files with 34 additions and 32 deletions
|
@ -1186,7 +1186,7 @@ qboolean Media_ShowFilm(void)
|
||||||
fwrite(&size, sizeof(size), 1, f);
|
fwrite(&size, sizeof(size), 1, f);
|
||||||
fclose(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;
|
return true;
|
||||||
|
@ -1236,18 +1236,18 @@ qboolean Media_ShowFilm(void)
|
||||||
{
|
{
|
||||||
LONG lSize;
|
LONG lSize;
|
||||||
LPBYTE pBuffer;
|
LPBYTE pBuffer;
|
||||||
AVIStreamRead(pavisound, soundpos, AVISTREAMREAD_CONVENIENT,
|
LONG samples;
|
||||||
NULL, 0, &lSize, NULL);
|
|
||||||
|
|
||||||
soundpos+=lSize;
|
AVIStreamRead(pavisound, 0, AVISTREAMREAD_CONVENIENT,
|
||||||
|
NULL, 0, &lSize, &samples);
|
||||||
|
|
||||||
|
soundpos+=samples;
|
||||||
|
|
||||||
pBuffer = framedata;
|
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, samples, pWaveFormat->nChannels, 2);
|
||||||
|
|
||||||
S_RawAudio(-1, pBuffer, pWaveFormat->nSamplesPerSec, lSize, pWaveFormat->nChannels, 2);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -27,7 +27,7 @@ typedef struct {
|
||||||
unsigned char *buf;
|
unsigned char *buf;
|
||||||
roq_cell cells[256];
|
roq_cell cells[256];
|
||||||
roq_qcell qcells[256];
|
roq_qcell qcells[256];
|
||||||
short snd_sqr_arr[260];
|
short snd_sqr_arr[256];
|
||||||
long roq_start, aud_pos, vid_pos;
|
long roq_start, aud_pos, vid_pos;
|
||||||
long *frame_offset;
|
long *frame_offset;
|
||||||
unsigned long num_frames, num_audio_bytes;
|
unsigned long num_frames, num_audio_bytes;
|
||||||
|
|
|
@ -569,7 +569,7 @@ int i, snd_left, snd_right;
|
||||||
fseek(fp, chunk_size, SEEK_CUR);
|
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);
|
if(ri->audio != NULL) BZ_Free(ri->audio);
|
||||||
ri->audio=NULL;
|
ri->audio=NULL;
|
||||||
|
@ -583,12 +583,12 @@ int i, snd_left, snd_right;
|
||||||
|
|
||||||
if(chunk_id == RoQ_SOUND_MONO)
|
if(chunk_id == RoQ_SOUND_MONO)
|
||||||
{
|
{
|
||||||
ri->audio_size = chunk_size * 2;
|
ri->audio_size = chunk_size;
|
||||||
snd_left = chunk_arg;
|
snd_left = chunk_arg;
|
||||||
for(i = 0; i < chunk_size; i++)
|
for(i = 0; i < chunk_size; i++)
|
||||||
{
|
{
|
||||||
snd_left += ri->snd_sqr_arr[(unsigned)fgetc(fp)];
|
snd_left += (int)ri->snd_sqr_arr[(unsigned)fgetc(fp)];
|
||||||
*(unsigned short *)&ri->audio[i * 2] = snd_left;
|
*(short *)&ri->audio[i * 2] = snd_left;
|
||||||
}
|
}
|
||||||
ri->aud_pos = ftell(fp);
|
ri->aud_pos = ftell(fp);
|
||||||
return chunk_size;
|
return chunk_size;
|
||||||
|
@ -596,18 +596,18 @@ int i, snd_left, snd_right;
|
||||||
|
|
||||||
if(chunk_id == RoQ_SOUND_STEREO)
|
if(chunk_id == RoQ_SOUND_STEREO)
|
||||||
{
|
{
|
||||||
ri->audio_size = chunk_size * 2;
|
ri->audio_size = chunk_size;
|
||||||
snd_left = (chunk_arg & 0xFF00);
|
snd_left = (chunk_arg & 0xFF00);
|
||||||
snd_right = (chunk_arg & 0xFF) << 8;
|
snd_right = (chunk_arg & 0xFF) << 8;
|
||||||
for(i = 0; i < chunk_size; i += 2)
|
for(i = 0; i < chunk_size; i += 2)
|
||||||
{
|
{
|
||||||
snd_left += ri->snd_sqr_arr[(unsigned)fgetc(fp)];
|
snd_left += (int)ri->snd_sqr_arr[(unsigned)fgetc(fp)];
|
||||||
snd_right += ri->snd_sqr_arr[(unsigned)fgetc(fp)];
|
snd_right += (int)ri->snd_sqr_arr[(unsigned)fgetc(fp)];
|
||||||
*(unsigned short *)&ri->audio[i * 2] = snd_left;
|
*(short *)&ri->audio[i * 2] = snd_left;
|
||||||
*(unsigned short *)&ri->audio[i * 2 + 2] = snd_right;
|
*(short *)&ri->audio[i * 2 + 2] = snd_right;
|
||||||
}
|
}
|
||||||
ri->aud_pos = ftell(fp);
|
ri->aud_pos = ftell(fp);
|
||||||
return chunk_size/2;
|
return chunk_size;
|
||||||
}
|
}
|
||||||
|
|
||||||
ri->aud_pos = ftell(fp);
|
ri->aud_pos = ftell(fp);
|
||||||
|
|
|
@ -1559,6 +1559,7 @@ void S_RawAudio(int sourceid, qbyte *data, int speed, int samples, int channels,
|
||||||
int prepadl;
|
int prepadl;
|
||||||
int oldlength;
|
int oldlength;
|
||||||
int spare;
|
int spare;
|
||||||
|
int outsamples;
|
||||||
float speedfactor;
|
float speedfactor;
|
||||||
sfxcache_t *newcache;
|
sfxcache_t *newcache;
|
||||||
streaming_t *s, *free=NULL;
|
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);
|
BZ_Free(s->sfxcache);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
samples/=channels;
|
|
||||||
if (i == MAX_RAW_SOURCES) //whoops.
|
if (i == MAX_RAW_SOURCES) //whoops.
|
||||||
{
|
{
|
||||||
if (!free)
|
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");
|
// Con_Printf("Restarting raw stream\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
speedfactor = (float)speed/snd_speed;
|
||||||
|
outsamples = samples/speedfactor;
|
||||||
|
|
||||||
oldlength = s->sfxcache->length;
|
oldlength = s->sfxcache->length;
|
||||||
|
|
||||||
prepadl = 0x7fffffff;
|
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
|
if (spare < 0) //remaining samples since last time
|
||||||
spare = 0;
|
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");
|
Con_Printf("Sacrificed raw sound stream\n");
|
||||||
spare = 0; //too far out. sacrifice it all
|
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)
|
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, 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);
|
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);
|
BZ_Free(s->sfxcache);
|
||||||
s->sfxcache = s->sfx.cache.data = newcache;
|
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 (channels == 1)
|
||||||
{
|
{
|
||||||
if (width == 2)
|
if (width == 2)
|
||||||
|
@ -1704,9 +1707,9 @@ void S_RawAudio(int sourceid, qbyte *data, int speed, int samples, int channels,
|
||||||
int src=0;
|
int src=0;
|
||||||
int pos=0;
|
int pos=0;
|
||||||
|
|
||||||
while (pos++ < samples)
|
while (pos++ < outsamples)
|
||||||
{
|
{
|
||||||
src = pos/speedfactor;
|
src = pos*speedfactor;
|
||||||
sample = indata[src];
|
sample = indata[src];
|
||||||
*outpos++ = sample;
|
*outpos++ = sample;
|
||||||
}
|
}
|
||||||
|
@ -1730,9 +1733,9 @@ void S_RawAudio(int sourceid, qbyte *data, int speed, int samples, int channels,
|
||||||
int src=0;
|
int src=0;
|
||||||
int pos=0;
|
int pos=0;
|
||||||
|
|
||||||
while (pos++ < samples)
|
while (pos++ < outsamples)
|
||||||
{
|
{
|
||||||
src = pos/speedfactor;
|
src = pos*speedfactor;
|
||||||
sample = indata[src];
|
sample = indata[src];
|
||||||
*outpos++ = (int)( (unsigned char)(sample) - 128);
|
*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 src=0;
|
||||||
int pos=0;
|
int pos=0;
|
||||||
|
|
||||||
while (pos++ < samples)
|
while (pos++ < outsamples)
|
||||||
{
|
{
|
||||||
src = pos/speedfactor;
|
src = pos*speedfactor;
|
||||||
sample = indata[src*2];
|
sample = indata[src*2];
|
||||||
*outpos++ = sample;
|
*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;
|
s->sfxcache->loopstart = s->sfxcache->length;
|
||||||
|
|
||||||
|
|
||||||
for (si = sndcardinfo; si; si=si->next)
|
for (si = sndcardinfo; si; si=si->next)
|
||||||
{
|
{
|
||||||
for (i = 0; i < MAX_CHANNELS; i++)
|
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].pos -= prepadl;
|
||||||
// si->channel[i].end -= prepadl;
|
// si->channel[i].end -= prepadl;
|
||||||
si->channel[i].end += samples;
|
si->channel[i].end += outsamples;
|
||||||
|
|
||||||
if (si->channel[i].end < si->paintedtime)
|
if (si->channel[i].end < si->paintedtime)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue