Mercurial > hg > beaglert
comparison examples/audio_in_FFT/main.cpp @ 300:dbeed520b014 prerelease
Renamed projects to examples
author | Giulio Moro <giuliomoro@yahoo.it> |
---|---|
date | Fri, 27 May 2016 13:58:20 +0100 |
parents | projects/audio_in_FFT/main.cpp@301dceb39ec8 |
children | e4392164b458 |
comparison
equal
deleted
inserted
replaced
297:a3d83ebdf49b | 300:dbeed520b014 |
---|---|
1 /* | |
2 * main.cpp | |
3 * | |
4 * Created on: Oct 24, 2014 | |
5 * Author: parallels | |
6 */ | |
7 | |
8 #include <iostream> | |
9 #include <cstdlib> | |
10 #include <libgen.h> | |
11 #include <signal.h> | |
12 #include <getopt.h> | |
13 #include <BeagleRT.h> | |
14 | |
15 using namespace std; | |
16 | |
17 // Handle Ctrl-C by requesting that the audio rendering stop | |
18 void interrupt_handler(int var) | |
19 { | |
20 gShouldStop = true; | |
21 } | |
22 | |
23 // Print usage information | |
24 void usage(const char * processName) | |
25 { | |
26 cerr << "Usage: " << processName << " [options]" << endl; | |
27 | |
28 BeagleRT_usage(); | |
29 | |
30 cerr << " --fftsize [-s] size: Set the fSize of the FFT, in samples\n"; | |
31 cerr << " --help [-h]: Print this menu\n"; | |
32 } | |
33 | |
34 int main(int argc, char *argv[]) | |
35 { | |
36 BeagleRTInitSettings settings; // Standard audio settings | |
37 int fftSize = 64; // Size of the FFT, in samples | |
38 | |
39 struct option customOptions[] = | |
40 { | |
41 {"help", 0, NULL, 'h'}, | |
42 {"fftsize", 1, NULL, 's'}, | |
43 {NULL, 0, NULL, 0} | |
44 }; | |
45 | |
46 // Set default settings | |
47 BeagleRT_defaultSettings(&settings); | |
48 | |
49 // settings.useAnalog = 0; // No matrix usage by default | |
50 | |
51 // Parse command-line arguments | |
52 while (1) { | |
53 int c; | |
54 if ((c = BeagleRT_getopt_long(argc, argv, "hs:", customOptions, &settings)) < 0) | |
55 break; | |
56 switch (c) { | |
57 case 'h': | |
58 usage(basename(argv[0])); | |
59 exit(0); | |
60 case 's': | |
61 fftSize = atof(optarg); | |
62 break; | |
63 case '?': | |
64 default: | |
65 usage(basename(argv[0])); | |
66 exit(1); | |
67 } | |
68 } | |
69 | |
70 // Initialise the PRU audio device | |
71 if(BeagleRT_initAudio(&settings, &fftSize) != 0) { | |
72 cout << "Error: unable to initialise audio" << endl; | |
73 return -1; | |
74 } | |
75 | |
76 // Start the audio device running | |
77 if(BeagleRT_startAudio()) { | |
78 cout << "Error: unable to start real-time audio" << endl; | |
79 return -1; | |
80 } | |
81 | |
82 // Set up interrupt handler to catch Control-C and SIGTERM | |
83 signal(SIGINT, interrupt_handler); | |
84 signal(SIGTERM, interrupt_handler); | |
85 | |
86 // Run until told to stop | |
87 while(!gShouldStop) { | |
88 usleep(100000); | |
89 } | |
90 | |
91 // Stop the audio device | |
92 BeagleRT_stopAudio(); | |
93 | |
94 // Clean up any resources allocated for audio | |
95 BeagleRT_cleanupAudio(); | |
96 | |
97 // All done! | |
98 return 0; | |
99 } | |
100 |