comparison projects/basic/render.cpp @ 180:07cfd337ad18

Updated examples with new audioWrite macros
author Giulio Moro <giuliomoro@yahoo.it>
date Sat, 02 Jan 2016 13:55:01 +0100
parents 3c3a1357657d
children ac8eb07afcf5
comparison
equal deleted inserted replaced
179:f1012082f142 180:07cfd337ad18
6 */ 6 */
7 7
8 8
9 #include <BeagleRT.h> 9 #include <BeagleRT.h>
10 #include <cmath> 10 #include <cmath>
11 #include <Utilities.h>
11 12
12 float gFrequency = 440.0; 13 float gFrequency = 440.0;
13 float gPhase; 14 float gPhase;
14 float gInverseSampleRate; 15 float gInverseSampleRate;
15 16
45 float out = 0.8f * sinf(gPhase); 46 float out = 0.8f * sinf(gPhase);
46 gPhase += 2.0 * M_PI * gFrequency * gInverseSampleRate; 47 gPhase += 2.0 * M_PI * gFrequency * gInverseSampleRate;
47 if(gPhase > 2.0 * M_PI) 48 if(gPhase > 2.0 * M_PI)
48 gPhase -= 2.0 * M_PI; 49 gPhase -= 2.0 * M_PI;
49 50
50 for(unsigned int channel = 0; channel < context->audioChannels; channel++) 51 for(unsigned int channel = 0; channel < context->audioChannels; channel++) {
51 context->audioOut[n * context->audioChannels + channel] = out; 52 // Two equivalent ways to write this code
53
54 // The long way, using the buffers directly:
55 // context->audioOut[n * context->audioChannels + channel] = out;
56
57 // Or using the macros:
58 audioWriteFrame(context, n, channel, out);
59 }
52 } 60 }
53 } 61 }
54 62
55 // cleanup() is called once at the end, after the audio has stopped. 63 // cleanup() is called once at the end, after the audio has stopped.
56 // Release any resources that were allocated in setup(). 64 // Release any resources that were allocated in setup().