forked from maemo-leste/libcmtspeechdata
/
dsp2.c
67 lines (54 loc) · 1.11 KB
/
dsp2.c
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
/* -*- linux-c -*- */
struct test_ctx {
int source;
int sink;
};
#include "utils/dsp.c"
#include "utils/audio.h"
/*
* Mandatory variables.
*/
int audio_fd;
char silence[SSIZE];
int main(int argc, char *argv[])
{
int speed = 4000;
audio_fd = audio_open(speed);
{
#define SIZE 128
s16 buf[SIZE], buf2[SIZE];
int count = 0;
while (1) {
int len = read(audio_fd, buf, SIZE);
if (len < 0) {
printf("Error reading DSP: %m\n");
continue;
}
if (len != SIZE)
printf("Short read: %d\n", len);
if (!count) {
printf("priming\n");
write(audio_fd, silence, SSIZE);
}
count++;
to_mono(buf, buf2, SIZE);
to_stereo(buf2, buf, SIZE/2);
{
int delay;
float t;
if (ioctl(audio_fd, SNDCTL_DSP_GETODELAY, &delay) == -1)
delay = 0;
delay /= 4;/* Get number of 16 bit stereo samples */
t = (float) delay / (float) speed; /* Get delay in seconds */
t *= 1000.0;/* Convert delay to milliseconds */
if (len != write(audio_fd, buf, len)) {
printf("Short write\n");
}
#if 1
printf ("\rDelay=%5.3g msec", t);
fflush (stdout);
#endif
}
}
}
}