-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.c
98 lines (86 loc) · 1.68 KB
/
main.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
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
#include <stdio.h>
#include <stdlib.h>
#include "net.h"
#include "soundinit.h"
#include "soundtest.h"
#include "recordtest.h"
#include "fft.h"
#define RECORD_FRAMES_COUNT 100000
static int
test_tun (void)
{
struct hila_net *net;
net = hila_net_open ();
if (!net) {
printf ("cannot open tun.\n");
return -1;
}
printf ("tun opened!\n");
hila_net_close (net);
return 0;
}
static int
play_sound (void)
{
if (soundtest_play () < 0) {
printf ("could not play sound.\n");
return -1;
}
printf ("sound should have played.\n");
return 0;
}
static int
print_record_samples (void)
{
int err;
int i;
unsigned char record_frames[RECORD_FRAMES_COUNT];
err = 0 > recordtest_record (record_frames, RECORD_FRAMES_COUNT);
if (err) {
printf ("could not record sound.\n");
return -1;
}
for (i = 0; i < RECORD_FRAMES_COUNT; i++) {
printf ("%d\n", (int) record_frames[i]);
}
return 0;
}
static int
test_fft (void)
{
double *wsave;
double data[] = {1.0, 2.0, 3.0, 4.0, 5.0};
double *ret;
int i;
wsave = fft_initialize (5);
if (!wsave)
return -1;
ret = fft_compute (5, data, wsave);
if (!ret)
goto fail;
for (i = 0; i < 6; i++) {
printf ("%.10g\n", ret[i]);
}
free (ret);
free (wsave);
return 0;
fail:
free (wsave);
return -1;
}
static int
hila_main (void)
{
int err;
err = test_tun () < 0;
err = play_sound () < 0 || err;
err = print_record_samples () < 0 || err;
err = test_fft () < 0 || err;
return -err;
}
int
main (int argc, char **argv)
{
sound_init ();
return -hila_main ();
}