diff projects/samples/render.cpp @ 67:472e892c6e41

Merge newapi into default
author Andrew McPherson <a.mcpherson@qmul.ac.uk>
date Fri, 17 Jul 2015 15:28:18 +0100
parents 3c3a1357657d
children ac8eb07afcf5
line wrap: on
line diff
--- a/projects/samples/render.cpp	Sun Feb 08 00:20:01 2015 +0000
+++ b/projects/samples/render.cpp	Fri Jul 17 15:28:18 2015 +0100
@@ -6,11 +6,8 @@
  */
 
 
-#include "../../include/render.h"
-#include "../../include/RTAudio.h"	// to schedule lower prio parallel process
-#include <rtdk.h>
+#include <BeagleRT.h>
 #include <cmath>
-#include <stdio.h>
 #include "SampleData.h"
 
 SampleData gSampleData;	// User defined structure to get complex data from main
@@ -22,7 +19,7 @@
 bool initialise_trigger();
 void trigger_samples();
 
-// initialise_render() is called once before the audio rendering starts.
+// setup() is called once before the audio rendering starts.
 // Use it to perform any initialisation and allocation which is dependent
 // on the period size or sample rate.
 //
@@ -31,11 +28,7 @@
 //
 // Return true on success; returning false halts the program.
 
-bool initialise_render(int numMatrixChannels, int numAudioChannels,
-					   int numMatrixFramesPerPeriod,
-					   int numAudioFramesPerPeriod,
-					   float matrixSampleRate, float audioSampleRate,
-					   void *userData)
+bool setup(BeagleRTContext *context, void *userData)
 {
 
 	// Retrieve a parameter passed in from the initAudio() call
@@ -55,10 +48,9 @@
 // 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(BeagleRTContext *context, void *userData)
 {
-	for(int n = 0; n < numAudioFrames; n++) {
+	for(unsigned int n = 0; n < context->audioFrames; n++) {
 		float out = 0;
 
 		// If triggered...
@@ -68,12 +60,12 @@
 		if(gReadPtr >= gSampleData.sampleLen)
 			gReadPtr = -1;
 
-		for(int channel = 0; channel < gNumAudioChannels; channel++)
-			audioOut[n * gNumAudioChannels + channel] = out;	// ...and put it in both left and right channel
+		for(unsigned int channel = 0; channel < context->audioChannels; channel++)
+			context->audioOut[n * context->audioChannels + channel] = out;	// ...and put it in both left and right channel
 	}
 
 	// Request that the lower-priority task run at next opportunity
-	scheduleAuxiliaryTask(gTriggerSamplesTask);
+	BeagleRT_scheduleAuxiliaryTask(gTriggerSamplesTask);
 }
 
 // Initialise the auxiliary task
@@ -81,7 +73,7 @@
 
 bool initialise_trigger()
 {
-	if((gTriggerSamplesTask = createAuxiliaryTaskLoop(&trigger_samples, 50, "beaglert-trigger-samples")) == 0)
+	if((gTriggerSamplesTask = BeagleRT_createAuxiliaryTask(&trigger_samples, 50, "beaglert-trigger-samples")) == 0)
 		return false;
 
 	rt_printf("Press 'a' to trigger sample, 's' to stop\n");
@@ -124,10 +116,10 @@
 
 
 
-// cleanup_render() is called once at the end, after the audio has stopped.
-// Release any resources that were allocated in initialise_render().
+// cleanup() is called once at the end, after the audio has stopped.
+// Release any resources that were allocated in setup().
 
-void cleanup_render()
+void cleanup(BeagleRTContext *context, void *userData)
 {
 	delete[] gSampleData.samples;
 }