giuliomoro@18: /* giuliomoro@18: * assignment1_crossover giuliomoro@18: * RTDSP 2015 giuliomoro@18: * giuliomoro@18: * First assignment for ECS732 RTDSP, to implement a 2-way audio crossover giuliomoro@18: * using the BeagleBone Black. giuliomoro@18: * giuliomoro@18: * Andrew McPherson and Victor Zappi giuliomoro@18: * Queen Mary, University of London giuliomoro@18: */ giuliomoro@18: giuliomoro@18: #include giuliomoro@18: #include giuliomoro@18: #include giuliomoro@18: #include giuliomoro@18: #include giuliomoro@18: #include "../include/RTAudio.h" giuliomoro@18: #include giuliomoro@18: #include giuliomoro@18: #include giuliomoro@18: giuliomoro@18: using namespace std; giuliomoro@18: giuliomoro@18: // Handle Ctrl-C by requesting that the audio rendering stop giuliomoro@18: void interrupt_handler(int var) giuliomoro@18: { giuliomoro@18: gShouldStop = true; giuliomoro@18: } giuliomoro@18: giuliomoro@18: // Print usage information giuliomoro@18: void usage(const char * processName) giuliomoro@18: { giuliomoro@18: cerr << "Usage: " << processName << " [options]" << endl; giuliomoro@18: giuliomoro@18: BeagleRT_usage(); giuliomoro@18: giuliomoro@18: cerr << " --help [-h]: Print this menu\n"; giuliomoro@18: } giuliomoro@18: giuliomoro@18: int main(int argc, char *argv[]) giuliomoro@18: { giuliomoro@18: RTAudioSettings settings; // Standard audio settings giuliomoro@18: float frequency = 1000.0; // Frequency of crossover giuliomoro@18: giuliomoro@18: struct option customOptions[] = giuliomoro@18: { giuliomoro@18: {"help", 0, NULL, 'h'}, giuliomoro@18: {"frequency", 1, NULL, 'f'}, giuliomoro@18: {NULL, 0, NULL, 0} giuliomoro@18: }; giuliomoro@18: giuliomoro@18: // Set default settings giuliomoro@18: BeagleRT_defaultSettings(&settings); giuliomoro@18: giuliomoro@18: // Parse command-line arguments giuliomoro@18: while (1) { giuliomoro@18: int c; giuliomoro@18: if ((c = BeagleRT_getopt_long(argc, argv, "hf:", customOptions, &settings)) < 0) giuliomoro@18: break; giuliomoro@18: switch (c) { giuliomoro@18: case 'h': giuliomoro@18: usage(basename(argv[0])); giuliomoro@18: exit(0); giuliomoro@18: case 'f': giuliomoro@18: frequency = atof(optarg); giuliomoro@18: if(frequency < 20.0) giuliomoro@18: frequency = 20.0; giuliomoro@18: if(frequency > 5000.0) giuliomoro@18: frequency = 5000.0; giuliomoro@18: break; giuliomoro@18: case '?': giuliomoro@18: default: giuliomoro@18: usage(basename(argv[0])); giuliomoro@18: exit(1); giuliomoro@18: } giuliomoro@18: } giuliomoro@18: giuliomoro@18: // Initialise the PRU audio device giuliomoro@18: if(BeagleRT_initAudio(&settings, &frequency) != 0) { giuliomoro@18: cout << "Error: unable to initialise audio" << endl; giuliomoro@18: return -1; giuliomoro@18: } giuliomoro@18: giuliomoro@18: // Start the audio device running giuliomoro@18: if(BeagleRT_startAudio()) { giuliomoro@18: cout << "Error: unable to start real-time audio" << endl; giuliomoro@18: return -1; giuliomoro@18: } giuliomoro@18: giuliomoro@18: // Set up interrupt handler to catch Control-C giuliomoro@18: signal(SIGINT, interrupt_handler); giuliomoro@18: signal(SIGTERM, interrupt_handler); giuliomoro@18: giuliomoro@18: // Run until told to stop giuliomoro@18: while(!gShouldStop) { giuliomoro@18: usleep(100000); giuliomoro@18: } giuliomoro@18: giuliomoro@18: // Stop the audio device giuliomoro@18: BeagleRT_stopAudio(); giuliomoro@18: giuliomoro@18: // Clean up any resources allocated for audio giuliomoro@18: BeagleRT_cleanupAudio(); giuliomoro@18: giuliomoro@18: // All done! giuliomoro@18: return 0; giuliomoro@18: }