Voss Connection Detection
1
Detect a connector click using realtime code on Bela hardware
main.cpp
Go to the documentation of this file.
1
8
/*
9
* default_main.cpp
10
*
11
* Created on: Oct 24, 2014
12
* Author: parallels
13
*/
14
#include <unistd.h>
15
#include <iostream>
16
#include <cstdlib>
17
#include <stdio.h>
18
#include <libgen.h>
19
#include <signal.h>
20
#include <getopt.h>
21
#include <string.h>
22
#include "../include/Bela.h"
23
extern
char
*
PROGRAM_NAME
;
24
25
using namespace
std;
26
27
// Handle Ctrl-C by requesting that the audio rendering stop
28
void
interrupt_handler
(
int
var)
29
{
30
Bela_requestStop();
31
}
32
33
// Print usage information
34
void
usage
(
const
char
* processName)
35
{
36
cerr <<
"Usage: "
<< processName <<
" [options]"
<< endl;
37
38
Bela_usage();
39
40
cerr <<
" --help [-h]: Print this menu\n"
;
41
}
42
43
int
main
(
int
argc,
char
*argv[])
44
{
45
BelaInitSettings* settings = Bela_InitSettings_alloc();
// Standard audio settings
46
49
const
char
*
const
new_argv[] = {
50
argv[0],
51
"--disable-led"
,
52
"-p128"
,
53
"-C4"
,
54
"-B0"
,
55
"-H-6"
,
56
"-N1"
,
57
"-G1"
,
58
"-M0"
,
59
"-D4"
,
60
"-A0"
,
61
"--pga-gain-left=10"
,
62
"--pga-gain-right=10"
,
63
"-X0"
,
64
"--audio-expander-inputs"
,
65
"0,1,3"
,
66
"--stop-button-pin"
,
// Default action is to stop the program
67
"-1"
68
};
69
int
new_argc = 18;
70
71
72
struct
option customOptions[] =
73
{
74
{
"help"
, 0, NULL,
'h'
},
75
{NULL, 0, NULL, 0}
76
};
77
78
// Set default settings
79
Bela_defaultSettings(settings);
80
settings->setup =
setup
;
81
settings->render =
render
;
82
settings->cleanup =
cleanup
;
83
if
(argc > 0 && argv[0])
84
{
85
settings->projectName = strrchr((
char
*) new_argv[0],
'/'
) + 1;
86
}
87
88
while
(1) {
89
int
c = Bela_getopt_long(new_argc,(
char
*
const
*) new_argv,
"h"
, customOptions, settings);
90
if
(c < 0)
91
{
92
break
;
93
}
94
int
ret = -1;
95
switch
(c) {
96
case
'h'
:
97
usage
(basename(argv[0]));
98
ret = 0;
99
break
;
100
default
:
101
usage
(basename(argv[0]));
102
ret = 1;
103
break
;
104
}
105
if
(ret >= 0)
106
{
107
Bela_InitSettings_free(settings);
108
return
ret;
109
}
110
}
111
112
/* cerr << "Usedigital: " << settings->useDigital << endl; */
113
/* cerr << "numDigitalChannels: " << settings->numDigitalChannels << endl; */
114
115
// Initialise the PRU audio device
116
if
(Bela_initAudio(settings, 0) != 0) {
117
Bela_InitSettings_free(settings);
118
fprintf(stderr,
"Error: unable to initialise audio\n"
);
119
return
1;
120
}
121
Bela_InitSettings_free(settings);
122
123
// Start the audio device running
124
if
(Bela_startAudio()) {
125
fprintf(stderr,
"Error: unable to start real-time audio\n"
);
126
// Stop the audio device
127
Bela_stopAudio();
128
// Clean up any resources allocated for audio
129
Bela_cleanupAudio();
130
return
1;
131
}
132
133
// Set up interrupt handler to catch Control-C and SIGTERM
134
signal(SIGINT,
interrupt_handler
);
135
signal(SIGTERM,
interrupt_handler
);
136
137
// Run until told to stop
138
while
(!Bela_stopRequested()) {
139
usleep(100000);
140
}
141
142
// Stop the audio device
143
Bela_stopAudio();
144
145
// Clean up any resources allocated for audio
146
Bela_cleanupAudio();
147
148
// All done!
149
return
0;
150
}
interrupt_handler
void interrupt_handler(int var)
Definition:
main.cpp:28
render
void render(BelaContext *context, void *ConnDetect_opaque)
Definition:
render.cpp:51
usage
void usage(const char *processName)
Definition:
main.cpp:34
setup
bool setup(BelaContext *context, void *ConnDetect_ptr)
Definition:
render.cpp:18
cleanup
void cleanup(BelaContext *context, void *ConnDetect_ptr)
Definition:
render.cpp:78
PROGRAM_NAME
char * PROGRAM_NAME
default_main.cpp, the main code for starting up the Bela Audio setup. Important settings are set usin...
main
int main(int argc, char *argv[])
Definition:
main.cpp:43
src
main.cpp
Generated by
1.8.17