diff examples/04-Audio/measure-noisefloor/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 8fcfbfb32aa0
children
line wrap: on
line diff
--- a/examples/04-Audio/measure-noisefloor/render.cpp	Fri Jun 24 13:19:52 2016 +0100
+++ b/examples/04-Audio/measure-noisefloor/render.cpp	Fri Jun 24 13:32:07 2016 +0100
@@ -49,6 +49,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;
+	}
+
 	// Clear the filter data structures
 	for(int i = 0; i < 10; i++) {
 		gReadBufferPointers[i] = gWriteBufferPointers[i] = 0;
@@ -78,10 +86,10 @@
 	
 	for(unsigned int n = 0; n < context->audioFrames; n++) {
 		// Store audio inputs in buffer
-		for(unsigned int ch = 0; ch < context->audioChannels; ch++) {
+		for(unsigned int ch = 0; ch < context->audioOutChannels; ch++) {
 			if(gWriteBufferPointers[ch] < gBufferSize) {
 				gWriteBuffers[ch][gWriteBufferPointers[ch]] = 
-					context->audioIn[n * context->audioChannels + ch];
+					context->audioIn[n * context->audioOutChannels + ch];
 				gWriteBufferPointers[ch]++;
 				if(gWriteBufferPointers[ch] >= gBufferSize)
 					bufferIsFull = true;
@@ -89,13 +97,13 @@
 		}
 	}
 	
-	if(context->analogChannels != 0) {
+	if(context->analogOutChannels != 0) {
 		for(unsigned int n = 0; n < context->analogFrames; n++) {
 			// Store analog inputs in buffer, starting at channel 2
-			for(unsigned int ch = 0; ch < context->analogChannels; ch++) {
+			for(unsigned int ch = 0; ch < context->analogOutChannels; ch++) {
 				if(gWriteBufferPointers[ch + 2] < gBufferSize) {
 					gWriteBuffers[ch + 2][gWriteBufferPointers[ch + 2]] = 
-						context->analogIn[n * context->analogChannels + ch];
+						context->analogIn[n * context->analogOutChannels + ch];
 					gWriteBufferPointers[ch + 2]++;
 					if(gWriteBufferPointers[ch + 2] >= gBufferSize)
 						bufferIsFull = true;
@@ -103,7 +111,7 @@
 				
 				// Set all analog outputs to halfway point so they can be more
 				// easily measured for noise
-				context->analogOut[n * context->analogChannels + ch] = 0.5;
+				context->analogOut[n * context->analogOutChannels + ch] = 0.5;
 			}
 		}	
 	}