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

[#1966] Add timing info in pulseaudio layer

parent 83037f49
Branches
Tags
No related merge requests found
...@@ -188,12 +188,14 @@ void EchoCancel::putData(SFLDataFormat *inputData, int nbBytes) ...@@ -188,12 +188,14 @@ void EchoCancel::putData(SFLDataFormat *inputData, int nbBytes)
{ {
// std::cout << "putData nbBytes: " << nbBytes << std::endl; // std::cout << "putData nbBytes: " << nbBytes << std::endl;
/*
if(_spkrStoped) { if(_spkrStoped) {
_debug("EchoCancel: Flush data"); _debug("EchoCancel: Flush data");
_micData->flushAll(); _micData->flushAll();
_spkrData->flushAll(); _spkrData->flushAll();
_spkrStoped = false; _spkrStoped = false;
} }
*/
// Put data in speaker ring buffer // Put data in speaker ring buffer
_spkrData->Put(inputData, nbBytes); _spkrData->Put(inputData, nbBytes);
...@@ -204,10 +206,11 @@ void EchoCancel::process(SFLDataFormat *data, int nbBytes) {} ...@@ -204,10 +206,11 @@ void EchoCancel::process(SFLDataFormat *data, int nbBytes) {}
int EchoCancel::process(SFLDataFormat *inputData, SFLDataFormat *outputData, int nbBytes) int EchoCancel::process(SFLDataFormat *inputData, SFLDataFormat *outputData, int nbBytes)
{ {
/*
if(_spkrStoped) { if(_spkrStoped) {
return 0; return 0;
} }
*/
int byteSize = _smplPerFrame*sizeof(SFLDataFormat); int byteSize = _smplPerFrame*sizeof(SFLDataFormat);
...@@ -357,7 +360,7 @@ void EchoCancel::updateEchoCancel(SFLDataFormat *micData, SFLDataFormat *spkrDat ...@@ -357,7 +360,7 @@ void EchoCancel::updateEchoCancel(SFLDataFormat *micData, SFLDataFormat *spkrDat
if(_adaptCnt == _micAdaptSize) { if(_adaptCnt == _micAdaptSize) {
_debug("EchoCancel: Echo path adaptation completed"); _debug("EchoCancel: Echo path adaptation completed");
_adaptDone = true; _adaptDone = true;
_amplDelayIndexOut = getMaximumIndex(_correlationArray, _correlationSize); _amplDelayIndexOut = 0;// getMaximumIndex(_correlationArray, _correlationSize);
_debug("EchoCancel: Echo length %d", _amplDelayIndexOut); _debug("EchoCancel: Echo length %d", _amplDelayIndexOut);
spkrLearningData->write((const char *)_spkrAdaptArray, _spkrAdaptSize*sizeof(int)); spkrLearningData->write((const char *)_spkrAdaptArray, _spkrAdaptSize*sizeof(int));
micLearningData->write((const char *)_micAdaptArray, _micAdaptSize*sizeof(int)); micLearningData->write((const char *)_micAdaptArray, _micAdaptSize*sizeof(int));
......
...@@ -35,7 +35,7 @@ ...@@ -35,7 +35,7 @@
#define ECHO_LENGTH 50 #define ECHO_LENGTH 50
// Voice level threashold // Voice level threashold
#define MIN_SIG_LEVEL 100 #define MIN_SIG_LEVEL 1000
// Delay between mic and speaker // Delay between mic and speaker
#define DELAY_AMPLIFY 60 #define DELAY_AMPLIFY 60
......
...@@ -145,6 +145,13 @@ AudioStream::stream_state_callback (pa_stream* s, void* user_data) ...@@ -145,6 +145,13 @@ AudioStream::stream_state_callback (pa_stream* s, void* user_data)
case PA_STREAM_READY: case PA_STREAM_READY:
_info ("Audio: Stream successfully created, connected to %s", pa_stream_get_device_name (s)); _info ("Audio: Stream successfully created, connected to %s", pa_stream_get_device_name (s));
// pa_buffer_attr *buffattr = (pa_buffer_attr *)pa_xmalloc (sizeof(pa_buffer_attr));
_debug("Audio: maxlength %u", pa_stream_get_buffer_attr(s)->maxlength);
_debug("Audio: tlength %u", pa_stream_get_buffer_attr(s)->tlength);
_debug("Audio: prebug %u", pa_stream_get_buffer_attr(s)->prebuf);
_debug("Audio: minreq %u", pa_stream_get_buffer_attr(s)->minreq);
_debug("Audio: fragsize %u", pa_stream_get_buffer_attr(s)->fragsize);
// pa_xfree (buffattr);
break; break;
case PA_STREAM_UNCONNECTED: case PA_STREAM_UNCONNECTED:
...@@ -210,7 +217,9 @@ AudioStream::createStream (pa_context* c, std::string *deviceName) ...@@ -210,7 +217,9 @@ AudioStream::createStream (pa_context* c, std::string *deviceName)
} else if (_streamType == CAPTURE_STREAM) { } else if (_streamType == CAPTURE_STREAM) {
attributes->maxlength = (uint32_t) -1; attributes->maxlength = (uint32_t) -1;
attributes->fragsize = pa_usec_to_bytes (20 * PA_USEC_PER_MSEC, &_sample_spec); attributes->tlength = pa_usec_to_bytes (20 * PA_USEC_PER_MSEC, &_sample_spec);
attributes->prebuf = 0;
attributes->fragsize = pa_usec_to_bytes (100 * PA_USEC_PER_MSEC, &_sample_spec);
pa_threaded_mainloop_lock(_mainloop); pa_threaded_mainloop_lock(_mainloop);
......
...@@ -66,19 +66,16 @@ static void pa_success_callback(pa_context *c, int success, void *userdata) { ...@@ -66,19 +66,16 @@ static void pa_success_callback(pa_context *c, int success, void *userdata) {
static void latency_update_callback(pa_stream *p, void *userdata) { static void latency_update_callback(pa_stream *p, void *userdata) {
pa_usec_t r_usec; pa_usec_t r_usec;
pa_buffer_attr *buffattr;
pa_stream_get_latency (p, &r_usec, NULL); pa_stream_get_latency (p, &r_usec, NULL);
// buffattr = pa_stream_get_buffer_attr(p);
_debug("Audio: Stream letency update %0.0f ms for device %s", (float)r_usec/1000, pa_stream_get_device_name(p)); _debug("Audio: Stream letency update %0.0f ms for device %s", (float)r_usec/1000, pa_stream_get_device_name(p));
// _debug("Audio: maxlength %d", buffattr->maxlength); _debug("Audio: maxlength %u", pa_stream_get_buffer_attr(p)->maxlength);
// _debug("Audio: tlength %d", buffattr->tlength); _debug("Audio: tlength %u", pa_stream_get_buffer_attr(p)->tlength);
// _debug("Audio: prebug %d", buffattr->prebuf); _debug("Audio: prebuf %u", pa_stream_get_buffer_attr(p)->prebuf);
// _debug("Audio: minreq %d", buffattr->minreq); _debug("Audio: minreq %u", pa_stream_get_buffer_attr(p)->minreq);
// _debug("Audio: fragsize %d", buffattr->fragsize); _debug("Audio: fragsize %u", pa_stream_get_buffer_attr(p)->fragsize);
} }
...@@ -558,6 +555,7 @@ bool PulseLayer::createStreams (pa_context* c) ...@@ -558,6 +555,7 @@ bool PulseLayer::createStreams (pa_context* c)
pa_stream_set_latency_update_callback(record->pulseStream(), latency_update_callback, this); pa_stream_set_latency_update_callback(record->pulseStream(), latency_update_callback, this);
delete recordParam; delete recordParam;
/*
PulseLayerType * ringtoneParam = new PulseLayerType(); PulseLayerType * ringtoneParam = new PulseLayerType();
ringtoneParam->context = c; ringtoneParam->context = c;
ringtoneParam->type = RINGTONE_STREAM; ringtoneParam->type = RINGTONE_STREAM;
...@@ -575,7 +573,7 @@ bool PulseLayer::createStreams (pa_context* c) ...@@ -575,7 +573,7 @@ bool PulseLayer::createStreams (pa_context* c)
pa_stream_set_write_callback(ringtone->pulseStream(), ringtone_callback, this); pa_stream_set_write_callback(ringtone->pulseStream(), ringtone_callback, this);
pa_stream_set_moved_callback(ringtone->pulseStream(), stream_moved_callback, this); pa_stream_set_moved_callback(ringtone->pulseStream(), stream_moved_callback, this);
delete ringtoneParam; delete ringtoneParam;
*/
pa_threaded_mainloop_signal (m , 0); pa_threaded_mainloop_signal (m , 0);
flushMain(); flushMain();
...@@ -943,6 +941,7 @@ void PulseLayer::readFromMic (void) ...@@ -943,6 +941,7 @@ void PulseLayer::readFromMic (void)
// echo cancellation processing // echo cancellation processing
int sampleready = _echoCanceller->processAudio(rsmpl_out, echoCancelledMic, nbSample*sizeof(SFLDataFormat)); int sampleready = _echoCanceller->processAudio(rsmpl_out, echoCancelledMic, nbSample*sizeof(SFLDataFormat));
_debug("sampleready: %d", sampleready);
// getMainBuffer()->putData ( (void*) rsmpl_out, nbSample*sizeof (SFLDataFormat), 100); // getMainBuffer()->putData ( (void*) rsmpl_out, nbSample*sizeof (SFLDataFormat), 100);
if(sampleready) if(sampleready)
getMainBuffer()->putData ( echoCancelledMic, sampleready*sizeof (SFLDataFormat), 100); getMainBuffer()->putData ( echoCancelledMic, sampleready*sizeof (SFLDataFormat), 100);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment