diff projects/oscillator_bank/render.cpp @ 45:579c86316008 newapi

Major API overhaul. Moved to a single data structure for handling render functions. Functionally, generally similar except for scheduling within PRU loop function, which now uses interrupts from the PRU rather than polling. This requires an updated kernel.
author andrewm
date Thu, 28 May 2015 14:35:55 -0400
parents 06f93bef7dd2
children 643cbee74eda
line wrap: on
line diff
--- a/projects/oscillator_bank/render.cpp	Wed May 13 12:23:37 2015 +0100
+++ b/projects/oscillator_bank/render.cpp	Thu May 28 14:35:55 2015 -0400
@@ -58,11 +58,11 @@
 // in from the call to initAudio().
 //
 // Return true on success; returning false halts the program.
-bool initialise_render(int numMatrixChannels, int numAudioChannels,
+bool initialise_render(int numMatrixChannels,  int numDigitalChannels, int numAudioChannels,
 					   int numMatrixFramesPerPeriod,
 					   int numAudioFramesPerPeriod,
 					   float matrixSampleRate, float audioSampleRate,
-					   void *userData)
+					   void *userData, RTAudioSettings* settings)
 {
 	srandom(time(NULL));
 
@@ -125,10 +125,28 @@
 		gDFrequencies[n] = gDAmplitudes[n] = 0.0;
 	}
 
+	increment = 0;
+	freq = 440.0;
+
+	for(int n = 0; n < gNumOscillators; n++) {
+		// Update the frequencies to a regular spread, plus a small amount of randomness
+		// to avoid weird phase effects
+		float randScale = 0.99 + .02 * (float)random() / (float)RAND_MAX;
+		float newFreq = freq * randScale;
+
+		// For efficiency, frequency is expressed in change in wavetable position per sample, not Hz or radians
+		gFrequencies[n] = newFreq * (float)gWavetableLength / audioSampleRate;
+
+		freq += increment;
+	}
+
 	// Initialise auxiliary tasks
 	if((gFrequencyUpdateTask = createAuxiliaryTaskLoop(&recalculate_frequencies, 90, "beaglert-update-frequencies")) == 0)
 		return false;
 
+	for(int n = 0; n < gNumOscillators; n++)
+		rt_printf("%f\n", gFrequencies[n]);
+
 	gAudioSampleRate = audioSampleRate;
 	gSampleCount = 0;
 
@@ -140,8 +158,8 @@
 // ADCs and DACs (if available). If only audio is available, numMatrixFrames
 // will be 0.
 
-void render(int numMatrixFrames, int numAudioFrames, float *audioIn, float *audioOut,
-			uint16_t *matrixIn, uint16_t *matrixOut)
+void render(int numAnalogFrames, int numAudioFrames, int numDigitalFrames, float *audioIn, float *audioOut,
+		float *analogIn, float *analogOut, uint32_t *digital)
 {
 	// Initialise buffer to 0
 	memset(audioOut, 0, 2 * numAudioFrames * sizeof(float));
@@ -153,10 +171,10 @@
 			gDFrequencies, gDAmplitudes,
 			gWavetable);
 
-	if(numMatrixFrames != 0 && (gSampleCount += numAudioFrames) >= 128) {
+	if(numAnalogFrames != 0 && (gSampleCount += numAudioFrames) >= 128) {
 		gSampleCount = 0;
-		gNewMinFrequency = map(matrixIn[0], 0, MATRIX_MAX, 20.0f, 8000.0f);
-		gNewMaxFrequency = map(matrixIn[1], 0, MATRIX_MAX, 20.0f, 8000.0f);
+		gNewMinFrequency = map(analogIn[0], 0, 1.0, 1000.0f, 8000.0f);
+		gNewMaxFrequency = map(analogIn[1], 0, 1.0, 1000.0f, 8000.0f);
 
 		// Make sure max >= min
 		if(gNewMaxFrequency < gNewMinFrequency) {
@@ -166,7 +184,7 @@
 		}
 
 		// Request that the lower-priority task run at next opportunity
-		scheduleAuxiliaryTask(gFrequencyUpdateTask);
+		//scheduleAuxiliaryTask(gFrequencyUpdateTask);
 	}
 }