annotate core/default_main.cpp @ 504:b6eb94378ca9 prerelease

update_board
author Giulio Moro <giuliomoro@yahoo.it>
date Wed, 22 Jun 2016 01:24:55 +0100
parents e4392164b458
children
rev   line source
giuliomoro@64 1 /*
giuliomoro@64 2 * default_main.cpp
giuliomoro@64 3 *
giuliomoro@64 4 * Created on: Oct 24, 2014
giuliomoro@64 5 * Author: parallels
giuliomoro@64 6 */
giuliomoro@64 7 #include <unistd.h>
giuliomoro@64 8 #include <iostream>
giuliomoro@64 9 #include <cstdlib>
giuliomoro@64 10 #include <libgen.h>
giuliomoro@64 11 #include <signal.h>
giuliomoro@64 12 #include <getopt.h>
giuliomoro@301 13 #include "../include/Bela.h"
giuliomoro@64 14
giuliomoro@64 15 using namespace std;
giuliomoro@64 16
giuliomoro@64 17 // Handle Ctrl-C by requesting that the audio rendering stop
giuliomoro@64 18 void interrupt_handler(int var)
giuliomoro@64 19 {
giuliomoro@64 20 gShouldStop = true;
giuliomoro@64 21 }
giuliomoro@64 22
giuliomoro@64 23 // Print usage information
giuliomoro@64 24 void usage(const char * processName)
giuliomoro@64 25 {
giuliomoro@64 26 cerr << "Usage: " << processName << " [options]" << endl;
giuliomoro@64 27
giuliomoro@301 28 Bela_usage();
giuliomoro@64 29
giuliomoro@64 30 cerr << " --help [-h]: Print this menu\n";
giuliomoro@64 31 }
giuliomoro@64 32
giuliomoro@64 33 int main(int argc, char *argv[])
giuliomoro@64 34 {
giuliomoro@301 35 BelaInitSettings settings; // Standard audio settings
giuliomoro@64 36
giuliomoro@64 37 struct option customOptions[] =
giuliomoro@64 38 {
giuliomoro@64 39 {"help", 0, NULL, 'h'},
giuliomoro@64 40 {NULL, 0, NULL, 0}
giuliomoro@64 41 };
giuliomoro@64 42
giuliomoro@64 43 // Set default settings
giuliomoro@301 44 Bela_defaultSettings(&settings);
giuliomoro@64 45
giuliomoro@64 46 // Parse command-line arguments
giuliomoro@64 47 while (1) {
giuliomoro@64 48 int c;
giuliomoro@301 49 if ((c = Bela_getopt_long(argc, argv, "h", customOptions, &settings)) < 0)
giuliomoro@64 50 break;
giuliomoro@64 51 switch (c) {
giuliomoro@64 52 case 'h':
giuliomoro@64 53 usage(basename(argv[0]));
giuliomoro@64 54 exit(0);
giuliomoro@64 55 case '?':
giuliomoro@64 56 default:
giuliomoro@64 57 usage(basename(argv[0]));
giuliomoro@64 58 exit(1);
giuliomoro@64 59 }
giuliomoro@64 60 }
giuliomoro@64 61
giuliomoro@64 62 // Initialise the PRU audio device
giuliomoro@301 63 if(Bela_initAudio(&settings, 0) != 0) {
giuliomoro@64 64 cout << "Error: unable to initialise audio" << endl;
giuliomoro@64 65 return -1;
giuliomoro@64 66 }
giuliomoro@64 67
giuliomoro@64 68 // Start the audio device running
giuliomoro@301 69 if(Bela_startAudio()) {
giuliomoro@64 70 cout << "Error: unable to start real-time audio" << endl;
giuliomoro@64 71 return -1;
giuliomoro@64 72 }
giuliomoro@64 73
giuliomoro@64 74 // Set up interrupt handler to catch Control-C and SIGTERM
giuliomoro@64 75 signal(SIGINT, interrupt_handler);
giuliomoro@64 76 signal(SIGTERM, interrupt_handler);
giuliomoro@64 77
giuliomoro@64 78 // Run until told to stop
giuliomoro@64 79 while(!gShouldStop) {
giuliomoro@64 80 usleep(100000);
giuliomoro@64 81 }
giuliomoro@64 82
giuliomoro@64 83 // Stop the audio device
giuliomoro@301 84 Bela_stopAudio();
giuliomoro@64 85
giuliomoro@64 86 // Clean up any resources allocated for audio
giuliomoro@301 87 Bela_cleanupAudio();
giuliomoro@64 88
giuliomoro@64 89 // All done!
giuliomoro@64 90 return 0;
giuliomoro@64 91 }