User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the C++ section within the Software Development category of DaniWeb, a massive community of 422,916 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,309 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our C++ advertiser: Programming Forums
Views: 254 | Replies: 1
Reply
Join Date: Jul 2007
Posts: 37
Reputation: linux0id is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 0
linux0id's Avatar
linux0id linux0id is offline Offline
Light Poster

playback of decoded audio at normal speed

  #1  
May 26th, 2008
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; 
		
				
   int iNumAudioBytes = AVCODEC_MAX_AUDIO_FRAME_SIZE;
   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,
                               &iNumAudioBytes, 
                               pIn, lAudioBytesRemaining);
			
   delete pIn;
			
   if(bytesDecoded <= 0)
   {
         cerr << "* Decoding Error!" << endl;
         break;
    }
    else
    {
         //This function takes the buffer and passes its content to sound card
         alsaPlay((void*)buffer, bytesDecoded);
    }

}
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Jul 2007
Posts: 37
Reputation: linux0id is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 0
linux0id's Avatar
linux0id linux0id is offline Offline
Light Poster

Re: playback of decoded audio at normal speed

  #2  
May 27th, 2008
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?
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb C++ Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Other Threads in the C++ Forum

All times are GMT -4. The time now is 1:33 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC