简体   繁体   中英

FFMPEG audio decoding: efficient conversion from short to float sample buffer

I am using the FFMPEG avcodec_decode_audio to decode audio input files of various types. The resulting samples are of type SHORT.

These samples are processed with another library which requires the samples in FLOAT input format. Finally, for playback (on Android), I need to convert the FLOAT samples back to SHORT again:

short* inputSamples = ...;
float* tmpBuffer = new float[nrInputSamples];
for (int i=0; i<nrInputSamples; i++)
  tmpBuffer[i] = inputSamples[i]/32767.0f;

//process audio here

for (int i=0; i<nrInputSamples; i++)
  inputSamples[i] = tmpBuffer[i]*32767.0f;

Is there a more efficient way to do this (for instance force ffmpeg to decode the audio to FLOAT samples)?

Regards,

Use, the 'swresample' library that is included in the ffmpeg library, it exists for cases such as this. You can find examples on how to do this in their code repository.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM