diff projects/d-box/render.cpp @ 14:06f93bef7dd2

Updated remaining examples to new API
author andrewm
date Fri, 23 Jan 2015 15:35:10 +0000
parents 8a575ba3ab52
children 42a683058b6a
line wrap: on
line diff
--- a/projects/d-box/render.cpp	Fri Jan 23 15:17:09 2015 +0000
+++ b/projects/d-box/render.cpp	Fri Jan 23 15:35:10 2015 +0000
@@ -29,7 +29,6 @@
 extern bool gIsLoading;
 extern bool gAudioIn;
 extern int gPeriodSize;
-int gChannels = 2;
 
 float *gOscillatorBuffer1, *gOscillatorBuffer2;
 float *gOscillatorBufferRead, *gOscillatorBufferWrite;
@@ -131,26 +130,34 @@
 			uint16_t *matrixIn, uint16_t *matrixOut);
 #endif
 
-bool initialise_render(int numChannels, int numMatrixFramesPerPeriod, int numAudioFramesPerPeriod, float matrixSampleRate, float audioSampleRate, void *userData) {
-	gChannels = numChannels;
+bool initialise_render(int numMatrixChannels, int numAudioChannels,
+					   int numMatrixFramesPerPeriod,
+					   int numAudioFramesPerPeriod,
+					   float matrixSampleRate, float audioSampleRate,
+					   void *userData) {
 	int oscBankHopSize = *(int *)userData;
 
+	if(numMatrixChannels != 8) {
+		printf("Error: D-Box needs matrix enabled with 8 channels.\n");
+		return false;
+	}
+
 	// Allocate two buffers for rendering oscillator bank samples
 	// One will be used for writing in the background while the other is used for reading
 	// on the audio thread. 8-byte alignment needed for the NEON code.
-	if(posix_memalign((void **)&gOscillatorBuffer1, 8, oscBankHopSize * gChannels * sizeof(float))) {
+	if(posix_memalign((void **)&gOscillatorBuffer1, 8, oscBankHopSize * gNumAudioChannels * sizeof(float))) {
 		printf("Error allocating render buffers\n");
 		return false;
 	}
-	if(posix_memalign((void **)&gOscillatorBuffer2, 8, oscBankHopSize * gChannels * sizeof(float))) {
+	if(posix_memalign((void **)&gOscillatorBuffer2, 8, oscBankHopSize * gNumAudioChannels * sizeof(float))) {
 		printf("Error allocating render buffers\n");
 		return false;
 	}
 	gOscillatorBufferWrite	= gOscillatorBuffer1;
 	gOscillatorBufferRead	= gOscillatorBuffer2;
 
-	memset(gOscillatorBuffer1, 0, oscBankHopSize * gChannels * sizeof(float));
-	memset(gOscillatorBuffer2, 0, oscBankHopSize * gChannels * sizeof(float));
+	memset(gOscillatorBuffer1, 0, oscBankHopSize * gNumAudioChannels * sizeof(float));
+	memset(gOscillatorBuffer2, 0, oscBankHopSize * gNumAudioChannels * sizeof(float));
 
 	// Initialise the dynamic wavetable used by the oscillator bank
 	// It should match the size of the static one already allocated in the OscillatorBank object
@@ -222,10 +229,10 @@
 
 	if(gOscBanks[gCurrentOscBank]->state==bank_playing)
 	{
-		assert(gChannels == 2);
+		assert(gNumAudioChannels == 2);
 
 #ifdef OLD_OSCBANK
-		memset(audioOut, 0, numAudioFrames * gChannels * sizeof(float));
+		memset(audioOut, 0, numAudioFrames * gNumAudioChannels * sizeof(float));
 
 		/* Render the oscillator bank. The oscillator bank function is written in NEON assembly
 		 * and it strips out all extra checks, so find out in advance whether we can render a whole
@@ -262,7 +269,7 @@
 									 gOscBanks[gCurrentOscBank]->oscillatorAmplitudeDerivatives,
 									 gDynamicWavetable/*gOscBanks[gCurrentOscBank]->lookupTable*/);
 				framesRemaining -= gOscBanks[gCurrentOscBank]->hopCounter;
-				audioOutWithOffset += gChannels * gOscBanks[gCurrentOscBank]->hopCounter;
+				audioOutWithOffset += gNumAudioChannels * gOscBanks[gCurrentOscBank]->hopCounter;
 				gOscBanks[gCurrentOscBank]->sampleCount += gOscBanks[gCurrentOscBank]->hopCounter;
 				gOscBanks[gCurrentOscBank]->nextHop();
 			}
@@ -562,7 +569,7 @@
 		gOscillatorNeedsRender = false;
 
 		/* Render one frame into the write buffer */
-		memset(gOscillatorBufferWrite, 0, gOscBanks[gCurrentOscBank]->hopCounter * gChannels * sizeof(float));
+		memset(gOscillatorBufferWrite, 0, gOscBanks[gCurrentOscBank]->hopCounter * gNumAudioChannels * sizeof(float));
 
 		oscillator_bank_neon(gOscBanks[gCurrentOscBank]->hopCounter, gOscillatorBufferWrite,
 							 gOscBanks[gCurrentOscBank]->actPartNum, gOscBanks[gCurrentOscBank]->lookupTableSize,
@@ -572,7 +579,7 @@
 							 gOscBanks[gCurrentOscBank]->oscillatorAmplitudeDerivatives,
 							 /*gOscBanks[gCurrentOscBank]->lookupTable*/gDynamicWavetable);
 
-		gOscillatorBufferWriteCurrentSize = gOscBanks[gCurrentOscBank]->hopCounter * gChannels;
+		gOscillatorBufferWriteCurrentSize = gOscBanks[gCurrentOscBank]->hopCounter * gNumAudioChannels;
 
 		/* Update the pitch right before the hop
 		 * Total CV range +/- N_OCT octaves