diff examples/11-Extras/gpioAnalogLoopbackTest/render.cpp @ 543:8f8809c77dda prerelease

updated basics, digital, instruments, extras examples
author chnrx <chris.heinrichs@gmail.com>
date Fri, 24 Jun 2016 13:19:52 +0100
parents 8fcfbfb32aa0
children
line wrap: on
line diff
--- a/examples/11-Extras/gpioAnalogLoopbackTest/render.cpp	Fri Jun 24 13:00:31 2016 +0100
+++ b/examples/11-Extras/gpioAnalogLoopbackTest/render.cpp	Fri Jun 24 13:19:52 2016 +0100
@@ -25,19 +25,26 @@
 int gDigitalOutLoopDelay;
 bool setup(BelaContext *context, void *userData)
 {
+	// For this test we need the same amount of audio and analog input and output channels
+	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;
+	}
+
 	rt_printf("For this test you need the following connections:\n"
 			"analog%d out->digital%d in, analog%d out->analog%d in, "
 			"digital%d out -> digital%d in, digital%d out-> analog%d in\n",
 			gAnalogOutCh, gDigitalInACh, gAnalogOutCh, 0, gDigitalOutCh, gDigitalInDCh, gDigitalOutCh, 0);
 	rt_printf("Running test with %d analog channels and a buffer size of %d\n",
-			context->analogChannels, context->audioFrames);
+			context->analogInChannels, context->audioFrames);
 
 	for(unsigned int n = 0; n < context->digitalFrames; n++){
 		pinMode(context, n, gDigitalInACh, INPUT);
 		pinMode(context, n, gDigitalInDCh, INPUT);
 		pinMode(context, n, gDigitalOutCh, OUTPUT);
 	}
-	switch (context->analogChannels){
+	switch (context->analogOutChannels){
 		case 2:
 			gAnalogOutLoopDelay = context->audioFrames*2 + 3;
 			gDigitalOutLoopDelay = context->audioFrames*2 + 2;
@@ -96,10 +103,10 @@
 		static bool analog0In = false;
 		static bool digitalAIn = false;
 		static int count = 0;
-		bool doReadWrite = context->analogChannels<=4 ? true : ((context->analogChannels == 8) && (n&1)==0);
+		bool doReadWrite = context->analogInChannels<=4 ? true : ((context->analogInChannels == 8) && (n&1)==0);
 		if(doReadWrite){
 			digitalAIn = digitalRead(context, n, gDigitalInACh);
-			switch(context->analogChannels){
+			switch(context->analogInChannels){
 			case 8:
 				analog0In = analogRead(context, n/2, 0) > 0.5;
 				analogWrite(context, n/2, analogOut, writePattern[outPointer]);
@@ -150,20 +157,20 @@
 		bool doReadWrite = false;
 		static bool pastAnalog1In = false;
 		digitalWriteOnce(context, n, gDigitalOutCh,  writePattern[digitalOutPointer]);
-		if(context->analogChannels == 8){
+		if(context->analogInChannels == 8){
 			if((n&1) == 0){ //do it every other sample
 				pastAnalog1In = analogRead(context, n/2, 1) > 0.5;
 				digitalDIn = digitalRead(context, n, gDigitalInDCh);
 				doReadWrite = true;
 			}
 		}
-		if(context->analogChannels == 4){
+		if(context->analogInChannels == 4){
 			pastAnalog1In = analogRead(context, n, 1) > 0.5;
 			digitalDIn = digitalRead(context, n, gDigitalInDCh);
 			digitalWriteOnce(context, n, gDigitalOutCh,  writePattern[digitalOutPointer]);
 			doReadWrite = true;
 		}
-		if(context->analogChannels == 2){
+		if(context->analogInChannels == 2){
 			pastAnalog1In = analogRead(context, n * 2, 1) > 0.5;
 			digitalDIn = digitalRead(context, n, gDigitalInDCh);
 			digitalWriteOnce(context, n, gDigitalOutCh,  writePattern[digitalOutPointer]);
@@ -198,12 +205,12 @@
 void cleanup(BelaContext *context, void *userData)
 {
 	if(anaErrorCount == 0 && digErrorCount == 0){
-		rt_printf("Test was succesful with %d analog channels and a buffer size of %d\n", context->analogChannels, context->audioFrames);
+		rt_printf("Test was succesful with %d analog channels and a buffer size of %d\n", context->analogInChannels, context->audioFrames);
 	} else {
 		rt_printf("------------------------\n%danalog %ddigital errors over %dsamples while running test with ",
 				anaErrorCount, digErrorCount, context->audioFramesElapsed);
 		rt_printf("%d analog channels and a buffer size of %d \n\n\n",
-				context->analogChannels, context->audioFrames);
+				context->analogInChannels, context->audioFrames);
 		exit(1);
 	}
 }