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