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