diff projects/filter_FIR/render.cpp @ 108:3068421c0737 ultra-staging

Merged default into ultra-staging
author Giulio Moro <giuliomoro@yahoo.it>
date Tue, 18 Aug 2015 00:35:15 +0100
parents 3c3a1357657d
children 5433c83ce04e
line wrap: on
line diff
--- a/projects/filter_FIR/render.cpp	Mon Jun 08 01:07:48 2015 +0100
+++ b/projects/filter_FIR/render.cpp	Tue Aug 18 00:35:15 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 <NE10.h>					// neon library
 #include "SampleData.h"
 #include "FIRfilter.h"
@@ -25,8 +22,7 @@
 ne10_uint32_t blockSize;
 ne10_float32_t *gFIRfilterState;
 
-void initialise_filter();
-
+void initialise_filter(BeagleRTContext *context);
 
 // Task for handling the update of the frequencies using the matrix
 AuxiliaryTask gTriggerSamplesTask;
@@ -34,10 +30,7 @@
 bool initialise_trigger();
 void trigger_samples();
 
-int gPeriodSize;			// Period size in sensor frames
-
-
-// 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.
 //
@@ -46,20 +39,15 @@
 //
 // 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
 	gSampleData = *(SampleData *)userData;
 
 	gReadPtr = -1;
-	gPeriodSize = numMatrixFramesPerPeriod;
 
-	initialise_filter();
+	initialise_filter(context);
 
 	// Initialise auxiliary tasks
 	if(!initialise_trigger())
@@ -73,10 +61,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 in = 0;
 
 		// If triggered...
@@ -91,21 +78,21 @@
 
 	ne10_fir_float_neon(&gFIRfilter, gFIRfilterIn, gFIRfilterOut, blockSize);
 
-	for(int n = 0; n < numAudioFrames; n++) {
-		for(int channel = 0; channel < gNumAudioChannels; channel++)
-				audioOut[n * gNumAudioChannels + channel] = gFIRfilterOut[n];	// ...and put it in both left and right channel
+	for(unsigned int n = 0; n < context->audioFrames; n++) {
+		for(unsigned int channel = 0; channel < context->audioChannels; channel++)
+				context->audioOut[n * context->audioChannels + channel] = gFIRfilterOut[n];	// ...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 NE10 data structures to define FIR filter
 
-void initialise_filter()
+void initialise_filter(BeagleRTContext *context)
 {
-	blockSize = 2*gPeriodSize;
+	blockSize = context->audioFrames;
 	gFIRfilterState	= (ne10_float32_t *) NE10_MALLOC ((FILTER_TAP_NUM+blockSize-1) * sizeof (ne10_float32_t));
 	gFIRfilterIn = (ne10_float32_t *) NE10_MALLOC (blockSize * sizeof (ne10_float32_t));
 	gFIRfilterOut = (ne10_float32_t *) NE10_MALLOC (blockSize * sizeof (ne10_float32_t));
@@ -118,7 +105,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");
@@ -161,10 +148,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;