robert@464: /* robert@464: ____ _____ _ _ robert@464: | __ )| ____| | / \ robert@464: | _ \| _| | | / _ \ robert@464: | |_) | |___| |___ / ___ \ robert@464: |____/|_____|_____/_/ \_\ robert@464: robert@464: The platform for ultra-low latency audio and sensor processing robert@464: robert@464: http://bela.io robert@464: robert@464: A project of the Augmented Instruments Laboratory within the robert@464: Centre for Digital Music at Queen Mary University of London. robert@464: http://www.eecs.qmul.ac.uk/~andrewm robert@464: robert@464: (c) 2016 Augmented Instruments Laboratory: Andrew McPherson, robert@464: Astrid Bin, Liam Donovan, Christian Heinrichs, Robert Jack, robert@464: Giulio Moro, Laurel Pardue, Victor Zappi. All rights reserved. robert@464: robert@464: The Bela software is distributed under the GNU Lesser General Public License robert@464: (LGPL 3.0), available here: https://www.gnu.org/licenses/lgpl-3.0.txt robert@464: */ robert@464: robert@464: #include robert@464: #include robert@464: #include robert@464: #include robert@464: #include robert@464: #include robert@464: robert@464: extern int gBufferSize; robert@464: robert@464: using namespace std; robert@464: robert@464: // Handle Ctrl-C by requesting that the audio rendering stop robert@464: void interrupt_handler(int var) robert@464: { robert@464: gShouldStop = true; robert@464: } robert@464: robert@464: // Print usage information robert@464: void usage(const char * processName) robert@464: { robert@464: cerr << "Usage: " << processName << " [options]" << endl; robert@464: robert@464: Bela_usage(); robert@464: robert@464: cerr << " --buffer-size [-b] size Set the analysis buffer size\n"; robert@464: cerr << " --help [-h]: Print this menu\n"; robert@464: } robert@464: robert@464: int main(int argc, char *argv[]) robert@464: { robert@464: BelaInitSettings settings; // Standard audio settings robert@464: robert@464: struct option customOptions[] = robert@464: { robert@464: {"help", 0, NULL, 'h'}, robert@464: {"buffer-size", 1, NULL, 'b'}, robert@464: {NULL, 0, NULL, 0} robert@464: }; robert@464: robert@464: // Set default settings robert@464: Bela_defaultSettings(&settings); robert@464: robert@464: // By default use a longer period size because latency is not an issue robert@464: settings.periodSize = 32; robert@464: robert@464: // Parse command-line arguments robert@464: while (1) { robert@464: int c; robert@464: if ((c = Bela_getopt_long(argc, argv, "hb:", customOptions, &settings)) < 0) robert@464: break; robert@464: switch (c) { robert@464: case 'b': robert@464: gBufferSize = atoi(optarg); robert@464: break; robert@464: case 'h': robert@464: usage(basename(argv[0])); robert@464: exit(0); robert@464: case '?': robert@464: default: robert@464: usage(basename(argv[0])); robert@464: exit(1); robert@464: } robert@464: } robert@464: robert@464: if(gBufferSize < settings.periodSize) robert@464: gBufferSize = settings.periodSize; robert@464: robert@464: // Initialise the PRU audio device robert@464: if(Bela_initAudio(&settings, 0) != 0) { robert@464: cout << "Error: unable to initialise audio" << endl; robert@464: return -1; robert@464: } robert@464: robert@464: // Start the audio device running robert@464: if(Bela_startAudio()) { robert@464: cout << "Error: unable to start real-time audio" << endl; robert@464: return -1; robert@464: } robert@464: robert@464: // Set up interrupt handler to catch Control-C and SIGTERM robert@464: signal(SIGINT, interrupt_handler); robert@464: signal(SIGTERM, interrupt_handler); robert@464: robert@464: // Run until told to stop robert@464: while(!gShouldStop) { robert@464: usleep(100000); robert@464: } robert@464: robert@464: // Stop the audio device robert@464: Bela_stopAudio(); robert@464: robert@464: // Clean up any resources allocated for audio robert@464: Bela_cleanupAudio(); robert@464: robert@464: // All done! robert@464: return 0; robert@464: }