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