Skip to content

Commit

Permalink
Fix stutter in ffmpeg movie audio
Browse files Browse the repository at this point in the history
Attempting to calculate the resampling delay for determining the number
of out samples was actually causing underruns. There is no harm in not
accounting for any resample delay because any samples not taken are
buffered for the next conversion.
  • Loading branch information
TheCycoONE committed Jan 27, 2015
1 parent 54e392b commit 3f76480
Showing 1 changed file with 0 additions and 22 deletions.
22 changes: 0 additions & 22 deletions CorsixTH/Src/th_movie.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1004,7 +1004,6 @@ int THMovie::decodeAudioFrame(bool fFirst)
}
}

#if LIBSWRESAMPLE_VERSION_INT < AV_VERSION_INT(0, 12, 100)
//over-estimate output samples
iOutSamples = (int)av_rescale_rnd(m_frame->nb_samples, m_iMixerFrequency, m_pAudioCodecContext->sample_rate, AV_ROUND_UP);
iSampleSize = av_get_bytes_per_sample(AV_SAMPLE_FMT_S16) * iOutSamples * m_iMixerChannels;
Expand All @@ -1018,27 +1017,6 @@ int THMovie::decodeAudioFrame(bool fFirst)
m_pbAudioBuffer = (uint8_t*)av_malloc(iSampleSize);
m_iAudioBufferMaxSize = iSampleSize;
}
#else
//output samples = (input samples + delay) * output rate / input rate
iOutSamples = (int)av_rescale_rnd(
swr_get_delay(
m_pAudioResampleContext,
m_pAudioCodecContext->sample_rate) + m_frame->nb_samples,
m_iMixerFrequency,
m_pAudioCodecContext->sample_rate,
AV_ROUND_UP);
iSampleSize = av_samples_get_buffer_size(NULL, m_iMixerChannels, iOutSamples, AV_SAMPLE_FMT_S16, 0);

if(iSampleSize > m_iAudioBufferMaxSize)
{
if(m_iAudioBufferMaxSize > 0)
{
av_free(m_pbAudioBuffer);
}
av_samples_alloc(&m_pbAudioBuffer, NULL, m_iMixerChannels, iOutSamples, AV_SAMPLE_FMT_S16, 0);
m_iAudioBufferMaxSize = iSampleSize;
}
#endif

#ifdef CORSIX_TH_USE_FFMPEG
swr_convert(m_pAudioResampleContext, &m_pbAudioBuffer, iOutSamples, (const uint8_t**)&m_frame->data[0], m_frame->nb_samples);
Expand Down

0 comments on commit 3f76480

Please sign in to comment.