diff examples/04-Audio/FFT-audio-in/render.cpp @ 544:cdabbaf3a252 prerelease

Updated Audio examples for audioOutChannels etc.
author Robert Jack <robert.h.jack@gmail.com>
date Fri, 24 Jun 2016 13:32:07 +0100
parents 1cec96845a23
children
line wrap: on
line diff
--- a/examples/04-Audio/FFT-audio-in/render.cpp	Fri Jun 24 13:19:52 2016 +0100
+++ b/examples/04-Audio/FFT-audio-in/render.cpp	Fri Jun 24 13:32:07 2016 +0100
@@ -40,6 +40,14 @@
 
 bool setup(BelaContext *context, void *userData)
 {
+    
+    // Check that we have the same number of inputs and outputs.
+	if(context->audioInChannels != context->audioOutChannels ||
+			context->analogInChannels != context-> analogOutChannels){
+		printf("Error: for this project, you need the same number of input and output channels.\n");
+		return false;
+	}
+	
 	// Retrieve a parameter passed in from the initAudio() call
 	gFFTSize = *(int *)userData;
 
@@ -56,8 +64,8 @@
 void render(BelaContext *context, void *userData)
 {
 	for(unsigned int n = 0; n < context->audioFrames; n++) {
-		timeDomainIn[gReadPointer].r = (ne10_float32_t) ((context->audioIn[n*context->audioChannels] +
-															context->audioIn[n*context->audioChannels+1]) * 0.5);
+		timeDomainIn[gReadPointer].r = (ne10_float32_t) ((context->audioIn[n*context->audioInChannels] +
+															context->audioIn[n*context->audioOutChannels+1]) * 0.5);
 		timeDomainIn[gReadPointer].i = 0;
 
 		if(++gReadPointer >= gFFTSize)
@@ -74,8 +82,8 @@
 			gWritePointer = 0;
 		}
 
-		for(unsigned int channel = 0; channel < context->audioChannels; channel++)
-			context->audioOut[n * context->audioChannels + channel] = (float) timeDomainOut[gWritePointer].r;
+		for(unsigned int channel = 0; channel < context->audioOutChannels; channel++)
+			context->audioOut[n * context->audioOutChannels + channel] = (float) timeDomainOut[gWritePointer].r;
 		gWritePointer++;
 	}
 }