Hello everyone!
I am learning sound programming on Linux. In my app I am using ffmpeg to decode the audio, and then ALSA to pass it on to speakers. So far everything is fine - the packets are retrieved, stored in a queue. After that, the packets are read from the queue, decoded and the result passed to ALSA. Now my problem is this - the program plays the audio as fast as it can, and not at the speed it supposed to. I have read somewhere that I need some buffer or something, but I have not found any information about it. I would really appreciate if someone could point me int the right direction. Thanks! Here is the playback loop -

while (1)
   packet_queue_get(&audioq, &packet, 0);
   long lAudioBytesRemaining= packet.size;
   uint8_t  * pAudioRawData=packet.data;
   int bytesDecoded = -1; 
   long lSize = lAudioBytesRemaining  + FF_INPUT_BUFFER_PADDING_SIZE;
   uint8_t  * pIn = new uint8_t[lSize];
   memset(pIn, 0, lSize);
   memcpy(pIn, pAudioRawData, lAudioBytesRemaining);

   //This function decodes the audio, stores the result in buffer
   bytesDecoded = avcodec_decode_audio2(aCodecCtx, buffer,
                               pIn, lAudioBytesRemaining);
   delete pIn;
   if(bytesDecoded <= 0)
         cerr << "* Decoding Error!" << endl;
         //This function takes the buffer and passes its content to sound card
         alsaPlay((void*)buffer, bytesDecoded);

9 Years
Discussion Span
Last Post by linux0id

ok... lets put it another way -
how can I make a 1D array of decoded samples play at normal speed, and not as fast as possible? Anybody?

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.