comparison projects/matrix_gpio_demo/main.cpp @ 18:31503d9de101 matrix_gpio

- digitalWrite and analogWrite macros are now persistent: they write a value on the given channel from the current frame to the end of the buffer. When this is not needed you can use digitalWriteFrame and analogWriteFrame instead. - included the matrix_gpio_demo code - the Eclipe project is somehow broken
author Giulio Moro <giuliomoro@yahoo.it>
date Thu, 30 Apr 2015 16:02:47 +0100
parents
children
comparison
equal deleted inserted replaced
17:85e8b08a7471 18:31503d9de101
1 /*
2 * assignment1_crossover
3 * RTDSP 2015
4 *
5 * First assignment for ECS732 RTDSP, to implement a 2-way audio crossover
6 * using the BeagleBone Black.
7 *
8 * Andrew McPherson and Victor Zappi
9 * Queen Mary, University of London
10 */
11
12 #include <iostream>
13 #include <cstdlib>
14 #include <libgen.h>
15 #include <signal.h>
16 #include <getopt.h>
17 #include "../include/RTAudio.h"
18 #include <unistd.h>
19 #include <stdlib.h>
20 #include <fcntl.h>
21
22 using namespace std;
23
24 // Handle Ctrl-C by requesting that the audio rendering stop
25 void interrupt_handler(int var)
26 {
27 gShouldStop = true;
28 }
29
30 // Print usage information
31 void usage(const char * processName)
32 {
33 cerr << "Usage: " << processName << " [options]" << endl;
34
35 BeagleRT_usage();
36
37 cerr << " --help [-h]: Print this menu\n";
38 }
39
40 int main(int argc, char *argv[])
41 {
42 RTAudioSettings settings; // Standard audio settings
43 float frequency = 1000.0; // Frequency of crossover
44
45 struct option customOptions[] =
46 {
47 {"help", 0, NULL, 'h'},
48 {"frequency", 1, NULL, 'f'},
49 {NULL, 0, NULL, 0}
50 };
51
52 // Set default settings
53 BeagleRT_defaultSettings(&settings);
54
55 // Parse command-line arguments
56 while (1) {
57 int c;
58 if ((c = BeagleRT_getopt_long(argc, argv, "hf:", customOptions, &settings)) < 0)
59 break;
60 switch (c) {
61 case 'h':
62 usage(basename(argv[0]));
63 exit(0);
64 case 'f':
65 frequency = atof(optarg);
66 if(frequency < 20.0)
67 frequency = 20.0;
68 if(frequency > 5000.0)
69 frequency = 5000.0;
70 break;
71 case '?':
72 default:
73 usage(basename(argv[0]));
74 exit(1);
75 }
76 }
77
78 // Initialise the PRU audio device
79 if(BeagleRT_initAudio(&settings, &frequency) != 0) {
80 cout << "Error: unable to initialise audio" << endl;
81 return -1;
82 }
83
84 // Start the audio device running
85 if(BeagleRT_startAudio()) {
86 cout << "Error: unable to start real-time audio" << endl;
87 return -1;
88 }
89
90 // Set up interrupt handler to catch Control-C
91 signal(SIGINT, interrupt_handler);
92 signal(SIGTERM, interrupt_handler);
93
94 // Run until told to stop
95 while(!gShouldStop) {
96 usleep(100000);
97 }
98
99 // Stop the audio device
100 BeagleRT_stopAudio();
101
102 // Clean up any resources allocated for audio
103 BeagleRT_cleanupAudio();
104
105 // All done!
106 return 0;
107 }