diff --git a/daemon/src/audio/speexechocancel.cpp b/daemon/src/audio/speexechocancel.cpp index c5daacddafa48bead5b0b74c6b9af7e380eef5f3..9c61182692ece610c9e4a3952eff24510e3265d7 100644 --- a/daemon/src/audio/speexechocancel.cpp +++ b/daemon/src/audio/speexechocancel.cpp @@ -40,8 +40,8 @@ SpeexEchoCancel::SpeexEchoCancel() : echoTailLength_(Manager::instance().getEchoCancelTailLength() * SPEEX_SAMPLE_RATE / 1000), echoState_(speex_echo_state_init(EC_FRAME_SIZE, echoTailLength_)), preState_(speex_preprocess_state_init(EC_FRAME_SIZE, SPEEX_SAMPLE_RATE)), - micData_(new RingBuffer(RINGBUFFER_SIZE)), - spkrData_(new RingBuffer(RINGBUFFER_SIZE)), + micData_(RINGBUFFER_SIZE), + spkrData_(RINGBUFFER_SIZE), spkrStopped_(true) { DEBUG("EchoCancel: Initializing echo canceller with delay: %d, filter length: %d, frame size: %d and samplerate %d", @@ -51,27 +51,25 @@ SpeexEchoCancel::SpeexEchoCancel() : speex_echo_ctl(echoState_, SPEEX_ECHO_SET_SAMPLING_RATE, &rate); speex_preprocess_ctl(preState_, SPEEX_PREPROCESS_SET_ECHO_STATE, echoState_); - micData_->createReadPointer(); - spkrData_->createReadPointer(); + micData_.createReadPointer(); + spkrData_.createReadPointer(); } SpeexEchoCancel::~SpeexEchoCancel() { speex_echo_state_destroy(echoState_); speex_preprocess_state_destroy(preState_); - delete spkrData_; - delete micData_; } void SpeexEchoCancel::putData(SFLDataFormat *inputData, int samples) { if (spkrStopped_) { - micData_->flushAll(); - spkrData_->flushAll(); + micData_.flushAll(); + spkrData_.flushAll(); spkrStopped_ = false; } - spkrData_->Put(inputData, samples * sizeof(SFLDataFormat)); + spkrData_.Put(inputData, samples * sizeof(SFLDataFormat)); } int SpeexEchoCancel::process(SFLDataFormat *inputData, SFLDataFormat *outputData, int samples) @@ -87,19 +85,19 @@ int SpeexEchoCancel::process(SFLDataFormat *inputData, SFLDataFormat *outputData memset(tmpOut_, 0, sizeof(tmpOut_)); // Put mic data in ringbuffer - micData_->Put(inputData, samples * sizeof(SFLDataFormat)); + micData_.Put(inputData, samples * sizeof(SFLDataFormat)); // Store data for synchronization - int spkrAvail = spkrData_->AvailForGet(); - int micAvail = micData_->AvailForGet(); + int spkrAvail = spkrData_.AvailForGet(); + int micAvail = micData_.AvailForGet(); if (spkrAvail < (echoDelay_+byteSize) || micAvail < byteSize) { - micData_->Discard(byteSize); + micData_.Discard(byteSize); return 0; } - spkrData_->Get(tmpSpkr_, byteSize); - micData_->Get(tmpMic_, byteSize); + spkrData_.Get(tmpSpkr_, byteSize); + micData_.Get(tmpMic_, byteSize); for (int i = 0; i < EC_FRAME_SIZE; i++) { int32_t tmp = tmpSpkr_[i] * 3; @@ -120,8 +118,8 @@ int SpeexEchoCancel::process(SFLDataFormat *inputData, SFLDataFormat *outputData memcpy(outputData, tmpOut_, byteSize); - spkrAvail = spkrData_->AvailForGet(); - micAvail = micData_->AvailForGet(); + spkrAvail = spkrData_.AvailForGet(); + micAvail = micData_.AvailForGet(); return EC_FRAME_SIZE; } diff --git a/daemon/src/audio/speexechocancel.h b/daemon/src/audio/speexechocancel.h index 48d945384f90322897968ee7e89f166f4a09da15..3f0fbb35ec8d4ce1007f7876bcdaec9e11fcf7e4 100644 --- a/daemon/src/audio/speexechocancel.h +++ b/daemon/src/audio/speexechocancel.h @@ -22,8 +22,8 @@ #include "global.h" #include "noncopyable.h" +#include "ringbuffer.h" -class RingBuffer; class SpeexEchoState_; typedef SpeexEchoState_ SpeexEchoState; class SpeexPreprocessState_; @@ -57,8 +57,8 @@ class SpeexEchoCancel { SpeexEchoState *echoState_; SpeexPreprocessState *preState_; - RingBuffer *micData_; - RingBuffer *spkrData_; + RingBuffer micData_; + RingBuffer spkrData_; bool spkrStopped_;