echosuppress.cpp 1.13 KB
Newer Older
1
2
3
4
5
6
7
/*
 * EchoSuppress.cpp
 *
 *  Created on: 2011-05-18
 *      Author: asavard
 */

8
9
10
#include <cassert>
#include <stdexcept>

11
#include "echosuppress.h"
12
#include "pj/pool.h"
13
14
#include "pj/os.h"

15
#define SAMPLES_PER_FRAME 160
16

17
EchoSuppress::EchoSuppress(pj_pool_t *pool)
18
{
19
20
    if (pjmedia_echo_create(pool, 8000, SAMPLES_PER_FRAME, 250, 0, PJMEDIA_ECHO_SIMPLE | PJMEDIA_ECHO_NO_LOCK, &echoState) != PJ_SUCCESS)
    	throw std::runtime_error("EchoCancel: Could not create echo canceller");
21
22
23
24
}

EchoSuppress::~EchoSuppress()
{
25
	pjmedia_echo_destroy(echoState);
26
27
}

28
void EchoSuppress::putData (SFLDataFormat *inputData, int samples)
29
{
30
31
	assert(samples == SAMPLES_PER_FRAME);
	assert(sizeof(SFLDataFormat) == sizeof(pj_int16_t));
32
	if (pjmedia_echo_playback(echoState, reinterpret_cast<pj_int16_t *>(inputData)) != PJ_SUCCESS)
33
        _warn("EchoCancel: Problem while putting input data");
34
35
}

36
void EchoSuppress::getData(SFLDataFormat *outputData)
37
{
38
	assert(sizeof(SFLDataFormat) == sizeof(pj_int16_t));
39
    if (pjmedia_echo_capture(echoState, reinterpret_cast<pj_int16_t *>(outputData), 0) != PJ_SUCCESS)
40
        _warn("EchoCancel: Problem while getting output data");
41
}