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