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