diff core/default_libpd_render.cpp @ 537:bfcbeb437869 API-update

Updated RTAudioSettings with in/out, ported some examples and libpd
author Giulio Moro <giuliomoro@yahoo.it>
date Fri, 24 Jun 2016 01:36:07 +0100
parents 485913c58a61
children
line wrap: on
line diff
--- a/core/default_libpd_render.cpp	Thu Jun 23 18:17:35 2016 +0100
+++ b/core/default_libpd_render.cpp	Fri Jun 24 01:36:07 2016 +0100
@@ -136,9 +136,13 @@
 		printf("Error file %s/%s not found. The %s file should be your main patch.\n", folder, file, file);
 		return false;
 	}
-
+	if(context->analogInChannels != context->analogOutChannels ||
+			context->audioInChannels != context->audioOutChannels){
+		printf("This project requires the number of inputs and the number of outputs to be the same\n");
+		return false;
+	}
 	// analog setup
-	gAnalogChannelsInUse = context->analogChannels;
+	gAnalogChannelsInUse = context->analogInChannels;
 
 	// digital setup
 	dcm.setCallback(sendDigitalMessage);
@@ -305,27 +309,27 @@
 		float* p0;
 		float* p1;
 		for (j = 0, p0 = gInBuf; j < gLibpdBlockSize; j++, p0++) {
-			for (k = 0, p1 = p0; k < context->audioChannels; k++, p1 += gLibpdBlockSize) {
+			for (k = 0, p1 = p0; k < context->audioInChannels; k++, p1 += gLibpdBlockSize) {
 				*p1 = audioRead(context, audioFrameBase + j, k);
 			}
 		}
 		// then analogs
 		// this loop resamples by ZOH, as needed, using m
-		if(context->analogChannels == 8 ){ //hold the value for two frames
+		if(context->analogInChannels == 8 ){ //hold the value for two frames
 			for (j = 0, p0 = gInBuf; j < gLibpdBlockSize; j++, p0++) {
 				for (k = 0, p1 = p0 + gLibpdBlockSize * gFirstAnalogChannel; k < gAnalogChannelsInUse; ++k, p1 += gLibpdBlockSize) {
 					unsigned int analogFrame = (audioFrameBase + j) / 2;
 					*p1 = analogRead(context, analogFrame, k);
 				}
 			}
-		} else if(context->analogChannels == 4){ //write every frame
+		} else if(context->analogInChannels == 4){ //write every frame
 			for (j = 0, p0 = gInBuf; j < gLibpdBlockSize; j++, p0++) {
 				for (k = 0, p1 = p0 + gLibpdBlockSize * gFirstAnalogChannel; k < gAnalogChannelsInUse; ++k, p1 += gLibpdBlockSize) {
 					unsigned int analogFrame = audioFrameBase + j;
 					*p1 = analogRead(context, analogFrame, k);
 				}
 			}
-		} else if(context->analogChannels == 2){ //drop every other frame
+		} else if(context->analogInChannels == 2){ //drop every other frame
 			for (j = 0, p0 = gInBuf; j < gLibpdBlockSize; j++, p0++) {
 				for (k = 0, p1 = p0 + gLibpdBlockSize * gFirstAnalogChannel; k < gAnalogChannelsInUse; ++k, p1 += gLibpdBlockSize) {
 					unsigned int analogFrame = (audioFrameBase + j) * 2;
@@ -369,7 +373,7 @@
 
 		//audio
 		for (j = 0, p0 = gOutBuf; j < gLibpdBlockSize; j++, p0++) {
-			for (k = 0, p1 = p0; k < context->audioChannels; k++, p1 += gLibpdBlockSize) {
+			for (k = 0, p1 = p0; k < context->audioOutChannels; k++, p1 += gLibpdBlockSize) {
 				audioWrite(context, audioFrameBase + j, k, *p1);
 			}
 		}
@@ -383,23 +387,23 @@
 
 
 		//analog
-		if(context->analogChannels == 8){
+		if(context->analogOutChannels == 8){
 			for (j = 0, p0 = gOutBuf; j < gLibpdBlockSize; j += 2, p0 += 2) { //write every two frames
 				unsigned int analogFrame = (audioFrameBase + j) / 2;
 				for (k = 0, p1 = p0 + gLibpdBlockSize * gFirstAnalogChannel; k < gAnalogChannelsInUse; k++, p1 += gLibpdBlockSize) {
 					analogWriteOnce(context, analogFrame, k, *p1);
 				}
 			}
-		} else if(context->analogChannels == 4){ //write every frame
+		} else if(context->analogOutChannels == 4){ //write every frame
 			for (j = 0, p0 = gOutBuf; j < gLibpdBlockSize; ++j, ++p0) {
 				unsigned int analogFrame = (audioFrameBase + j);
-				for (k = 0, p1 = p0  + gLibpdBlockSize * context->audioChannels; k < gAnalogChannelsInUse; k++, p1 += gLibpdBlockSize) {
+				for (k = 0, p1 = p0  + gLibpdBlockSize * gFirstAnalogChannel; k < gAnalogChannelsInUse; k++, p1 += gLibpdBlockSize) {
 					analogWriteOnce(context, analogFrame, k, *p1);
 				}
 			}
-		} else if(context->analogChannels == 2){ //write every frame twice
+		} else if(context->analogOutChannels == 2){ //write every frame twice
 			for (j = 0, p0 = gOutBuf; j < gLibpdBlockSize; j++, p0++) {
-				for (k = 0, p1 = p0 + gLibpdBlockSize * context->audioChannels; k < gAnalogChannelsInUse; k++, p1 += gLibpdBlockSize) {
+				for (k = 0, p1 = p0 + gLibpdBlockSize * gFirstAnalogChannel; k < gAnalogChannelsInUse; k++, p1 += gLibpdBlockSize) {
 					int analogFrame = audioFrameBase * 2 + j * 2;
 					analogWriteOnce(context, analogFrame, k, *p1);
 					analogWriteOnce(context, analogFrame + 1, k, *p1);