Commit 141b4b69 authored by Alexandre Savard's avatar Alexandre Savard
Browse files

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

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