Mercurial > hg > beaglert
diff projects/basic_sensor/render.cpp @ 13:6adb088196a7
Fixed ADC bug; added a simple passthrough test
author | andrewm |
---|---|
date | Fri, 23 Jan 2015 15:17:09 +0000 |
parents | a6beeba3a648 |
children | a6d223473ea2 |
line wrap: on
line diff
--- a/projects/basic_sensor/render.cpp Thu Jan 22 19:00:22 2015 +0000 +++ b/projects/basic_sensor/render.cpp Fri Jan 23 15:17:09 2015 +0000 @@ -13,7 +13,7 @@ float gPhase; float gInverseSampleRate; -int gNumChannels; +int gMatrixFramesPerAudioFrame; // These settings are carried over from main.cpp // Setting global variables is an alternative approach @@ -37,12 +37,12 @@ float matrixSampleRate, float audioSampleRate, void *userData) { - if(numMatrixFramesPerPeriod*2 != numAudioFramesPerPeriod) { - rt_printf("Error: this example needs the matrix enabled, running at half audio rate\n"); + if(numMatrixFramesPerPeriod == 0 || numMatrixFramesPerPeriod > numAudioFramesPerPeriod) { + rt_printf("Error: this example needs the matrix enabled, with 4 or 8 channels\n"); return false; } - gNumChannels = numAudioChannels; + gMatrixFramesPerAudioFrame = numAudioFramesPerPeriod / numMatrixFramesPerPeriod; gInverseSampleRate = 1.0 / audioSampleRate; gPhase = 0.0; @@ -64,16 +64,16 @@ // is twice as high for(int n = 0; n < numAudioFrames; n++) { - if(!(n % 2)) { + if(!(n % gMatrixFramesPerAudioFrame)) { // Even audio samples: update frequency and amplitude from the matrix - frequency = map((float)analogRead(gSensorInputFrequency, n/2), 0, MATRIX_MAX, 100, 1000); - amplitude = (float)analogRead(gSensorInputAmplitude, n/2) / MATRIX_MAX; + frequency = map(analogRead(gSensorInputFrequency, n/gMatrixFramesPerAudioFrame), 0, MATRIX_MAX, 100, 1000); + amplitude = (float)analogRead(gSensorInputAmplitude, n/gMatrixFramesPerAudioFrame) / MATRIX_MAX; } float out = amplitude * sinf(gPhase); - for(int channel = 0; channel < gNumChannels; channel++) - audioOut[n * gNumChannels + channel] = out; + for(int channel = 0; channel < gNumAudioChannels; channel++) + audioOut[n * gNumAudioChannels + channel] = out; gPhase += 2.0 * M_PI * frequency * gInverseSampleRate; if(gPhase > 2.0 * M_PI)