Skip to content
Snippets Groups Projects
Commit 3d2a5409 authored by Alexandre Savard's avatar Alexandre Savard
Browse files

[#2333] Lengthen the audio buffer reduce number of underrun in pulseaudio

parent 286847f9
No related branches found
No related tags found
No related merge requests found
......@@ -185,8 +185,8 @@ AudioStream::createStream (pa_context* c)
// 2048 bytes (1024 int16) is 20 ms at 44100 Hz
if (_streamType == PLAYBACK_STREAM) {
attributes->maxlength = 32000;
attributes->tlength = 8192;
attributes->prebuf = 2048;
attributes->tlength = 16000;
attributes->prebuf = 1024;
attributes->minreq = 512;
attributes->fragsize = (uint32_t) -1;
pa_stream_connect_playback( s , NULL , attributes, PA_STREAM_INTERPOLATE_TIMING, &_volume, NULL);
......@@ -196,9 +196,9 @@ AudioStream::createStream (pa_context* c)
// attributes->maxlength = 66500;
// attributes->fragsize = (uint32_t)-1;
attributes->maxlength = 16000;
attributes->tlength = 8192;
attributes->prebuf = 2048;
attributes->maxlength = 32000;
attributes->tlength = 16000;
attributes->prebuf = 1024;
attributes->minreq = 512;
attributes->fragsize = (uint32_t) -1;
......
......@@ -57,8 +57,16 @@ static void stream_moved_callback(pa_stream *s UNUSED, void *userdata UNUSED)
static void playback_underflow_callback (pa_stream* s, void* userdata UNUSED)
{
_debug ("PulseLayer::Buffer Underflow\n");
SFLDataFormat* out = (SFLDataFormat*) pa_xmalloc (framesPerBuffer*sizeof(SFLDataFormat));
bzero (out, framesPerBuffer*sizeof(SFLDataFormat));
pa_stream_write (s, out, framesPerBuffer*sizeof(SFLDataFormat), NULL, 0, PA_SEEK_RELATIVE);
pa_stream_trigger (s, NULL, NULL);
pa_xfree (out);
}
......@@ -485,9 +493,9 @@ void PulseLayer::writeToSpeaker (void)
{
toGet = framesPerBuffer;
toPlay = ( (int) (toGet * sizeof (SFLDataFormat)) > framesPerBuffer) ? framesPerBuffer : toGet * sizeof (SFLDataFormat);
toPlay = ( (int) (toGet * sizeof (SFLDataFormat)) > framesPerBuffer * sizeof (SFLDataFormat)) ? framesPerBuffer : toGet * sizeof (SFLDataFormat);
out = (SFLDataFormat*) pa_xmalloc (toPlay);
file_tone->getNext(out, toPlay/2 , 100);
file_tone->getNext(out, toPlay/sizeof(SFLDataFormat), 100);
pa_stream_write (playback->pulseStream(), out, toPlay, NULL, 0, PA_SEEK_RELATIVE);
pa_xfree (out);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment