>
>
>
> I'm not using sdl.
> I open the /dev/audio device. I set the number of channels (it is set with
> the codec.channels) and the sample rate.
> This is how I write datas :
> write(_fileDescriptor, buffer, size)
> where "buffer" contains the datas decoded by ffmpeg
> (avcodec_decode_audio2).
>
> Nicolas Krieger
I have found a solution.
I used SDL to convert from mono to stereo (decodedBuffer contains the data
decoded with ffmpeg) :
SDL_AudioCVT cvt;
SDL_BuildAudioCVT(&cvt, AUDIO_S16, 1, 44100, AUDIO_S16, 2, 44100);
cvt.buf = (Uint8*)malloc(decodedBuffer->getDataSize()*cvt.len_mult);
memcpy(cvt.buf, decodedBuffer->getBuffer(), decodedBuffer->getDataSize());
cvt.len = decodedBuffer->getDataSize();
SDL_ConvertAudio(&cvt);
And then, if we want the left or right channel (_leftVolume and _rightVolume
values are between 0 and 1) :
int16 = (short*) (cvt.buf);
for(int i=0; i<cvt.len_cvt/2; i++) {
if (leftchannel) {
(*int16) = (short)((float)(*int16) * _leftVolume);
} else {
(*int16) = (short)((float)(*int16) * _rightVolume);
}
int16++;
leftchannel = !leftchannel;
}
and pass the data to the audio device.
Nicolas Krieger
_______________________________________________
libav-user mailing list
[email protected]
https://lists.mplayerhq.hu/mailman/listinfo/libav-user