robert@464: /* robert@464: * default_main.cpp robert@464: * robert@464: * Created on: Oct 24, 2014 robert@464: * Author: parallels robert@464: */ robert@464: #include robert@464: #include robert@464: #include robert@464: #include robert@464: #include robert@464: #include robert@464: #include "../include/Bela.h" 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 << " --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: {NULL, 0, NULL, 0} robert@464: }; robert@464: robert@464: // Set default settings robert@464: Bela_defaultSettings(&settings); 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, "h", customOptions, &settings)) < 0) robert@464: break; robert@464: switch (c) { 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: // 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: }