Mercurial > hg > beaglert
comparison examples/08-PureData/basic_libpd/main.cpp @ 464:8fcfbfb32aa0 prerelease
Examples reorder with subdirectories. Added header to each project. Moved Doxygen to bottom of render.cpp.
author | Robert Jack <robert.h.jack@gmail.com> |
---|---|
date | Mon, 20 Jun 2016 16:20:38 +0100 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
463:c47709e8b5c9 | 464:8fcfbfb32aa0 |
---|---|
1 /* | |
2 * default_main.cpp | |
3 * | |
4 * Created on: Oct 24, 2014 | |
5 * Author: parallels | |
6 */ | |
7 #include <unistd.h> | |
8 #include <iostream> | |
9 #include <cstdlib> | |
10 #include <libgen.h> | |
11 #include <signal.h> | |
12 #include <getopt.h> | |
13 #include "../include/Bela.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 Bela_usage(); | |
29 | |
30 cerr << " --help [-h]: Print this menu\n"; | |
31 } | |
32 | |
33 int main(int argc, char *argv[]) | |
34 { | |
35 BelaInitSettings settings; // Standard audio settings | |
36 | |
37 struct option customOptions[] = | |
38 { | |
39 {"help", 0, NULL, 'h'}, | |
40 {NULL, 0, NULL, 0} | |
41 }; | |
42 | |
43 // Set default settings | |
44 Bela_defaultSettings(&settings); | |
45 | |
46 // Parse command-line arguments | |
47 while (1) { | |
48 int c; | |
49 if ((c = Bela_getopt_long(argc, argv, "h", customOptions, &settings)) < 0) | |
50 break; | |
51 switch (c) { | |
52 case 'h': | |
53 usage(basename(argv[0])); | |
54 exit(0); | |
55 case '?': | |
56 default: | |
57 usage(basename(argv[0])); | |
58 exit(1); | |
59 } | |
60 } | |
61 | |
62 // Initialise the PRU audio device | |
63 if(Bela_initAudio(&settings, 0) != 0) { | |
64 cout << "Error: unable to initialise audio" << endl; | |
65 return -1; | |
66 } | |
67 | |
68 // Start the audio device running | |
69 if(Bela_startAudio()) { | |
70 cout << "Error: unable to start real-time audio" << endl; | |
71 return -1; | |
72 } | |
73 | |
74 // Set up interrupt handler to catch Control-C and SIGTERM | |
75 signal(SIGINT, interrupt_handler); | |
76 signal(SIGTERM, interrupt_handler); | |
77 | |
78 // Run until told to stop | |
79 while(!gShouldStop) { | |
80 usleep(100000); | |
81 } | |
82 | |
83 // Stop the audio device | |
84 Bela_stopAudio(); | |
85 | |
86 // Clean up any resources allocated for audio | |
87 Bela_cleanupAudio(); | |
88 | |
89 // All done! | |
90 return 0; | |
91 } |