comparison examples/04-Audio/measure-noisefloor/main.cpp @ 468:85cf9c0da052 prerelease

merge
author Giulio Moro <giuliomoro@yahoo.it>
date Mon, 20 Jun 2016 17:08:02 +0100
parents 8fcfbfb32aa0
children
comparison
equal deleted inserted replaced
467:03a2cd5f151b 468:85cf9c0da052
1 /*
2 ____ _____ _ _
3 | __ )| ____| | / \
4 | _ \| _| | | / _ \
5 | |_) | |___| |___ / ___ \
6 |____/|_____|_____/_/ \_\
7
8 The platform for ultra-low latency audio and sensor processing
9
10 http://bela.io
11
12 A project of the Augmented Instruments Laboratory within the
13 Centre for Digital Music at Queen Mary University of London.
14 http://www.eecs.qmul.ac.uk/~andrewm
15
16 (c) 2016 Augmented Instruments Laboratory: Andrew McPherson,
17 Astrid Bin, Liam Donovan, Christian Heinrichs, Robert Jack,
18 Giulio Moro, Laurel Pardue, Victor Zappi. All rights reserved.
19
20 The Bela software is distributed under the GNU Lesser General Public License
21 (LGPL 3.0), available here: https://www.gnu.org/licenses/lgpl-3.0.txt
22 */
23
24 #include <iostream>
25 #include <cstdlib>
26 #include <libgen.h>
27 #include <signal.h>
28 #include <getopt.h>
29 #include <Bela.h>
30
31 extern int gBufferSize;
32
33 using namespace std;
34
35 // Handle Ctrl-C by requesting that the audio rendering stop
36 void interrupt_handler(int var)
37 {
38 gShouldStop = true;
39 }
40
41 // Print usage information
42 void usage(const char * processName)
43 {
44 cerr << "Usage: " << processName << " [options]" << endl;
45
46 Bela_usage();
47
48 cerr << " --buffer-size [-b] size Set the analysis buffer size\n";
49 cerr << " --help [-h]: Print this menu\n";
50 }
51
52 int main(int argc, char *argv[])
53 {
54 BelaInitSettings settings; // Standard audio settings
55
56 struct option customOptions[] =
57 {
58 {"help", 0, NULL, 'h'},
59 {"buffer-size", 1, NULL, 'b'},
60 {NULL, 0, NULL, 0}
61 };
62
63 // Set default settings
64 Bela_defaultSettings(&settings);
65
66 // By default use a longer period size because latency is not an issue
67 settings.periodSize = 32;
68
69 // Parse command-line arguments
70 while (1) {
71 int c;
72 if ((c = Bela_getopt_long(argc, argv, "hb:", customOptions, &settings)) < 0)
73 break;
74 switch (c) {
75 case 'b':
76 gBufferSize = atoi(optarg);
77 break;
78 case 'h':
79 usage(basename(argv[0]));
80 exit(0);
81 case '?':
82 default:
83 usage(basename(argv[0]));
84 exit(1);
85 }
86 }
87
88 if(gBufferSize < settings.periodSize)
89 gBufferSize = settings.periodSize;
90
91 // Initialise the PRU audio device
92 if(Bela_initAudio(&settings, 0) != 0) {
93 cout << "Error: unable to initialise audio" << endl;
94 return -1;
95 }
96
97 // Start the audio device running
98 if(Bela_startAudio()) {
99 cout << "Error: unable to start real-time audio" << endl;
100 return -1;
101 }
102
103 // Set up interrupt handler to catch Control-C and SIGTERM
104 signal(SIGINT, interrupt_handler);
105 signal(SIGTERM, interrupt_handler);
106
107 // Run until told to stop
108 while(!gShouldStop) {
109 usleep(100000);
110 }
111
112 // Stop the audio device
113 Bela_stopAudio();
114
115 // Clean up any resources allocated for audio
116 Bela_cleanupAudio();
117
118 // All done!
119 return 0;
120 }