comparison examples/01-Basics/sinetone/render.cpp @ 543:8f8809c77dda prerelease

updated basics, digital, instruments, extras examples
author chnrx <chris.heinrichs@gmail.com>
date Fri, 24 Jun 2016 13:19:52 +0100
parents 1cec96845a23
children db3e1a08cdee
comparison
equal deleted inserted replaced
542:3016638b4da2 543:8f8809c77dda
28 float gPhase; 28 float gPhase;
29 float gInverseSampleRate; 29 float gInverseSampleRate;
30 30
31 bool setup(BelaContext *context, void *userData) 31 bool setup(BelaContext *context, void *userData)
32 { 32 {
33 // Retrieve a parameter passed in from the initAudio() call
34 if(userData != 0)
35 gFrequency = *(float *)userData;
36
37 gInverseSampleRate = 1.0 / context->audioSampleRate; 33 gInverseSampleRate = 1.0 / context->audioSampleRate;
38 gPhase = 0.0; 34 gPhase = 0.0;s
39 35
40 return true; 36 return true;
41 } 37 }
42 38
43 void render(BelaContext *context, void *userData) 39 void render(BelaContext *context, void *userData)
46 float out = 0.8f * sinf(gPhase); 42 float out = 0.8f * sinf(gPhase);
47 gPhase += 2.0 * M_PI * gFrequency * gInverseSampleRate; 43 gPhase += 2.0 * M_PI * gFrequency * gInverseSampleRate;
48 if(gPhase > 2.0 * M_PI) 44 if(gPhase > 2.0 * M_PI)
49 gPhase -= 2.0 * M_PI; 45 gPhase -= 2.0 * M_PI;
50 46
51 for(unsigned int channel = 0; channel < context->audioChannels; channel++) { 47 for(unsigned int channel = 0; channel < context->audioOutChannels; channel++) {
52 // Two equivalent ways to write this code 48 // Two equivalent ways to write this code
53 49
54 // The long way, using the buffers directly: 50 // The long way, using the buffers directly:
55 // context->audioOut[n * context->audioChannels + channel] = out; 51 // context->audioOut[n * context->audioOutChannels + channel] = out;
56 52
57 // Or using the macros: 53 // Or using the macros:
58 audioWrite(context, n, channel, out); 54 audioWrite(context, n, channel, out);
59 } 55 }
60 } 56 }