-
Notifications
You must be signed in to change notification settings - Fork 62
/
Copy pathfm-radio.c
57 lines (46 loc) · 1.45 KB
/
fm-radio.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
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <luaradio.h>
const char *script_template =
"local frequency = %f\n"
"return radio.CompositeBlock():connect("
" radio.RtlSdrSource(frequency - 250e3, 1102500),"
" radio.TunerBlock(-250e3, 200e3, 5),"
" radio.WBFMMonoDemodulator(),"
" radio.DownsamplerBlock(5),"
" radio.PulseAudioSink(1)"
")";
int main(int argc, char *argv[]) {
luaradio_t *radio;
char script[512];
if (argc < 2) {
fprintf(stderr, "Usage: %s <FM station frequency>\n", argv[0]);
return -1;
}
/* Substitute station frequency in script template */
snprintf(script, sizeof(script), script_template, atof(argv[1]));
/* Create context */
if ((radio = luaradio_new()) == NULL) {
perror("Allocating memory");
return -1;
}
/* Load flow graph */
if (luaradio_load(radio, script) < 0) {
fprintf(stderr, "Error loading flow graph: %s\n", luaradio_strerror(radio));
return -1;
}
/* Start flow graph */
if (luaradio_start(radio) < 0) {
fprintf(stderr, "Error starting flow graph: %s\n", luaradio_strerror(radio));
return -1;
}
/* Wait until completion */
if (luaradio_wait(radio, NULL) < 0) {
fprintf(stderr, "Error waiting for flow graph: %s\n", luaradio_strerror(radio));
return -1;
}
/* Free context */
luaradio_free(radio);
return 0;
}