[libav-api] read an audio file into a double buffer

Florian Iragne florian at iragne.fr
Fri Jan 3 08:09:51 CET 2014

Hi Luca,

Le 03/01/2014 02:49, Luca Barbato a écrit :
>>   * technical: For the double buffer output, i shunt my process when i
>> obtain the ouput AVFrame and use it's data. Is it the recommended way?
> if you feed the avframe to the avresample yes, otherwise you should
> treat that data as quasi-opaque.
>> BTW, is there a recommended way to do what i want?
> demux -> decode -> resample -> your application
> That should be enough.

Thanks for your answer

Indeed, i feed the AVFrame to the avresample. And after that, i convert 
to double data using the following code
uint8_t* data = oframe->data[0];
         for (int i = 0; i < oframe->nb_samples; ++i) {
             //divide by uint8_max to transform into double between 0 and 1
             _outBuffer[i] = (double) (data[i] - (UINT8_MAX / 2)) / 
(double) (UINT8_MAX/2);

Hence i get double values ranging from -1 to 1. But I think that's not 
the right way to do this.

Should i do something like:
avresample_convert(avr, (double*)oframe->data, oframe->linesize[0], 
frame->nb_samples, frame->data, frame->linesize[0], frame->nb_samples);

to let the avresample do the conversion? Is there any helper function?



More information about the libav-api mailing list