Mercurial > hg > beaglert
comparison examples/07-DataLogging/write-file/render.cpp @ 501:6962184f8567 prerelease
Additional name changes to doxygen example title.
author | Robert Jack <robert.h.jack@gmail.com> |
---|---|
date | Wed, 22 Jun 2016 00:34:07 +0100 |
parents | |
children | ff6e9199c444 |
comparison
equal
deleted
inserted
replaced
500:b935f890e512 | 501:6962184f8567 |
---|---|
1 /* | |
2 ____ _____ _ _ | |
3 | __ )| ____| | / \ | |
4 | _ \| _| | | / _ \ | |
5 | |_) | |___| |___ / ___ \ | |
6 |____/|_____|_____/_/ \_\ | |
7 | |
8 The platform for ultra-low latency audio and sensor processing | |
9 | |
10 http://bela.io | |
11 | |
12 A project of the Augmented Instruments Laboratory within the | |
13 Centre for Digital Music at Queen Mary University of London. | |
14 http://www.eecs.qmul.ac.uk/~andrewm | |
15 | |
16 (c) 2016 Augmented Instruments Laboratory: Andrew McPherson, | |
17 Astrid Bin, Liam Donovan, Christian Heinrichs, Robert Jack, | |
18 Giulio Moro, Laurel Pardue, Victor Zappi. All rights reserved. | |
19 | |
20 The Bela software is distributed under the GNU Lesser General Public License | |
21 (LGPL 3.0), available here: https://www.gnu.org/licenses/lgpl-3.0.txt | |
22 */ | |
23 | |
24 | |
25 #include <Bela.h> | |
26 #include <cmath> | |
27 #include <WriteFile.h> | |
28 | |
29 float gPhase1, gPhase2; | |
30 float gFrequency1, gFrequency2; | |
31 float gInverseSampleRate; | |
32 | |
33 WriteFile file1; | |
34 WriteFile file2; | |
35 | |
36 bool setup(BelaContext *context, void *userData) | |
37 { | |
38 gInverseSampleRate = 1.0/context->audioSampleRate; | |
39 file1.init("out1.m"); //set the file name to write to | |
40 file1.setHeader("myvar=[\n"); //set a line to be printed at the beginning of the file | |
41 file1.setFooter("];\n"); //set a line to be printed at the end of the file | |
42 file1.setEcho(true); // enable echo to the console (as well as to the file) | |
43 file1.setFormat("%.5f %.10f %f\n"); // set the format that you want to use for your output. Please use %f only (with modifiers) | |
44 file2.init("out2.m"); | |
45 file2.setHeader("input=[\n"); | |
46 file2.setFooter("];\n"); | |
47 file2.setEcho(false); | |
48 file2.setFormat("%f\n"); | |
49 gPhase1 = 0.0; | |
50 gPhase2 = 0.0; | |
51 | |
52 gFrequency1 = 200.0; | |
53 gFrequency2 = 201.0; | |
54 return true; | |
55 } | |
56 | |
57 void render(BelaContext *context, void *userData) | |
58 { | |
59 static int count = 0; | |
60 if((count&16383) == 0){ | |
61 file2.log(context->audioIn, context->audioFrames); //write the input buffer every so often | |
62 } | |
63 for(unsigned int n = 0; n < context->audioFrames; n++) { | |
64 float chn1 = sinf(gPhase1); | |
65 float chn2 = sinf(gPhase2); | |
66 gPhase1 += 2.0 * M_PI * gFrequency1 * gInverseSampleRate; | |
67 gPhase2 += 2.0 * M_PI * gFrequency2 * gInverseSampleRate; | |
68 if(gPhase1 > 2.0 * M_PI) | |
69 gPhase1 -= 2.0 * M_PI; | |
70 if(gPhase2 > 2.0 * M_PI) | |
71 gPhase2 -= 2.0 * M_PI; | |
72 if( (count&511) == 0){ | |
73 file1.log(chn1); | |
74 file1.log(chn2); | |
75 file1.log(count); | |
76 } | |
77 count++; | |
78 } | |
79 } | |
80 | |
81 // cleanup_render() is called once at the end, after the audio has stopped. | |
82 // Release any resources that were allocated in initialise_render(). | |
83 | |
84 void cleanup(BelaContext *context, void *userData) | |
85 { | |
86 | |
87 } | |
88 | |
89 /* ------------ Project Explantation ------------ */ | |
90 | |
91 /** | |
92 \example 07-write-file | |
93 | |
94 Writing data to a file | |
95 --------------------------- | |
96 | |
97 This sketch demonstrates how to log values from within a project for later processing or analysis. | |
98 | |
99 */ | |
100 |