annotate projects/audio_in_FFT/main.cpp @ 12:a6beeba3a648

Initial support for higher matrix sample rates by reducing the number of channels. Input not tested yet, and not all examples updated to new format.
author andrewm
date Thu, 22 Jan 2015 19:00:22 +0000
parents 09f03ac40fcc
children 901d205d1a3c
rev   line source
victor@4 1 /*
victor@4 2 * main.cpp
victor@4 3 *
victor@4 4 * Created on: Oct 24, 2014
victor@4 5 * Author: parallels
victor@4 6 */
victor@4 7
victor@4 8 #include <iostream>
victor@4 9 #include <cstdlib>
victor@4 10 #include <libgen.h>
victor@4 11 #include <signal.h>
andrewm@5 12 #include <getopt.h>
victor@4 13 #include "../../include/RTAudio.h"
victor@4 14
victor@4 15 using namespace std;
victor@4 16
victor@4 17 // Handle Ctrl-C by requesting that the audio rendering stop
victor@4 18 void interrupt_handler(int var)
victor@4 19 {
victor@4 20 gShouldStop = true;
victor@4 21 }
victor@4 22
victor@4 23 // Print usage information
victor@4 24 void usage(const char * processName)
victor@4 25 {
andrewm@5 26 cerr << "Usage: " << processName << " [options]" << endl;
andrewm@5 27
andrewm@5 28 BeagleRT_usage();
andrewm@5 29
andrewm@5 30 cerr << " --fftsize [-s] size: Set the fSize of the FFT, in samples\n";
andrewm@5 31 cerr << " --help [-h]: Print this menu\n";
victor@4 32 }
victor@4 33
victor@4 34 int main(int argc, char *argv[])
victor@4 35 {
andrewm@5 36 RTAudioSettings settings; // Standard audio settings
victor@4 37 int fftSize = 64; // Size of the FFT, in samples
andrewm@5 38
andrewm@5 39 struct option customOptions[] =
andrewm@5 40 {
andrewm@5 41 {"help", 0, NULL, 'h'},
andrewm@5 42 {"fftsize", 1, NULL, 's'},
andrewm@5 43 {NULL, 0, NULL, 0}
andrewm@5 44 };
andrewm@5 45
andrewm@5 46 // Set default settings
andrewm@5 47 BeagleRT_defaultSettings(&settings);
andrewm@5 48
andrewm@5 49 settings.useMatrix = 0; // No matrix usage by default
victor@4 50
victor@4 51 // Parse command-line arguments
victor@4 52 while (1) {
victor@4 53 int c;
andrewm@5 54 if ((c = BeagleRT_getopt_long(argc, argv, "hs:", customOptions, &settings)) < 0)
victor@4 55 break;
victor@4 56 switch (c) {
victor@4 57 case 'h':
victor@4 58 usage(basename(argv[0]));
victor@4 59 exit(0);
victor@4 60 case 's':
victor@4 61 fftSize = atof(optarg);
victor@4 62 break;
victor@4 63 case '?':
victor@4 64 default:
victor@4 65 usage(basename(argv[0]));
victor@4 66 exit(1);
victor@4 67 }
victor@4 68 }
victor@4 69
victor@4 70 // Initialise the PRU audio device
andrewm@5 71 if(BeagleRT_initAudio(&settings, &fftSize) != 0) {
victor@4 72 cout << "Error: unable to initialise audio" << endl;
victor@4 73 return -1;
victor@4 74 }
victor@4 75
victor@4 76 // Start the audio device running
andrewm@5 77 if(BeagleRT_startAudio()) {
victor@4 78 cout << "Error: unable to start real-time audio" << endl;
victor@4 79 return -1;
victor@4 80 }
victor@4 81
victor@4 82 // Set up interrupt handler to catch Control-C
victor@4 83 signal(SIGINT, interrupt_handler);
victor@4 84
victor@4 85 // Run until told to stop
victor@4 86 while(!gShouldStop) {
victor@4 87 usleep(100000);
victor@4 88 }
victor@4 89
victor@4 90 // Stop the audio device
andrewm@5 91 BeagleRT_stopAudio();
victor@4 92
victor@4 93 // Clean up any resources allocated for audio
andrewm@5 94 BeagleRT_cleanupAudio();
victor@4 95
victor@4 96 // All done!
victor@4 97 return 0;
victor@4 98 }
andrewm@5 99