Mercurial > hg > beaglert
annotate 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 |
rev | line source |
---|---|
robert@464 | 1 /* |
robert@464 | 2 * default_main.cpp |
robert@464 | 3 * |
robert@464 | 4 * Created on: Oct 24, 2014 |
robert@464 | 5 * Author: parallels |
robert@464 | 6 */ |
robert@464 | 7 #include <unistd.h> |
robert@464 | 8 #include <iostream> |
robert@464 | 9 #include <cstdlib> |
robert@464 | 10 #include <libgen.h> |
robert@464 | 11 #include <signal.h> |
robert@464 | 12 #include <getopt.h> |
robert@464 | 13 #include "../include/Bela.h" |
robert@464 | 14 |
robert@464 | 15 using namespace std; |
robert@464 | 16 |
robert@464 | 17 // Handle Ctrl-C by requesting that the audio rendering stop |
robert@464 | 18 void interrupt_handler(int var) |
robert@464 | 19 { |
robert@464 | 20 gShouldStop = true; |
robert@464 | 21 } |
robert@464 | 22 |
robert@464 | 23 // Print usage information |
robert@464 | 24 void usage(const char * processName) |
robert@464 | 25 { |
robert@464 | 26 cerr << "Usage: " << processName << " [options]" << endl; |
robert@464 | 27 |
robert@464 | 28 Bela_usage(); |
robert@464 | 29 |
robert@464 | 30 cerr << " --help [-h]: Print this menu\n"; |
robert@464 | 31 } |
robert@464 | 32 |
robert@464 | 33 int main(int argc, char *argv[]) |
robert@464 | 34 { |
robert@464 | 35 BelaInitSettings settings; // Standard audio settings |
robert@464 | 36 |
robert@464 | 37 struct option customOptions[] = |
robert@464 | 38 { |
robert@464 | 39 {"help", 0, NULL, 'h'}, |
robert@464 | 40 {NULL, 0, NULL, 0} |
robert@464 | 41 }; |
robert@464 | 42 |
robert@464 | 43 // Set default settings |
robert@464 | 44 Bela_defaultSettings(&settings); |
robert@464 | 45 |
robert@464 | 46 // Parse command-line arguments |
robert@464 | 47 while (1) { |
robert@464 | 48 int c; |
robert@464 | 49 if ((c = Bela_getopt_long(argc, argv, "h", customOptions, &settings)) < 0) |
robert@464 | 50 break; |
robert@464 | 51 switch (c) { |
robert@464 | 52 case 'h': |
robert@464 | 53 usage(basename(argv[0])); |
robert@464 | 54 exit(0); |
robert@464 | 55 case '?': |
robert@464 | 56 default: |
robert@464 | 57 usage(basename(argv[0])); |
robert@464 | 58 exit(1); |
robert@464 | 59 } |
robert@464 | 60 } |
robert@464 | 61 |
robert@464 | 62 // Initialise the PRU audio device |
robert@464 | 63 if(Bela_initAudio(&settings, 0) != 0) { |
robert@464 | 64 cout << "Error: unable to initialise audio" << endl; |
robert@464 | 65 return -1; |
robert@464 | 66 } |
robert@464 | 67 |
robert@464 | 68 // Start the audio device running |
robert@464 | 69 if(Bela_startAudio()) { |
robert@464 | 70 cout << "Error: unable to start real-time audio" << endl; |
robert@464 | 71 return -1; |
robert@464 | 72 } |
robert@464 | 73 |
robert@464 | 74 // Set up interrupt handler to catch Control-C and SIGTERM |
robert@464 | 75 signal(SIGINT, interrupt_handler); |
robert@464 | 76 signal(SIGTERM, interrupt_handler); |
robert@464 | 77 |
robert@464 | 78 // Run until told to stop |
robert@464 | 79 while(!gShouldStop) { |
robert@464 | 80 usleep(100000); |
robert@464 | 81 } |
robert@464 | 82 |
robert@464 | 83 // Stop the audio device |
robert@464 | 84 Bela_stopAudio(); |
robert@464 | 85 |
robert@464 | 86 // Clean up any resources allocated for audio |
robert@464 | 87 Bela_cleanupAudio(); |
robert@464 | 88 |
robert@464 | 89 // All done! |
robert@464 | 90 return 0; |
robert@464 | 91 } |