comparison examples/04-Audio/tremolo/render.cpp @ 547:a2096488a21a prerelease

Merge
author chnrx <chris.heinrichs@gmail.com>
date Fri, 24 Jun 2016 14:12:22 +0100
parents a11814e864a8
children
comparison
equal deleted inserted replaced
546:db3e1a08cdee 547:a2096488a21a
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 // Check that we have the same number of inputs and outputs.
34 if(context->audioInChannels != context->audioOutChannels ||
35 context->analogInChannels != context-> analogOutChannels){
36 printf("Error: for this project, you need the same number of input and output channels.\n");
37 return false;
38 }
33 39
34 gInverseSampleRate = 1.0 / context->audioSampleRate; 40 gInverseSampleRate = 1.0 / context->audioSampleRate;
35 gPhase = 0.0; 41 gPhase = 0.0;
36 42
37 return true; 43 return true;
48 // Keep track and wrap the phase of the sinewave 54 // Keep track and wrap the phase of the sinewave
49 gPhase += 2.0 * M_PI * gFrequency * gInverseSampleRate; 55 gPhase += 2.0 * M_PI * gFrequency * gInverseSampleRate;
50 if(gPhase > 2.0 * M_PI) 56 if(gPhase > 2.0 * M_PI)
51 gPhase -= 2.0 * M_PI; 57 gPhase -= 2.0 * M_PI;
52 58
53 for(unsigned int channel = 0; channel < context->audioChannels; channel++) { 59 for(unsigned int channel = 0; channel < context->audioOutChannels; channel++) {
54 // Read the audio input and half the amplitude 60 // Read the audio input and half the amplitude
55 float input = audioRead(context, n, channel) * 0.5; 61 float input = audioRead(context, n, channel) * 0.5;
56 // Write to audio output the audio input multiplied by the sinewave 62 // Write to audio output the audio input multiplied by the sinewave
57 audioWrite(context, n, channel, (input*lfo)); 63 audioWrite(context, n, channel, (input*lfo));
58 } 64 }
59 } 65 }
60 66
61 // Nested for loops for analog channels 67 // Nested for loops for analog channels
62 for(unsigned int n = 0; n < context->analogFrames; n++) { 68 for(unsigned int n = 0; n < context->analogFrames; n++) {
63 for(unsigned int ch = 0; ch < context->analogChannels; ch++) { 69 for(unsigned int ch = 0; ch < context->analogOutChannels; ch++) {
64 // Read analog channel 0 and map the range from 0-1 to 0.25-20 70 // Read analog channel 0 and map the range from 0-1 to 0.25-20
65 // use this to set the value of gFrequency 71 // use this to set the value of gFrequency
66 gFrequency = map(analogRead(context, n, 0), 0.0, 1.0, 0.25, 20.0); 72 gFrequency = map(analogRead(context, n, 0), 0.0, 1.0, 0.25, 20.0);
67 } 73 }
68 } 74 }