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