comparison examples/04-Audio/tremolo/render.cpp @ 545:a11814e864a8 prerelease

Tremolo updated
author Robert Jack <robert.h.jack@gmail.com>
date Fri, 24 Jun 2016 13:36:09 +0100
parents 58652b93ef7e
children
comparison
equal deleted inserted replaced
544:cdabbaf3a252 545:a11814e864a8
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 }