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

[#2333] Update streams parameters

parent ad4852c2
No related branches found
No related tags found
No related merge requests found
......@@ -34,6 +34,7 @@ AudioStream::AudioStream (PulseLayerType * driver)
_mainloop (driver->mainloop)
{
sample_spec.format = PA_SAMPLE_S16LE;
// sample_spec.format = PA_SAMPLE_FLOAT32LE;
sample_spec.rate = 44100;
sample_spec.channels = 1;
channel_map.channels = 1;
......@@ -184,23 +185,31 @@ 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 = 88200;
attributes->tlength = 44100;
/*
attributes->maxlength = (uint32_t) -1;
attributes->tlength = 4096;
attributes->prebuf = (uint32_t) -1;
attributes->minreq = (uint32_t) -1;
attributes->fragsize = (uint32_t) -1;
*/
attributes->maxlength = 88200;
attributes->tlength = 8192;
attributes->prebuf = 4096;
attributes->minreq = 2048;
attributes->fragsize = 4096;
pa_stream_connect_playback( s , NULL , attributes, PA_STREAM_ADJUST_LATENCY, &_volume, NULL);
} else if (_streamType == CAPTURE_STREAM) {
attributes->maxlength = 88200;
attributes->tlength = 44100;
attributes->prebuf = 4096;
attributes->minreq = 2048;
attributes->maxlength = (uint32_t) -1;
attributes->tlength = (uint32_t) -1;
attributes->prebuf = (uint32_t) -1;
attributes->minreq = (uint32_t) -1;
attributes->fragsize = 4096;
pa_stream_connect_record( s, NULL, attributes, PA_STREAM_ADJUST_LATENCY);
pa_stream_connect_record( s, NULL, attributes, (pa_stream_flags_t)(PA_STREAM_PEAK_DETECT|PA_STREAM_ADJUST_LATENCY));
} else if (_streamType == UPLOAD_STREAM) {
pa_stream_connect_upload (s , 1024);
} else {
......
......@@ -27,7 +27,6 @@
#include "audio/ringbuffer.h"
#include "audio/audioloop.h"
#include <cc++/thread.h>
/**
......@@ -135,7 +134,7 @@ class AudioStream {
* @param c The pulseaudio context
* @return pa_stream* The newly created audio stream
*/
pa_stream* createStream( pa_context* c );
pa_stream* createStream( pa_context* c);
/**
* Mandatory asynchronous callback on the audio stream state
......
......@@ -66,14 +66,8 @@ static void playback_underflow_callback (pa_stream* s, void* userdata UNUSED)
// _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));
bzero (out, framesPerBuffer*sizeof(SFLDataFormat));
pa_stream_write (s, out, framesPerBuffer*sizeof(SFLDataFormat), NULL, 0, PA_SEEK_RELATIVE);
// fill in audio buffer twice the prebuffering value to restart playback
pa_stream_trigger (s, NULL, NULL);
pa_xfree (out);
}
......@@ -503,19 +497,19 @@ void PulseLayer::writeToSpeaker (void)
urgentAvailBytes = _urgentRingBuffer.AvailForGet();
if (urgentAvailBytes > (framesPerBuffer*sizeof(SFLDataFormat))) {
if (urgentAvailBytes > (signed int)(framesPerBuffer*sizeof(SFLDataFormat))) {
_debug("urgentAvailBytes: %i\n", urgentAvailBytes);
toGet = (urgentAvailBytes < (int) (framesPerBuffer * sizeof (SFLDataFormat))) ? urgentAvailBytes : framesPerBuffer * sizeof (SFLDataFormat);
out = (SFLDataFormat*) pa_xmalloc (toGet * sizeof (SFLDataFormat));
_urgentRingBuffer.Get (out, toGet, 100);
pa_stream_write (playback->pulseStream(), out, toGet, NULL, 0, PA_SEEK_RELATIVE);
pa_stream_write (playback->pulseStream(), out, toGet, pa_xfree, 0, PA_SEEK_RELATIVE);
// Consume the regular one as well (same amount of bytes)
_mainBuffer.discard (toGet);
pa_xfree(out);
// pa_xfree(out);
} else {
......@@ -532,9 +526,9 @@ void PulseLayer::writeToSpeaker (void)
toGet = framesPerBuffer;
out = (SFLDataFormat*) pa_xmalloc (toGet * sizeof (SFLDataFormat));
tone->getNext (out, toGet , 100);
pa_stream_write (playback->pulseStream(), out, toGet * sizeof (SFLDataFormat), NULL, 0, PA_SEEK_RELATIVE);
pa_stream_write (playback->pulseStream(), out, toGet * sizeof (SFLDataFormat), pa_xfree, 0, PA_SEEK_RELATIVE);
pa_xfree (out);
// pa_xfree (out);
}
}
......@@ -544,12 +538,12 @@ void PulseLayer::writeToSpeaker (void)
{
toGet = framesPerBuffer;
toPlay = ( (int) (toGet * sizeof (SFLDataFormat)) > framesPerBuffer * sizeof (SFLDataFormat)) ? framesPerBuffer : toGet * sizeof (SFLDataFormat);
toPlay = ( (int) (toGet * sizeof (SFLDataFormat)) > (signed int)(framesPerBuffer * sizeof (SFLDataFormat))) ? framesPerBuffer : toGet * sizeof (SFLDataFormat);
out = (SFLDataFormat*) pa_xmalloc (toPlay);
file_tone->getNext(out, toPlay/sizeof(SFLDataFormat), 100);
pa_stream_write (playback->pulseStream(), out, toPlay, NULL, 0, PA_SEEK_RELATIVE);
pa_stream_write (playback->pulseStream(), out, toPlay, pa_xfree, 0, PA_SEEK_RELATIVE);
pa_xfree (out);
// pa_xfree (out);
}
} else {
......@@ -596,13 +590,13 @@ void PulseLayer::writeToSpeaker (void)
int nbSample = _converter->upsampleData((SFLDataFormat*)out, rsmpl_out, _mainBufferSampleRate, _audioSampleRate, nb_sample_down);
pa_stream_write (playback->pulseStream(), rsmpl_out, nbSample*sizeof(SFLDataFormat), NULL, 0, PA_SEEK_RELATIVE);
pa_stream_write (playback->pulseStream(), rsmpl_out, nbSample*sizeof(SFLDataFormat), pa_xfree, 0, PA_SEEK_RELATIVE);
pa_xfree (rsmpl_out);
// pa_xfree (rsmpl_out);
} else {
pa_stream_write (playback->pulseStream(), out, toGet, NULL, 0, PA_SEEK_RELATIVE);
pa_stream_write (playback->pulseStream(), out, toGet, pa_xfree, 0, PA_SEEK_RELATIVE);
}
......@@ -615,9 +609,9 @@ void PulseLayer::writeToSpeaker (void)
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_stream_write(playback->pulseStream(), zeros, framesPerBuffer*sizeof(SFLDataFormat), pa_xfree, 0, PA_SEEK_RELATIVE);
pa_xfree (zeros);
// pa_xfree (zeros);
}
......@@ -626,7 +620,7 @@ void PulseLayer::writeToSpeaker (void)
_urgentRingBuffer.Discard(toGet);
pa_xfree (out);
// 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