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