•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the C++ section within the Software Development category of DaniWeb, a massive community of 427,382 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,034 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: 262 | Replies: 1
![]() |
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 -
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);
}
}![]() |
•
•
•
•
•
•
•
•
DaniWeb C++ Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
Other Threads in the C++ Forum
- Previous Thread: Insertion Sort using a Linked List
- Next Thread: Hash Table ( display function )


Linear Mode