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