Question

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,

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top