giuliomoro@64: /* giuliomoro@64: * default_main.cpp giuliomoro@64: * giuliomoro@64: * Created on: Oct 24, 2014 giuliomoro@64: * Author: parallels giuliomoro@64: */ giuliomoro@64: #include giuliomoro@64: #include giuliomoro@64: #include giuliomoro@64: #include giuliomoro@64: #include giuliomoro@64: #include giuliomoro@301: #include "../include/Bela.h" giuliomoro@64: giuliomoro@64: using namespace std; giuliomoro@64: giuliomoro@64: // Handle Ctrl-C by requesting that the audio rendering stop giuliomoro@64: void interrupt_handler(int var) giuliomoro@64: { giuliomoro@64: gShouldStop = true; giuliomoro@64: } giuliomoro@64: giuliomoro@64: // Print usage information giuliomoro@64: void usage(const char * processName) giuliomoro@64: { giuliomoro@64: cerr << "Usage: " << processName << " [options]" << endl; giuliomoro@64: giuliomoro@301: Bela_usage(); giuliomoro@64: giuliomoro@64: cerr << " --help [-h]: Print this menu\n"; giuliomoro@64: } giuliomoro@64: giuliomoro@64: int main(int argc, char *argv[]) giuliomoro@64: { giuliomoro@301: BelaInitSettings settings; // Standard audio settings giuliomoro@64: giuliomoro@64: struct option customOptions[] = giuliomoro@64: { giuliomoro@64: {"help", 0, NULL, 'h'}, giuliomoro@64: {NULL, 0, NULL, 0} giuliomoro@64: }; giuliomoro@64: giuliomoro@64: // Set default settings giuliomoro@301: Bela_defaultSettings(&settings); giuliomoro@64: giuliomoro@64: // Parse command-line arguments giuliomoro@64: while (1) { giuliomoro@64: int c; giuliomoro@301: if ((c = Bela_getopt_long(argc, argv, "h", customOptions, &settings)) < 0) giuliomoro@64: break; giuliomoro@64: switch (c) { giuliomoro@64: case 'h': giuliomoro@64: usage(basename(argv[0])); giuliomoro@64: exit(0); giuliomoro@64: case '?': giuliomoro@64: default: giuliomoro@64: usage(basename(argv[0])); giuliomoro@64: exit(1); giuliomoro@64: } giuliomoro@64: } giuliomoro@64: giuliomoro@64: // Initialise the PRU audio device giuliomoro@301: if(Bela_initAudio(&settings, 0) != 0) { giuliomoro@64: cout << "Error: unable to initialise audio" << endl; giuliomoro@64: return -1; giuliomoro@64: } giuliomoro@64: giuliomoro@64: // Start the audio device running giuliomoro@301: if(Bela_startAudio()) { giuliomoro@64: cout << "Error: unable to start real-time audio" << endl; giuliomoro@64: return -1; giuliomoro@64: } giuliomoro@64: giuliomoro@64: // Set up interrupt handler to catch Control-C and SIGTERM giuliomoro@64: signal(SIGINT, interrupt_handler); giuliomoro@64: signal(SIGTERM, interrupt_handler); giuliomoro@64: giuliomoro@64: // Run until told to stop giuliomoro@64: while(!gShouldStop) { giuliomoro@64: usleep(100000); giuliomoro@64: } giuliomoro@64: giuliomoro@64: // Stop the audio device giuliomoro@301: Bela_stopAudio(); giuliomoro@64: giuliomoro@64: // Clean up any resources allocated for audio giuliomoro@301: Bela_cleanupAudio(); giuliomoro@64: giuliomoro@64: // All done! giuliomoro@64: return 0; giuliomoro@64: }