giuliomoro@153
|
1 #include <BeagleRT.h>
|
giuliomoro@153
|
2 #include <Scope.h>
|
giuliomoro@153
|
3 #include <cmath>
|
giuliomoro@153
|
4 #include <WriteFile.h>
|
giuliomoro@153
|
5
|
giuliomoro@153
|
6 float gPhase1, gPhase2;
|
giuliomoro@153
|
7 float gFrequency1, gFrequency2;
|
giuliomoro@153
|
8 float gInverseSampleRate;
|
giuliomoro@153
|
9
|
giuliomoro@153
|
10 WriteFile file1;
|
giuliomoro@153
|
11 WriteFile file2;
|
giuliomoro@153
|
12
|
giuliomoro@153
|
13 bool setup(BeagleRTContext *context, void *userData)
|
giuliomoro@153
|
14 {
|
giuliomoro@153
|
15 gInverseSampleRate = 1.0/context->audioSampleRate;
|
giuliomoro@153
|
16 file1.init("out1.m"); //set the file name to write to
|
giuliomoro@153
|
17 file1.setHeader("myvar=[\n"); //set a line to be printed at the beginning of the file
|
giuliomoro@153
|
18 file1.setFooter("];\n"); //set a line to be printed at the end of the file
|
giuliomoro@153
|
19 file1.setEcho(true); // enable echo to the console (as well as to the file)
|
giuliomoro@153
|
20 file1.setFormat("%.5f %.10f %f\n"); // set the format that you want to use for your output. Please use %f only (with modifiers)
|
giuliomoro@153
|
21 file2.init("out2.m");
|
giuliomoro@153
|
22 file2.setHeader("input=[\n");
|
giuliomoro@153
|
23 file2.setFooter("];\n");
|
giuliomoro@153
|
24 file2.setEcho(false);
|
giuliomoro@153
|
25 file2.setFormat("%f\n");
|
giuliomoro@153
|
26 gPhase1 = 0.0;
|
giuliomoro@153
|
27 gPhase2 = 0.0;
|
giuliomoro@153
|
28
|
giuliomoro@153
|
29 gFrequency1 = 200.0;
|
giuliomoro@153
|
30 gFrequency2 = 201.0;
|
giuliomoro@153
|
31 return true;
|
giuliomoro@153
|
32 }
|
giuliomoro@153
|
33
|
giuliomoro@153
|
34 void render(BeagleRTContext *context, void *userData)
|
giuliomoro@153
|
35 {
|
giuliomoro@153
|
36 static int count = 0;
|
giuliomoro@153
|
37 if((count&16383) == 0){
|
giuliomoro@153
|
38 file2.log(context->audioIn, context->audioFrames); //write the input buffer every so often
|
giuliomoro@153
|
39 }
|
giuliomoro@153
|
40 for(unsigned int n = 0; n < context->audioFrames; n++) {
|
giuliomoro@153
|
41 float chn1 = sinf(gPhase1);
|
giuliomoro@153
|
42 float chn2 = sinf(gPhase2);
|
giuliomoro@153
|
43 gPhase1 += 2.0 * M_PI * gFrequency1 * gInverseSampleRate;
|
giuliomoro@153
|
44 gPhase2 += 2.0 * M_PI * gFrequency2 * gInverseSampleRate;
|
giuliomoro@153
|
45 if(gPhase1 > 2.0 * M_PI)
|
giuliomoro@153
|
46 gPhase1 -= 2.0 * M_PI;
|
giuliomoro@153
|
47 if(gPhase2 > 2.0 * M_PI)
|
giuliomoro@153
|
48 gPhase2 -= 2.0 * M_PI;
|
giuliomoro@153
|
49 if( (count&511) == 0){
|
giuliomoro@153
|
50 file1.log(chn1);
|
giuliomoro@153
|
51 file1.log(chn2);
|
giuliomoro@153
|
52 file1.log(count);
|
giuliomoro@153
|
53 }
|
giuliomoro@153
|
54 count++;
|
giuliomoro@153
|
55 }
|
giuliomoro@153
|
56 }
|
giuliomoro@153
|
57
|
giuliomoro@153
|
58 // cleanup_render() is called once at the end, after the audio has stopped.
|
giuliomoro@153
|
59 // Release any resources that were allocated in initialise_render().
|
giuliomoro@153
|
60
|
giuliomoro@153
|
61 void cleanup(BeagleRTContext *context, void *userData)
|
giuliomoro@153
|
62 {
|
giuliomoro@153
|
63
|
giuliomoro@153
|
64 }
|