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