Commit 420906d4 authored by Alexandre Savard's avatar Alexandre Savard

[#2333] Better audiostream parameters

parent 48d49ab0
......@@ -184,11 +184,11 @@ AudioStream::createStream (pa_context* c)
// parameters are defined as number of bytes
// 2048 bytes (1024 int16) is 20 ms at 44100 Hz
if (_streamType == PLAYBACK_STREAM) {
attributes->maxlength = 64000;
attributes->tlength = 32000;
attributes->maxlength = 16000;
attributes->tlength = 8192;
attributes->prebuf = 2048; // Pulseaudio will not start if prebuffering is not reached
attributes->minreq = 1024; // The server side playback framesize
attributes->fragsize = 4096; // Fragment size at wich we receive an interupt
attributes->minreq = 512; // The server side playback framesize
attributes->fragsize = 1024; // Fragment size at wich we receive an interupt
pa_stream_connect_playback( s , NULL , attributes, PA_STREAM_INTERPOLATE_TIMING, &_volume, NULL);
// pa_stream_connect_playback (s , NULL , attributes, PA_STREAM_START_CORKED, &_volume, NULL);
} else if (_streamType == CAPTURE_STREAM) {
......
......@@ -57,6 +57,12 @@ 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");
// const pa_timing_info* info = pa_stream_get_timing_info(s);
// _debug(" pa write_index: %l\n", (long)(info->write_index));
// _debug(" pa write_index_corupt (if not 0): %i\n", info->write_index_corrupt);
// _debug(" pa read_index: %l\n", (long)(info->read_index));
// _debug(" pa read_index_corrupt (if not 0): %i\n", info->read_index_corrupt);
// fill in audio buffer twice the prebuffering value to restart playback
SFLDataFormat* out = (SFLDataFormat*) pa_xmalloc (framesPerBuffer*sizeof(SFLDataFormat));
......@@ -348,12 +354,12 @@ void PulseLayer::startStream (void)
assert (context);
}
_urgentRingBuffer.flush();
_mainBuffer.flushAllBuffers();
// Create Streams
connectPulseAudioServer();
_urgentRingBuffer.flushAll();
_mainBuffer.flushAllBuffers();
is_started = true;
}
......@@ -403,18 +409,19 @@ PulseLayer::stopStream (void)
void PulseLayer::underflow (pa_stream* s UNUSED, void* userdata UNUSED)
{
_debug ("PulseLayer::Buffer Underflow\n");
}
// void PulseLayer::underflow (pa_stream* s UNUSED, void* userdata UNUSED)
//{
// _debug ("PulseLayer::Buffer Underflow\n");
//}
/*
void PulseLayer::overflow (pa_stream* s, void* userdata UNUSED)
{
//PulseLayer* pulse = (PulseLayer*) userdata;
pa_stream_drop (s);
pa_stream_trigger (s, NULL, NULL);
}
*/
void PulseLayer::processPlaybackData (void)
......@@ -453,9 +460,17 @@ void PulseLayer::writeToSpeaker (void)
int toGet;
int toPlay;
// const pa_timing_info* info = pa_stream_get_timing_info(s);
// _debug(" pa write_index: %i", info->write_index);
// _debug(" pa write_index_corupt (if not 0): %i" info->write_index_corrupt);
// _debug(" pa read_index: %i", info->read_index);
// _debug(" pa read_index_corrupt (if not 0): %i", info->read_index_corrupt);
SFLDataFormat* out;// = (SFLDataFormat*)pa_xmalloc(framesPerBuffer);
urgentAvailBytes = _urgentRingBuffer.AvailForGet();
if (urgentAvailBytes > 0) {
_debug("urgentAvailBytes: %i\n", urgentAvailBytes);
......@@ -557,9 +572,14 @@ void PulseLayer::writeToSpeaker (void)
if((tone == 0) && (file_tone == 0)) {
// _debug("maxNbBytesToGet: %i\n", maxNbBytesToGet);
bzero (out, maxNbBytesToGet);
pa_stream_write (playback->pulseStream(), out, maxNbBytesToGet, NULL, 0, PA_SEEK_RELATIVE);
_debug("maxNbBytesToGet: %i\n", maxNbBytesToGet);
SFLDataFormat* zeros = (SFLDataFormat*)pa_xmalloc (framesPerBuffer*sizeof(SFLDataFormat));
bzero (zeros, framesPerBuffer*sizeof(SFLDataFormat));
pa_stream_write(playback->pulseStream(), zeros, framesPerBuffer*sizeof(SFLDataFormat), NULL, 0, PA_SEEK_RELATIVE);
pa_xfree (zeros);
}
}
......
......@@ -1704,7 +1704,7 @@ ManagerImpl::playDtmf (char code, bool isTalking)
// Put buffer to urgentRingBuffer
// put the size in bytes...
// so size * 1 channel (mono) * sizeof (bytes for the data)
audiolayer->flushUrgent();
// audiolayer->flushUrgent();
audiolayer->startStream();
audiolayer->putUrgent (buf, size * sizeof (SFLDataFormat));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment