annotate projects/basic_libpd/main.cpp @ 269:ac8eb07afcf5

Oxygen text added to each render.cpp file for the default projects. Text includes project explanation from Wiki, edited in places. Empty project added as a default project. Doxyfile updated. Each of the project locations added to INPUT configuration option. Consider just watching the whole project file so all new projects are automatically pulled through.
author Robert Jack <robert.h.jack@gmail.com>
date Tue, 17 May 2016 15:40:16 +0100
parents af211ee57867
children
rev   line source
giuliomoro@230 1 /*
giuliomoro@230 2 * default_main.cpp
giuliomoro@230 3 *
giuliomoro@230 4 * Created on: Oct 24, 2014
giuliomoro@230 5 * Author: parallels
giuliomoro@230 6 */
giuliomoro@230 7 #include <unistd.h>
giuliomoro@230 8 #include <iostream>
giuliomoro@230 9 #include <cstdlib>
giuliomoro@230 10 #include <libgen.h>
giuliomoro@230 11 #include <signal.h>
giuliomoro@230 12 #include <getopt.h>
giuliomoro@230 13 #include "../include/BeagleRT.h"
giuliomoro@230 14
giuliomoro@230 15 using namespace std;
giuliomoro@230 16
giuliomoro@230 17 // Handle Ctrl-C by requesting that the audio rendering stop
giuliomoro@230 18 void interrupt_handler(int var)
giuliomoro@230 19 {
giuliomoro@230 20 gShouldStop = true;
giuliomoro@230 21 }
giuliomoro@230 22
giuliomoro@230 23 // Print usage information
giuliomoro@230 24 void usage(const char * processName)
giuliomoro@230 25 {
giuliomoro@230 26 cerr << "Usage: " << processName << " [options]" << endl;
giuliomoro@230 27
giuliomoro@230 28 BeagleRT_usage();
giuliomoro@230 29
giuliomoro@230 30 cerr << " --help [-h]: Print this menu\n";
giuliomoro@230 31 }
giuliomoro@230 32
giuliomoro@230 33 int main(int argc, char *argv[])
giuliomoro@230 34 {
giuliomoro@230 35 BeagleRTInitSettings settings; // Standard audio settings
giuliomoro@230 36
giuliomoro@230 37 struct option customOptions[] =
giuliomoro@230 38 {
giuliomoro@230 39 {"help", 0, NULL, 'h'},
giuliomoro@230 40 {NULL, 0, NULL, 0}
giuliomoro@230 41 };
giuliomoro@230 42
giuliomoro@230 43 // Set default settings
giuliomoro@230 44 BeagleRT_defaultSettings(&settings);
giuliomoro@230 45
giuliomoro@230 46 // Parse command-line arguments
giuliomoro@230 47 while (1) {
giuliomoro@230 48 int c;
giuliomoro@230 49 if ((c = BeagleRT_getopt_long(argc, argv, "h", customOptions, &settings)) < 0)
giuliomoro@230 50 break;
giuliomoro@230 51 switch (c) {
giuliomoro@230 52 case 'h':
giuliomoro@230 53 usage(basename(argv[0]));
giuliomoro@230 54 exit(0);
giuliomoro@230 55 case '?':
giuliomoro@230 56 default:
giuliomoro@230 57 usage(basename(argv[0]));
giuliomoro@230 58 exit(1);
giuliomoro@230 59 }
giuliomoro@230 60 }
giuliomoro@230 61
giuliomoro@230 62 // Initialise the PRU audio device
giuliomoro@230 63 if(BeagleRT_initAudio(&settings, 0) != 0) {
giuliomoro@230 64 cout << "Error: unable to initialise audio" << endl;
giuliomoro@230 65 return -1;
giuliomoro@230 66 }
giuliomoro@230 67
giuliomoro@230 68 // Start the audio device running
giuliomoro@230 69 if(BeagleRT_startAudio()) {
giuliomoro@230 70 cout << "Error: unable to start real-time audio" << endl;
giuliomoro@230 71 return -1;
giuliomoro@230 72 }
giuliomoro@230 73
giuliomoro@230 74 // Set up interrupt handler to catch Control-C and SIGTERM
giuliomoro@230 75 signal(SIGINT, interrupt_handler);
giuliomoro@230 76 signal(SIGTERM, interrupt_handler);
giuliomoro@230 77
giuliomoro@230 78 // Run until told to stop
giuliomoro@230 79 while(!gShouldStop) {
giuliomoro@230 80 usleep(100000);
giuliomoro@230 81 }
giuliomoro@230 82
giuliomoro@230 83 // Stop the audio device
giuliomoro@230 84 BeagleRT_stopAudio();
giuliomoro@230 85
giuliomoro@230 86 // Clean up any resources allocated for audio
giuliomoro@230 87 BeagleRT_cleanupAudio();
giuliomoro@230 88
giuliomoro@230 89 // All done!
giuliomoro@230 90 return 0;
giuliomoro@230 91 }