Bink: remove redundant audio info from binkMovie
Read the sample rate and number of channels from individual audio frames.
This commit is contained in:
parent
cb72993765
commit
5b9a0e939c
1 changed files with 5 additions and 13 deletions
18
src/bink.c
18
src/bink.c
|
@ -51,9 +51,7 @@ struct binkMovie {
|
||||||
AVCodecContext* audioContext;
|
AVCodecContext* audioContext;
|
||||||
BOOL alInited;
|
BOOL alInited;
|
||||||
ALuint alSource;
|
ALuint alSource;
|
||||||
ALuint alNumChannels;
|
|
||||||
ALenum alFormat;
|
ALenum alFormat;
|
||||||
ALuint alSampleRate;
|
|
||||||
|
|
||||||
// Decoded audio frame queue.
|
// Decoded audio frame queue.
|
||||||
ALuint audioFrames[AUDIO_FRAMES];
|
ALuint audioFrames[AUDIO_FRAMES];
|
||||||
|
@ -186,31 +184,25 @@ static int DecodeAudioFrame(struct binkMovie* aMovie)
|
||||||
case AV_CH_LAYOUT_MONO:
|
case AV_CH_LAYOUT_MONO:
|
||||||
aMovie->alFormat = (aMovie->audioFrame->format == AV_SAMPLE_FMT_U8) ?
|
aMovie->alFormat = (aMovie->audioFrame->format == AV_SAMPLE_FMT_U8) ?
|
||||||
AL_FORMAT_MONO8 : AL_FORMAT_MONO16;
|
AL_FORMAT_MONO8 : AL_FORMAT_MONO16;
|
||||||
aMovie->alNumChannels = 1;
|
|
||||||
break;
|
break;
|
||||||
case AV_CH_LAYOUT_STEREO:
|
case AV_CH_LAYOUT_STEREO:
|
||||||
aMovie->alFormat = (aMovie->audioFrame->format == AV_SAMPLE_FMT_U8) ?
|
aMovie->alFormat = (aMovie->audioFrame->format == AV_SAMPLE_FMT_U8) ?
|
||||||
AL_FORMAT_STEREO8 : AL_FORMAT_STEREO16;
|
AL_FORMAT_STEREO8 : AL_FORMAT_STEREO16;
|
||||||
aMovie->alNumChannels = 2;
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
aMovie->alSampleRate = aMovie->audioFrame->sample_rate;
|
|
||||||
aMovie->audioTempBuffer =
|
aMovie->audioTempBuffer =
|
||||||
malloc(aMovie->alNumChannels * aMovie->audioFrame->nb_samples * 2 * 2);
|
malloc(aMovie->audioFrame->channels * aMovie->audioFrame->nb_samples * 2 * 2);
|
||||||
aMovie->alInited = TRUE;
|
aMovie->alInited = TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (aMovie->alNumChannels == 0)
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
if (aMovie->alNumFreeBuffers == 0)
|
if (aMovie->alNumFreeBuffers == 0)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
// queue this frame
|
// queue this frame
|
||||||
ALuint alBuffer = aMovie->alFreeBuffers[aMovie->alNumFreeBuffers-1];
|
ALuint alBuffer = aMovie->alFreeBuffers[aMovie->alNumFreeBuffers-1];
|
||||||
|
|
||||||
int sampleCount = aMovie->audioFrame->nb_samples * aMovie->alNumChannels;
|
int sampleCount = aMovie->audioFrame->nb_samples * aMovie->audioFrame->channels;
|
||||||
uint dataSize = sampleCount * 2; // 16bit is deafult
|
uint dataSize = sampleCount * 2; // 16bit is deafult
|
||||||
void* data = (void*)aMovie->audioFrame->extended_data[0];
|
void* data = (void*)aMovie->audioFrame->extended_data[0];
|
||||||
|
|
||||||
|
@ -254,20 +246,20 @@ static int DecodeAudioFrame(struct binkMovie* aMovie)
|
||||||
data = (void*)aMovie->audioTempBuffer;
|
data = (void*)aMovie->audioTempBuffer;
|
||||||
short* tempBuf = (short*)aMovie->audioTempBuffer;
|
short* tempBuf = (short*)aMovie->audioTempBuffer;
|
||||||
for (int i = 0; i < aMovie->audioFrame->nb_samples; i++) {
|
for (int i = 0; i < aMovie->audioFrame->nb_samples; i++) {
|
||||||
for (int j = 0; j < aMovie->alNumChannels; j++) {
|
for (int j = 0; j < aMovie->audioFrame->channels; j++) {
|
||||||
float* srcBuf = (float*)aMovie->audioFrame->extended_data[j];
|
float* srcBuf = (float*)aMovie->audioFrame->extended_data[j];
|
||||||
float val = srcBuf[i] * 32768;
|
float val = srcBuf[i] * 32768;
|
||||||
if (val > 32767)
|
if (val > 32767)
|
||||||
val = 32767;
|
val = 32767;
|
||||||
if (val < -32768)
|
if (val < -32768)
|
||||||
val = -32768;
|
val = -32768;
|
||||||
tempBuf[(i*aMovie->alNumChannels)+j] = (short)val;
|
tempBuf[(i*aMovie->audioFrame->channels)+j] = (short)val;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} break;
|
} break;
|
||||||
}
|
}
|
||||||
|
|
||||||
alBufferData(alBuffer, aMovie->alFormat, data, dataSize - 16, aMovie->alSampleRate);
|
alBufferData(alBuffer, aMovie->alFormat, data, dataSize - 16, aMovie->audioFrame->sample_rate);
|
||||||
AL_CHECK();
|
AL_CHECK();
|
||||||
|
|
||||||
alSourceQueueBuffers(aMovie->alSource, 1, &alBuffer);
|
alSourceQueueBuffers(aMovie->alSource, 1, &alBuffer);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue