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

[#1966] Add getData method to algorithm abstract interface and echocancel

parent 9d5dd613
No related branches found
No related tags found
No related merge requests found
...@@ -38,6 +38,11 @@ class Algorithm { ...@@ -38,6 +38,11 @@ class Algorithm {
*/ */
virtual void putData(SFLDataFormat *inputData, int nbBytes) = 0; virtual void putData(SFLDataFormat *inputData, int nbBytes) = 0;
/**
*
*/
virtual int getData(SFLDataFormat *outputData) = 0;
/** /**
* Class implementing this interface must define this function * Class implementing this interface must define this function
* for audio processing that require synchronization between spkrdata and * for audio processing that require synchronization between spkrdata and
......
...@@ -33,6 +33,14 @@ void AudioProcessing::resetAlgorithm(void) ...@@ -33,6 +33,14 @@ void AudioProcessing::resetAlgorithm(void)
_algorithm->reset(); _algorithm->reset();
} }
int AudioProcessing::getData(SFLDataFormat *outputData)
{
if(_algorithm)
return _algorithm->getData(outputData);
else
return 0;
}
void AudioProcessing::putData(SFLDataFormat *inputData, int nbBytes) void AudioProcessing::putData(SFLDataFormat *inputData, int nbBytes)
{ {
if(_algorithm) if(_algorithm)
......
...@@ -54,6 +54,11 @@ public: ...@@ -54,6 +54,11 @@ public:
*/ */
void putData(SFLDataFormat *inputData, int nbBytes); void putData(SFLDataFormat *inputData, int nbBytes);
/**
* Get data from internal buffer
*/
int getData(SFLDataFormat *outputData);
/** /**
* Process some audio data * Process some audio data
*/ */
......
...@@ -58,6 +58,8 @@ void DcBlocker::reset() ...@@ -58,6 +58,8 @@ void DcBlocker::reset()
void DcBlocker::putData(SFLDataFormat *inputData, int nbBytes) {} void DcBlocker::putData(SFLDataFormat *inputData, int nbBytes) {}
int DcBlocker::getData(SFLDataFormat *outputData) { return 0; }
void DcBlocker::process (SFLDataFormat *data, int nbBytes) void DcBlocker::process (SFLDataFormat *data, int nbBytes)
{ {
// y(n) = x(n) - x(n-1) + R y(n-1) , R = 0.9999 // y(n) = x(n) - x(n-1) + R y(n-1) , R = 0.9999
......
...@@ -86,6 +86,11 @@ public: ...@@ -86,6 +86,11 @@ public:
*/ */
virtual void putData(SFLDataFormat *inputData, int nbBytes); virtual void putData(SFLDataFormat *inputData, int nbBytes);
/**
* Unused
*/
virtual int getData(SFLDataFormat *outputData);
/** /**
* Perform dc blocking given the input data * Perform dc blocking given the input data
*/ */
......
...@@ -42,7 +42,8 @@ EchoCancel::EchoCancel(int smplRate, int frameLength) : _samplingRate(smplRate), ...@@ -42,7 +42,8 @@ EchoCancel::EchoCancel(int smplRate, int frameLength) : _samplingRate(smplRate),
_micAdaptCnt(0), _micAdaptCnt(0),
_spkrAdaptSize(SPKR_ADAPT_SIZE), _spkrAdaptSize(SPKR_ADAPT_SIZE),
_micAdaptSize(MIC_ADAPT_SIZE), _micAdaptSize(MIC_ADAPT_SIZE),
_correlationSize(0) _correlationSize(0),
_processedByte(0)
{ {
_debug("EchoCancel: Instantiate echo canceller"); _debug("EchoCancel: Instantiate echo canceller");
...@@ -57,9 +58,11 @@ EchoCancel::EchoCancel(int smplRate, int frameLength) : _samplingRate(smplRate), ...@@ -57,9 +58,11 @@ EchoCancel::EchoCancel(int smplRate, int frameLength) : _samplingRate(smplRate),
_micData = new RingBuffer(50000); _micData = new RingBuffer(50000);
_spkrData = new RingBuffer(50000); _spkrData = new RingBuffer(50000);
_spkrDataOut = new RingBuffer(50000);
_micData->createReadPointer(); _micData->createReadPointer();
_spkrData->createReadPointer(); _spkrData->createReadPointer();
_spkrDataOut->createReadPointer();
// variable used to sync mic and spkr // variable used to sync mic and spkr
_spkrStoped = true; _spkrStoped = true;
...@@ -158,6 +161,7 @@ void EchoCancel::reset() ...@@ -158,6 +161,7 @@ void EchoCancel::reset()
_micData->flushAll(); _micData->flushAll();
_spkrData->flushAll(); _spkrData->flushAll();
_spkrDataOut->flushAll();
// SFLDataFormat delay[960]; // SFLDataFormat delay[960];
// memset(delay, 0, sizeof(SFLDataFormat)); // memset(delay, 0, sizeof(SFLDataFormat));
...@@ -180,7 +184,6 @@ void EchoCancel::reset() ...@@ -180,7 +184,6 @@ void EchoCancel::reset()
f=.0; f=.0;
speex_preprocess_ctl(_noiseState, SPEEX_PREPROCESS_SET_DEREVERB_LEVEL, &f); speex_preprocess_ctl(_noiseState, SPEEX_PREPROCESS_SET_DEREVERB_LEVEL, &f);
_spkrStoped = true; _spkrStoped = true;
} }
...@@ -199,9 +202,24 @@ void EchoCancel::putData(SFLDataFormat *inputData, int nbBytes) ...@@ -199,9 +202,24 @@ void EchoCancel::putData(SFLDataFormat *inputData, int nbBytes)
// Put data in speaker ring buffer // Put data in speaker ring buffer
_spkrData->Put(inputData, nbBytes); _spkrData->Put(inputData, nbBytes);
_spkrDataOut->Put(inputData, nbBytes);
} }
int EchoCancel::getData(SFLDataFormat *outputData)
{
// int availForGet = _spkrData->AvailForGet();
int copied = 0;
if(_processedByte > 0) {
copied = _spkrDataOut->Get(outputData, _processedByte);
_processedByte = 0;
}
return copied;
}
void EchoCancel::process(SFLDataFormat *data, int nbBytes) {} 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)
...@@ -226,7 +244,7 @@ int EchoCancel::process(SFLDataFormat *inputData, SFLDataFormat *outputData, int ...@@ -226,7 +244,7 @@ int EchoCancel::process(SFLDataFormat *inputData, SFLDataFormat *outputData, int
int spkrAvail = _spkrData->AvailForGet(); int spkrAvail = _spkrData->AvailForGet();
int micAvail = _micData->AvailForGet(); int micAvail = _micData->AvailForGet();
_debug("EchoCancel: speaker avail %d, mic avail %d", spkrAvail, micAvail); _debug("EchoCancel: speaker avail %d, mic avail %d, processed: %d", spkrAvail/320, micAvail/320, _processedByte);
// Init number of frame processed // Init number of frame processed
int nbFrame = 0; int nbFrame = 0;
...@@ -246,6 +264,9 @@ int EchoCancel::process(SFLDataFormat *inputData, SFLDataFormat *outputData, int ...@@ -246,6 +264,9 @@ int EchoCancel::process(SFLDataFormat *inputData, SFLDataFormat *outputData, int
bcopy(_tmpOut, outputData+(nbFrame*_smplPerFrame), byteSize); bcopy(_tmpOut, outputData+(nbFrame*_smplPerFrame), byteSize);
// used to sync with speaker
_processedByte += byteSize;
// echoFile->write ((const char *)_tmpOut, byteSize); // echoFile->write ((const char *)_tmpOut, byteSize);
spkrAvail = _spkrData->AvailForGet(); spkrAvail = _spkrData->AvailForGet();
......
...@@ -72,6 +72,11 @@ class EchoCancel : public Algorithm { ...@@ -72,6 +72,11 @@ class EchoCancel : public Algorithm {
*/ */
virtual void putData(SFLDataFormat *inputData, int nbBytes); virtual void putData(SFLDataFormat *inputData, int nbBytes);
/**
* Get data ready to be played by speakers
*/
virtual int getData(SFLDataFormat *outputData);
/** /**
* Unused * Unused
*/ */
...@@ -152,6 +157,8 @@ class EchoCancel : public Algorithm { ...@@ -152,6 +157,8 @@ class EchoCancel : public Algorithm {
*/ */
RingBuffer *_spkrData; RingBuffer *_spkrData;
RingBuffer *_spkrDataOut;
/** /**
* Boolean value * Boolean value
*/ */
...@@ -274,6 +281,8 @@ class EchoCancel : public Algorithm { ...@@ -274,6 +281,8 @@ class EchoCancel : public Algorithm {
int _correlationArray[BUFF_SIZE]; int _correlationArray[BUFF_SIZE];
int _processedByte;
/* /*
ofstream *micFile; ofstream *micFile;
ofstream *spkrFile; ofstream *spkrFile;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment