summaryrefslogtreecommitdiff
path: root/test/soundtest.cpp
blob: 195be523e30c6edcbc7337e577aa06ae48cf4d5b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
/*
 * Software Hands-Free with Crappy UI
 */

#include <stdio.h>
#include <assert.h>

#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>

#include <libhfp/soundio.h>
#include <libhfp/events-indep.h>

using namespace libhfp;

/* The global notifier factory */
static IndepEventDispatcher g_dispatcher;


class TimerCrap {
public:
	TimerNotifier *timer;

	void Tick(TimerNotifier *tnp, SoundIoManager *siop) {
		bool res;

		assert(tnp == timer);
		res = siop->GetMute();
		if (res) {
			printf("Disabling mute\n");
		} else {
			printf("Enabling mute\n");
		}
		res = siop->SetMute(!res);
		assert(res);
		tnp->Set(1000);
	}
};


int
main(int argc, char **argv)
{
	SoundIoFormat soundio_format;
	SoundIoManager *soundp;
	SoundIo *sndp;
	SoundIoFilter *fltp;
	SoundIoFltSpeex *fltsp;
	SoundIoSpeexProps sprops;
	bool res;
	bool do_file = false;
	TimerCrap tc;

	soundp = new SoundIoManager(&g_dispatcher);
	assert(soundp);

	res = soundp->SetDriver("ALSA", "plughw:0");
	assert(res);

	if (!do_file) {

		soundio_format.samplerate = 8000;
		soundio_format.sampletype = SIO_PCM_S16_LE;
		soundio_format.nchannels = 1;
		soundio_format.bytes_per_record = 2;
		soundio_format.packet_samps = 64;

		sndp = SoundIoCreateAlsa(&g_dispatcher,
					 "plughw:1", 0);

	} else {
		sndp = SoundIoCreateFileHandler(&g_dispatcher,
						"/vhome/samr7/R2D2.wav",
						 false);
	}
	assert(sndp);

	soundp->SetSecondary(sndp);
	soundp->SetPacketIntervalHint(5);
	soundp->SetMinBufferFillHint(100);

	sprops.noisereduce = true;
	sprops.echocancel_ms = 200;
	sprops.agc_level = 0;
	sprops.dereverb_level = 0.0;
	sprops.dereverb_decay = 0.0;

	fltsp = SoundIoFltCreateSpeex(&g_dispatcher);
	fltsp->Configure(sprops);
	//soundp->AddBottom(fltsp);

	fltp = SoundIoFltCreateDummy();
	//soundp->AddTop(fltp);

	res = sndp->SndOpen(!do_file, true);
	if (!res) {
		printf("Could not open secondary\n");
		return 1;
	}

	soundp->Start();

	tc.timer = g_dispatcher.NewTimer();
	tc.timer->Bind(&tc, &TimerCrap::Tick, Arg1, soundp);
	tc.timer->Set(1000);

	assert(soundp->IsStarted());

	g_dispatcher.Run();
	return 0;
}