Mercurial > hg > beaglert
comparison examples/04-Audio/FFT-audio-in/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 ____ _____ _ _ | |
| 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 using namespace std; | |
| 32 | |
| 33 // Handle Ctrl-C by requesting that the audio rendering stop | |
| 34 void interrupt_handler(int var) | |
| 35 { | |
| 36 gShouldStop = true; | |
| 37 } | |
| 38 | |
| 39 // Print usage information | |
| 40 void usage(const char * processName) | |
| 41 { | |
| 42 cerr << "Usage: " << processName << " [options]" << endl; | |
| 43 | |
| 44 Bela_usage(); | |
| 45 | |
| 46 cerr << " --fftsize [-s] size: Set the fSize of the FFT, in samples\n"; | |
| 47 cerr << " --help [-h]: Print this menu\n"; | |
| 48 } | |
| 49 | |
| 50 int main(int argc, char *argv[]) | |
| 51 { | |
| 52 BelaInitSettings settings; // Standard audio settings | |
| 53 int fftSize = 64; // Size of the FFT, in samples | |
| 54 | |
| 55 struct option customOptions[] = | |
| 56 { | |
| 57 {"help", 0, NULL, 'h'}, | |
| 58 {"fftsize", 1, NULL, 's'}, | |
| 59 {NULL, 0, NULL, 0} | |
| 60 }; | |
| 61 | |
| 62 // Set default settings | |
| 63 Bela_defaultSettings(&settings); | |
| 64 | |
| 65 // settings.useAnalog = 0; // No matrix usage by default | |
| 66 | |
| 67 // Parse command-line arguments | |
| 68 while (1) { | |
| 69 int c; | |
| 70 if ((c = Bela_getopt_long(argc, argv, "hs:", customOptions, &settings)) < 0) | |
| 71 break; | |
| 72 switch (c) { | |
| 73 case 'h': | |
| 74 usage(basename(argv[0])); | |
| 75 exit(0); | |
| 76 case 's': | |
| 77 fftSize = atof(optarg); | |
| 78 break; | |
| 79 case '?': | |
| 80 default: | |
| 81 usage(basename(argv[0])); | |
| 82 exit(1); | |
| 83 } | |
| 84 } | |
| 85 | |
| 86 // Initialise the PRU audio device | |
| 87 if(Bela_initAudio(&settings, &fftSize) != 0) { | |
| 88 cout << "Error: unable to initialise audio" << endl; | |
| 89 return -1; | |
| 90 } | |
| 91 | |
| 92 // Start the audio device running | |
| 93 if(Bela_startAudio()) { | |
| 94 cout << "Error: unable to start real-time audio" << endl; | |
| 95 return -1; | |
| 96 } | |
| 97 | |
| 98 // Set up interrupt handler to catch Control-C and SIGTERM | |
| 99 signal(SIGINT, interrupt_handler); | |
| 100 signal(SIGTERM, interrupt_handler); | |
| 101 | |
| 102 // Run until told to stop | |
| 103 while(!gShouldStop) { | |
| 104 usleep(100000); | |
| 105 } | |
| 106 | |
| 107 // Stop the audio device | |
| 108 Bela_stopAudio(); | |
| 109 | |
| 110 // Clean up any resources allocated for audio | |
| 111 Bela_cleanupAudio(); | |
| 112 | |
| 113 // All done! | |
| 114 return 0; | |
| 115 } | |
| 116 | 
