andrewm@0: /* andrewm@0: * main.cpp andrewm@0: * andrewm@0: * Created on: Oct 24, 2014 andrewm@0: * Author: parallels andrewm@0: */ andrewm@0: andrewm@0: #include andrewm@0: #include andrewm@0: #include andrewm@0: #include andrewm@5: #include andrewm@0: #include "../../include/RTAudio.h" andrewm@0: andrewm@0: using namespace std; andrewm@0: andrewm@0: // Handle Ctrl-C by requesting that the audio rendering stop andrewm@0: void interrupt_handler(int var) andrewm@0: { andrewm@0: gShouldStop = true; andrewm@0: } andrewm@0: andrewm@0: // Print usage information andrewm@0: void usage(const char * processName) andrewm@0: { andrewm@5: cerr << "Usage: " << processName << " [options]" << endl; andrewm@5: andrewm@5: BeagleRT_usage(); andrewm@5: andrewm@5: cerr << " --frequency [-f] frequency: Set the frequency of the LED fade (default: 1.0)\n"; andrewm@5: cerr << " --help [-h]: Print this menu\n"; andrewm@0: } andrewm@0: andrewm@0: int main(int argc, char *argv[]) andrewm@0: { andrewm@5: RTAudioSettings settings; // Standard audio settings andrewm@5: float frequency = 1.0; // Frequency of LED fades andrewm@5: andrewm@5: struct option customOptions[] = andrewm@5: { andrewm@5: {"help", 0, NULL, 'h'}, andrewm@5: {"frequency", 1, NULL, 'f'}, andrewm@5: {NULL, 0, NULL, 0} andrewm@5: }; andrewm@5: andrewm@5: // Set default settings andrewm@5: BeagleRT_defaultSettings(&settings); andrewm@5: andrewm@5: // In this example, audio isn't used so might as well leave speaker muted andrewm@5: settings.beginMuted = 1; andrewm@0: andrewm@0: // Parse command-line arguments andrewm@0: while (1) { andrewm@0: int c; andrewm@5: if ((c = BeagleRT_getopt_long(argc, argv, "hf:", customOptions, &settings)) < 0) andrewm@0: break; andrewm@0: switch (c) { andrewm@0: case 'h': andrewm@0: usage(basename(argv[0])); andrewm@0: exit(0); andrewm@0: case 'f': andrewm@0: frequency = atof(optarg); andrewm@0: if(frequency < 0) andrewm@0: frequency = 0; andrewm@0: if(frequency > 11025.0) andrewm@0: frequency = 11025.0; andrewm@0: break; andrewm@0: case '?': andrewm@0: default: andrewm@0: usage(basename(argv[0])); andrewm@0: exit(1); andrewm@0: } andrewm@0: } andrewm@0: andrewm@0: // Initialise the PRU audio device andrewm@5: if(BeagleRT_initAudio(&settings, &frequency) != 0) { andrewm@0: cout << "Error: unable to initialise audio" << endl; andrewm@0: return -1; andrewm@0: } andrewm@0: andrewm@0: // Start the audio device running andrewm@5: if(BeagleRT_startAudio()) { andrewm@0: cout << "Error: unable to start real-time audio" << endl; andrewm@0: return -1; andrewm@0: } andrewm@0: andrewm@15: // Set up interrupt handler to catch Control-C and SIGTERM andrewm@0: signal(SIGINT, interrupt_handler); andrewm@15: signal(SIGTERM, interrupt_handler); andrewm@0: andrewm@0: // Run until told to stop andrewm@0: while(!gShouldStop) { andrewm@0: usleep(100000); andrewm@0: } andrewm@0: andrewm@0: // Stop the audio device andrewm@5: BeagleRT_stopAudio(); andrewm@0: andrewm@0: // Clean up any resources allocated for audio andrewm@5: BeagleRT_cleanupAudio(); andrewm@0: andrewm@0: // All done! andrewm@0: return 0; andrewm@0: }