changeset 56:3c3a1357657d newapi

Further API update to name three primary functions setup(), render() and cleanup(). Changed include paths so now can #include <BeagleRT.h>. Removed stale pru_rtaudio.bin file as this is now done as pru_rtaudio_bin.h. Updated examples to new API and fixed minor compiler warnings along the way. Network example needs further attention to compile.
author andrewm
date Wed, 15 Jul 2015 12:10:51 +0100
parents 41d24dba6b74
children 72726dd4f66c
files .cproject core/PRU.cpp core/RTAudio.cpp include/BeagleRT.h include/Utilities.h projects/analogDigitalDemo/main.cpp projects/analogDigitalDemo/render.cpp projects/audio_in_FFT/main.cpp projects/audio_in_FFT/render.cpp projects/basic/main.cpp projects/basic/render.cpp projects/basic_analog_output/main.cpp projects/basic_analog_output/render.cpp projects/basic_network/main.cpp projects/basic_network/render.cpp projects/basic_passthru/main.cpp projects/basic_passthru/render.cpp projects/cape_test/main.cpp projects/cape_test/render.cpp projects/d-box/main.cpp projects/d-box/render.cpp projects/filter_FIR/main.cpp projects/filter_FIR/render.cpp projects/filter_IIR/main.cpp projects/filter_IIR/render.cpp projects/oscillator_bank/main.cpp projects/oscillator_bank/render.cpp projects/samples/main.cpp projects/samples/render.cpp projects/tank_wars/main.cpp projects/tank_wars/render.cpp pru_rtaudio.bin
diffstat 32 files changed, 186 insertions(+), 197 deletions(-) [+]
line wrap: on
line diff
--- a/.cproject	Mon Jun 15 18:16:00 2015 +0100
+++ b/.cproject	Wed Jul 15 12:10:51 2015 +0100
@@ -34,6 +34,7 @@
 									<listOptionValue builtIn="false" value="/import/teaching/ECS732/arm-gcc/arm-linux-gnueabihf/include"/>
 									<listOptionValue builtIn="false" value="/import/teaching/ECS732/arm-gcc/arm-linux-gnueabihf/include/xenomai/include"/>
 									<listOptionValue builtIn="false" value="/usr/arm-linux-gnueabihf/include/ne10"/>
+									<listOptionValue builtIn="false" value="&quot;${workspace_loc:/BeagleRT/include}&quot;"/>
 								</option>
 								<option id="gnu.cpp.compiler.option.other.other.1516989263" name="Other flags" superClass="gnu.cpp.compiler.option.other.other" value="-c -fmessage-length=0 -Wpointer-arith -Wunused-result -D_GNU_SOURCE -D_REENTRANT -D__XENO__" valueType="string"/>
 								<option id="gnu.cpp.compiler.option.warnings.allwarn.1392851614" name="All warnings (-Wall)" superClass="gnu.cpp.compiler.option.warnings.allwarn" value="true" valueType="boolean"/>
@@ -49,6 +50,7 @@
 									<listOptionValue builtIn="false" value="/import/teaching/ECS732/arm-gcc/arm-linux-gnueabihf/include"/>
 									<listOptionValue builtIn="false" value="/import/teaching/ECS732/arm-gcc/arm-linux-gnueabihf/include/xenomai/include"/>
 									<listOptionValue builtIn="false" value="/usr/arm-linux-gnueabihf/include/ne10"/>
+									<listOptionValue builtIn="false" value="&quot;${workspace_loc:/BeagleRT/include}&quot;"/>
 								</option>
 								<option id="gnu.c.compiler.option.misc.other.835792865" name="Other flags" superClass="gnu.c.compiler.option.misc.other" value="-c -fmessage-length=0 -Wpointer-arith -Wunused-result  -D_GNU_SOURCE -D_REENTRANT -D__XENO__ -std=gnu99" valueType="string"/>
 								<option id="gnu.c.compiler.option.warnings.allwarn.1145989346" name="All warnings (-Wall)" superClass="gnu.c.compiler.option.warnings.allwarn" value="true" valueType="boolean"/>
@@ -84,6 +86,7 @@
 									<listOptionValue builtIn="false" value="/usr/arm-linux-gnueabihf/include/xenomai/include"/>
 									<listOptionValue builtIn="false" value="/import/teaching/ECS732/arm-gcc/arm-linux-gnueabihf/include"/>
 									<listOptionValue builtIn="false" value="/usr/arm-linux-gnueabihf/include/ne10"/>
+									<listOptionValue builtIn="false" value="&quot;${workspace_loc:/BeagleRT/include}&quot;"/>
 								</option>
 								<inputType id="cdt.managedbuild.tool.gnu.assembler.input.1788972942" superClass="cdt.managedbuild.tool.gnu.assembler.input"/>
 							</tool>
@@ -92,7 +95,7 @@
 					<sourceEntries>
 						<entry excluding="audio_routines_old.S" flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name="core"/>
 						<entry flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name="include"/>
-						<entry flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name="projects/cape_test"/>
+						<entry flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name="projects/basic"/>
 						<entry flags="VALUE_WORKSPACE_PATH" kind="sourcePath" name="source"/>
 					</sourceEntries>
 				</configuration>
@@ -123,10 +126,9 @@
 								<option id="gnu.cpp.compiler.exe.release.option.debugging.level.701035863" name="Debug Level" superClass="gnu.cpp.compiler.exe.release.option.debugging.level" value="gnu.cpp.compiler.debugging.level.none" valueType="enumerated"/>
 								<option id="gnu.cpp.compiler.option.include.paths.823255770" name="Include paths (-I)" superClass="gnu.cpp.compiler.option.include.paths" valueType="includePath">
 									<listOptionValue builtIn="false" value="/usr/xenomai/include"/>
-									<listOptionValue builtIn="false" value="/import/teaching/ECS732/arm-gcc/arm-linux-gnueabihf/include/xenomai/include"/>
 									<listOptionValue builtIn="false" value="/usr/arm-linux-gnueabihf/include/xenomai/include"/>
-									<listOptionValue builtIn="false" value="/import/teaching/ECS732/arm-gcc/arm-linux-gnueabihf/include"/>
 									<listOptionValue builtIn="false" value="/usr/arm-linux-gnueabihf/include/ne10"/>
+									<listOptionValue builtIn="false" value="&quot;${workspace_loc:/BeagleRT/include}&quot;"/>
 								</option>
 								<option id="gnu.cpp.compiler.option.dialect.std.776548502" name="Language standard" superClass="gnu.cpp.compiler.option.dialect.std" value="gnu.cpp.compiler.dialect.default" valueType="enumerated"/>
 								<option id="gnu.cpp.compiler.option.other.other.398422461" name="Other flags" superClass="gnu.cpp.compiler.option.other.other" value="-c -fmessage-length=0 -U_FORTIFY_SOURCE" valueType="string"/>
@@ -138,9 +140,8 @@
 								<option id="gnu.c.compiler.option.include.paths.1269113471" name="Include paths (-I)" superClass="gnu.c.compiler.option.include.paths" valueType="includePath">
 									<listOptionValue builtIn="false" value="/usr/xenomai/include"/>
 									<listOptionValue builtIn="false" value="/usr/arm-linux-gnueabihf/include/xenomai/include"/>
-									<listOptionValue builtIn="false" value="/import/teaching/ECS732/arm-gcc/arm-linux-gnueabihf/include"/>
-									<listOptionValue builtIn="false" value="/import/teaching/ECS732/arm-gcc/arm-linux-gnueabihf/include/xenomai/include"/>
 									<listOptionValue builtIn="false" value="/usr/arm-linux-gnueabihf/include/ne10"/>
+									<listOptionValue builtIn="false" value="&quot;${workspace_loc:/BeagleRT/include}&quot;"/>
 								</option>
 								<option id="gnu.c.compiler.option.include.files.40806287" name="Include files (-include)" superClass="gnu.c.compiler.option.include.files"/>
 								<option id="gnu.c.compiler.option.preprocessor.undef.symbol.980935416" name="Undefined symbols (-U)" superClass="gnu.c.compiler.option.preprocessor.undef.symbol" valueType="undefDefinedSymbols">
@@ -155,9 +156,7 @@
 									<listOptionValue builtIn="false" value="/usr/arm-linux-gnueabihf/lib"/>
 									<listOptionValue builtIn="false" value="/usr/arm-linux-gnueabihf/lib/xenomai"/>
 									<listOptionValue builtIn="false" value="/usr/local/linaro/arm-linux-gnueabihf/include/xenomai/lib"/>
-									<listOptionValue builtIn="false" value="/import/teaching/ECS732/arm-gcc/arm-linux-gnueabihf/lib"/>
 									<listOptionValue builtIn="false" value="/usr/lib/arm-linux-gnueabihf"/>
-									<listOptionValue builtIn="false" value="/import/teaching/ECS732/arm-gcc/arm-linux-gnueabihf/lib/xenomai"/>
 								</option>
 								<option id="gnu.cpp.link.option.libs.1930118082" name="Libraries (-l)" superClass="gnu.cpp.link.option.libs" valueType="libs">
 									<listOptionValue builtIn="false" value="rt"/>
@@ -176,6 +175,9 @@
 								</inputType>
 							</tool>
 							<tool command="arm-linux-gnueabihf-as" id="cdt.managedbuild.tool.gnu.assembler.exe.release.2052985276" name="GCC Assembler" superClass="cdt.managedbuild.tool.gnu.assembler.exe.release">
+								<option id="gnu.both.asm.option.include.paths.1499955275" name="Include paths (-I)" superClass="gnu.both.asm.option.include.paths" valueType="includePath">
+									<listOptionValue builtIn="false" value="&quot;${workspace_loc:/BeagleRT/include}&quot;"/>
+								</option>
 								<inputType id="cdt.managedbuild.tool.gnu.assembler.input.1212659593" superClass="cdt.managedbuild.tool.gnu.assembler.input"/>
 							</tool>
 						</toolChain>
@@ -183,7 +185,7 @@
 					<sourceEntries>
 						<entry excluding="audio_routines_old.S" flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name="core"/>
 						<entry flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name="include"/>
-						<entry flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name="projects/cape_test"/>
+						<entry flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name="projects/basic"/>
 						<entry flags="VALUE_WORKSPACE_PATH" kind="sourcePath" name="source"/>
 					</sourceEntries>
 				</configuration>
--- a/core/PRU.cpp	Mon Jun 15 18:16:00 2015 +0100
+++ b/core/PRU.cpp	Wed Jul 15 12:10:51 2015 +0100
@@ -430,7 +430,6 @@
 	float *lastAnalogOutFrame;
 	uint32_t *digitalBuffer0, *digitalBuffer1, *lastDigitalBuffer;
 	uint32_t pru_audio_offset, pru_spi_offset;
-	int result;
 
 	// Allocate audio buffers
 	context->audioIn = (float *)malloc(2 * context->audioFrames * sizeof(float));
@@ -474,7 +473,9 @@
 	// uint32_t testCount = 0;
 	// RTIME startTime = rt_timer_read();
 
-#ifndef BEAGLERT_USE_XENOMAI_INTERRUPTS
+#ifdef BEAGLERT_USE_XENOMAI_INTERRUPTS
+	int result;
+#else
 	// Which buffer the PRU was last processing
 	uint32_t lastPRUBuffer = 0;
 #endif
--- a/core/RTAudio.cpp	Mon Jun 15 18:16:00 2015 +0100
+++ b/core/RTAudio.cpp	Wed Jul 15 12:10:51 2015 +0100
@@ -82,7 +82,7 @@
 // plus any latency inherent in the ADCs and DACs themselves.
 // useAnalog indicates whether to enable the ADC and DAC or just use the audio codec.
 // numAnalogChannels indicates how many ADC and DAC channels to use.
-// userData is an opaque pointer which will be passed through to the initialise_render()
+// userData is an opaque pointer which will be passed through to the setup()
 // function for application-specific use
 //
 // Returns 0 on success.
@@ -218,7 +218,7 @@
 	BeagleRT_setHeadphoneLevel(settings->headphoneLevel);
 
 	// Call the user-defined initialisation function
-	if(!initialise_render(&gContext, userData)) {
+	if(!setup(&gContext, userData)) {
 		cout << "Couldn't initialise audio rendering\n";
 		return 1;
 	}
@@ -403,7 +403,7 @@
 // Free any resources associated with PRU real-time audio
 void BeagleRT_cleanupAudio()
 {
-	cleanup_render(&gContext, gUserData);
+	cleanup(&gContext, gUserData);
 
 	// Clean up the auxiliary tasks
 	vector<InternalAuxiliaryTask*>::iterator it;
--- a/include/BeagleRT.h	Mon Jun 15 18:16:00 2015 +0100
+++ b/include/BeagleRT.h	Wed Jul 15 12:10:51 2015 +0100
@@ -157,7 +157,7 @@
  * \ingroup render
  * \brief Structure holding current audio and sensor settings and pointers to data buffers.
  *
- * This structure is passed to initialise_render(), render() and cleanup_render(). It is
+ * This structure is passed to setup(), render() and cleanup(). It is
  * initialised in BeagleRT_initAudio() based on the contents of the BeagleRTInitSettings
  * structure.
  */
@@ -251,7 +251,7 @@
 /** \ingroup auxtask
  *
  * Auxiliary task variable. Auxiliary tasks are created using createAuxiliaryTask() and
- * automatically cleaned up after cleanup_render() finishes.
+ * automatically cleaned up after cleanup() finishes.
  */
 typedef void* AuxiliaryTask;	// Opaque data type to keep track of aux tasks
 
@@ -285,14 +285,14 @@
  * \param context Data structure holding information on sample rates, numbers of channels,
  * frame sizes and other state. Note: the buffers for audio, analog and digital data will
  * \b not yet be available to use. Do not attempt to read or write audio or sensor data
- * in initialise_render().
+ * in setup().
  * \param userData An opaque pointer to an optional user-defined data structure. Whatever
  * is passed as the second argument to BeagleRT_initAudio() will appear here.
  *
  * \return true on success, or false if an error occurred. If no initialisation is
- * required, initialise_render() should return true.
+ * required, setup() should return true.
  */
-bool initialise_render(BeagleRTContext *context, void *userData);
+bool setup(BeagleRTContext *context, void *userData);
 
 /**
  * \brief User-defined callback function to process audio and sensor data.
@@ -304,9 +304,9 @@
  * \param context Data structure holding buffers for audio, analog and digital data. The
  * structure also holds information on numbers of channels, frame sizes and sample rates,
  * which are guaranteed to remain the same throughout the program and to match what was
- * passed to initialise_render().
+ * passed to setup().
  * \param userData An opaque pointer to an optional user-defined data structure. Will
- * be the same as the \c userData parameter passed to initialise_render().
+ * be the same as the \c userData parameter passed to setup().
  */
 void render(BeagleRTContext *context, void *userData);
 
@@ -314,18 +314,18 @@
  * \brief User-defined cleanup function which runs when the program finishes.
  *
  * This function is called by the system once after audio rendering has finished, before the
- * program quits. Use it to release any memory allocated in initialise_render() and to perform
- * any other required cleanup. If no initialisation is performed in initialise_render(), then
+ * program quits. Use it to release any memory allocated in setup() and to perform
+ * any other required cleanup. If no initialisation is performed in setup(), then
  * this function will usually be empty.
  *
  * \param context Data structure holding information on sample rates, numbers of channels,
  * frame sizes and other state. Note: the buffers for audio, analog and digital data will
  * no longer be available to use. Do not attempt to read or write audio or sensor data
- * in cleanup_render().
+ * in cleanup().
  * \param userData An opaque pointer to an optional user-defined data structure. Will
- * be the same as the \c userData parameter passed to initialise_render() and render().
+ * be the same as the \c userData parameter passed to setup() and render().
  */
-void cleanup_render(BeagleRTContext *context, void *userData);
+void cleanup(BeagleRTContext *context, void *userData);
 
 /** @} */
 
@@ -400,12 +400,12 @@
  *
  * This function prepares audio rendering in BeagleRT. It should be called from main() sometime
  * after command line option parsing has finished. It will initialise the rendering system, which
- * in the process will result in a call to the user-defined initialise_render() function.
+ * in the process will result in a call to the user-defined setup() function.
  *
  * \param settings Data structure holding system settings, including numbers of channels, frame sizes,
  * volume levels and other information.
  * \param userData An opaque pointer to a user-defined data structure which will be passed to
- * initialise_render(), render() and cleanup_render(). You can use this to pass custom information
+ * setup(), render() and cleanup(). You can use this to pass custom information
  * to the rendering functions, as an alternative to using global variables.
  *
  * \return 0 on success, or nonzero if an error occurred.
@@ -435,7 +435,7 @@
  *
  * This function should only be called after BeagleRT_stopAudio(). It will release any
  * internal resources for audio and sensor processing. In the process, it will call the
- * user-defined cleanup_render() function.
+ * user-defined cleanup() function.
  */
 void BeagleRT_cleanupAudio();
 
@@ -526,7 +526,7 @@
  * calculations which would take more than one audio frame length to process, or they could be
  * used to communicate with external hardware when that communication might block or be delayed.
  *
- * All auxiliary tasks used by the program should be created in initialise_render(). The tasks
+ * All auxiliary tasks used by the program should be created in setup(). The tasks
  * can then be scheduled at will within the render() function.
  *
  * @{
@@ -539,7 +539,7 @@
  *
  * This function creates a new auxiliary task which, when scheduled, runs the function specified
  * in the first argument. Note that the task does not run until scheduleAuxiliaryTask() is called.
- * Auxiliary tasks should be created in initialise_render() and never in render() itself.
+ * Auxiliary tasks should be created in setup() and never in render() itself.
  *
  * The second argument specifies the real-time priority. Valid values are between 0
  * and 99, and usually should be lower than \ref BEAGLERT_AUDIO_PRIORITY. Tasks with higher priority always
--- a/include/Utilities.h	Mon Jun 15 18:16:00 2015 +0100
+++ b/include/Utilities.h	Wed Jul 15 12:10:51 2015 +0100
@@ -16,8 +16,8 @@
 #define changeBit(word,bit,value) 	((clearBit((word),(bit))) | ((value) << (bit)))
 
 #if 1
-// Note: pinMode(), analogWrite() and digitalWrite() should be able to be called from initialise_render()
-// Likewise, thread launch should be able to be called from initialise_render()
+// Note: pinMode(), analogWrite() and digitalWrite() should be able to be called from setup()
+// Likewise, thread launch should be able to be called from setup()
 // Also, make volume change functions callable from render() thread -- as an aux task?
 
 float analogReadFrame(BeagleRTContext *context, int frame, int channel);
--- a/projects/analogDigitalDemo/main.cpp	Mon Jun 15 18:16:00 2015 +0100
+++ b/projects/analogDigitalDemo/main.cpp	Wed Jul 15 12:10:51 2015 +0100
@@ -14,11 +14,12 @@
 #include <libgen.h>
 #include <signal.h>
 #include <getopt.h>
-#include "../../include/BeagleRT.h"
 #include <unistd.h>
 #include <stdlib.h>
 #include <fcntl.h>
 
+#include <BeagleRT.h>
+
 using namespace std;
 
 // Handle Ctrl-C by requesting that the audio rendering stop
--- a/projects/analogDigitalDemo/render.cpp	Mon Jun 15 18:16:00 2015 +0100
+++ b/projects/analogDigitalDemo/render.cpp	Wed Jul 15 12:10:51 2015 +0100
@@ -4,14 +4,12 @@
  * Queen Mary, University of London
  */
 
-#include "../../include/BeagleRT.h"
-#include "../../include/Utilities.h"
+#include <BeagleRT.h>
+#include <Utilities.h>
 #include <cmath>
 #include <rtdk.h>
 
-/* TASK: declare any global variables you need here */
-
-// 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.
 //
@@ -20,7 +18,7 @@
 //
 // Return true on success; returning false halts the program.
 
-bool initialise_render(BeagleRTContext *context, void *userData)
+bool setup(BeagleRTContext *context, void *userData)
 {
 	return true;
 }
@@ -83,14 +81,11 @@
 	return;
 
 }
-// cleanup_render() is called once at the end, after the audio has stopped.
-// Release any resources that were allocated in initialise_render().
 
-void cleanup_render(BeagleRTContext *context, void *userData)
+// cleanup() is called once at the end, after the audio has stopped.
+// Release any resources that were allocated in setup().
+
+void cleanup(BeagleRTContext *context, void *userData)
 {
-	/* TASK:
-	 * If you allocate any memory, be sure to release it here.
-	 * You may or may not need anything in this function, depending
-	 * on your implementation.
-	 */
+	// Nothing to do here
 }
--- a/projects/audio_in_FFT/main.cpp	Mon Jun 15 18:16:00 2015 +0100
+++ b/projects/audio_in_FFT/main.cpp	Wed Jul 15 12:10:51 2015 +0100
@@ -10,7 +10,7 @@
 #include <libgen.h>
 #include <signal.h>
 #include <getopt.h>
-#include "../../include/BeagleRT.h"
+#include <BeagleRT.h>
 
 using namespace std;
 
--- a/projects/audio_in_FFT/render.cpp	Mon Jun 15 18:16:00 2015 +0100
+++ b/projects/audio_in_FFT/render.cpp	Wed Jul 15 12:10:51 2015 +0100
@@ -6,7 +6,7 @@
  */
 
 
-#include "../../include/BeagleRT.h"
+#include <BeagleRT.h>
 #include <rtdk.h>
 #include <NE10.h>					// neon library
 #include <cmath>
@@ -23,7 +23,7 @@
 ne10_fft_cpx_float32_t* frequencyDomain;
 ne10_fft_cfg_float32_t cfg;
 
-// 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.
 //
@@ -32,7 +32,7 @@
 //
 // Return true on success; returning false halts the program.
 
-bool initialise_render(BeagleRTContext *context, void *userData)
+bool setup(BeagleRTContext *context, void *userData)
 {
 	// Retrieve a parameter passed in from the initAudio() call
 	gFFTSize = *(int *)userData;
@@ -74,16 +74,16 @@
 			gWritePointer = 0;
 		}
 
-		for(int channel = 0; channel < context->audioChannels; channel++)
+		for(unsigned int channel = 0; channel < context->audioChannels; channel++)
 			context->audioOut[n * context->audioChannels + channel] = (float) timeDomainOut[gWritePointer].r * gFFTScaleFactor;
 		gWritePointer++;
 	}
 }
 
-// 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(BeagleRTContext *context, void *userData)
+void cleanup(BeagleRTContext *context, void *userData)
 {
 	NE10_FREE(timeDomainIn);
 	NE10_FREE(timeDomainOut);
--- a/projects/basic/main.cpp	Mon Jun 15 18:16:00 2015 +0100
+++ b/projects/basic/main.cpp	Wed Jul 15 12:10:51 2015 +0100
@@ -10,7 +10,7 @@
 #include <libgen.h>
 #include <signal.h>
 #include <getopt.h>
-#include "../../include/BeagleRT.h"
+#include <BeagleRT.h>
 
 using namespace std;
 
--- a/projects/basic/render.cpp	Mon Jun 15 18:16:00 2015 +0100
+++ b/projects/basic/render.cpp	Wed Jul 15 12:10:51 2015 +0100
@@ -6,14 +6,14 @@
  */
 
 
-#include "../../include/BeagleRT.h"
+#include <BeagleRT.h>
 #include <cmath>
 
-float gFrequency;
+float gFrequency = 440.0;
 float gPhase;
 float gInverseSampleRate;
 
-// 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.
 //
@@ -22,10 +22,11 @@
 //
 // Return true on success; returning false halts the program.
 
-bool initialise_render(BeagleRTContext *context, void *userData)
+bool setup(BeagleRTContext *context, void *userData)
 {
 	// Retrieve a parameter passed in from the initAudio() call
-	gFrequency = *(float *)userData;
+	if(userData != 0)
+		gFrequency = *(float *)userData;
 
 	gInverseSampleRate = 1.0 / context->audioSampleRate;
 	gPhase = 0.0;
@@ -51,10 +52,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(BeagleRTContext *context, void *userData)
+void cleanup(BeagleRTContext *context, void *userData)
 {
 
 }
--- a/projects/basic_analog_output/main.cpp	Mon Jun 15 18:16:00 2015 +0100
+++ b/projects/basic_analog_output/main.cpp	Wed Jul 15 12:10:51 2015 +0100
@@ -10,7 +10,7 @@
 #include <libgen.h>
 #include <signal.h>
 #include <getopt.h>
-#include "../../include/BeagleRT.h"
+#include <BeagleRT.h>
 
 using namespace std;
 
--- a/projects/basic_analog_output/render.cpp	Mon Jun 15 18:16:00 2015 +0100
+++ b/projects/basic_analog_output/render.cpp	Wed Jul 15 12:10:51 2015 +0100
@@ -6,8 +6,8 @@
  */
 
 
-#include "../../include/BeagleRT.h"
-#include "../../include/Utilities.h"
+#include <BeagleRT.h>
+#include <Utilities.h>
 #include <rtdk.h>
 #include <cmath>
 
@@ -19,7 +19,7 @@
 float gPhase;
 float gInverseSampleRate;
 
-// 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.
 //
@@ -28,7 +28,7 @@
 //
 // Return true on success; returning false halts the program.
 
-bool initialise_render(BeagleRTContext *context, void *userData)
+bool setup(BeagleRTContext *context, void *userData)
 {
 	// Retrieve a parameter passed in from the initAudio() call
 	gFrequency = *(float *)userData;
@@ -51,10 +51,10 @@
 
 void render(BeagleRTContext *context, void *userData)
 {
-	for(int n = 0; n < context->analogFrames; n++) {
+	for(unsigned int n = 0; n < context->analogFrames; n++) {
 		// Set LED to different phase for each matrix channel
 		float relativePhase = 0.0;
-		for(int channel = 0; channel < context->analogChannels; channel++) {
+		for(unsigned int channel = 0; channel < context->analogChannels; channel++) {
 			float out = kMinimumAmplitude + kAmplitudeRange * 0.5f * (1.0f + sinf(gPhase + relativePhase));
 
 			analogWriteFrame(context, n, channel, out);
@@ -69,10 +69,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(BeagleRTContext *context, void *userData)
+void cleanup(BeagleRTContext *context, void *userData)
 {
 
 }
--- a/projects/basic_network/main.cpp	Mon Jun 15 18:16:00 2015 +0100
+++ b/projects/basic_network/main.cpp	Wed Jul 15 12:10:51 2015 +0100
@@ -10,8 +10,8 @@
 #include <libgen.h>
 #include <signal.h>
 #include <getopt.h>
-#include "../../include/RTAudio.h"
 #include <unistd.h>
+#include <BeagleRT.h>
 
 using namespace std;
 
@@ -34,8 +34,8 @@
 
 int main(int argc, char *argv[])
 {
-	RTAudioSettings settings;	// Standard audio settings
-	float frequency = 440.0;	// Frequency of oscillator
+	BeagleRTInitSettings settings;	// Standard audio settings
+	float frequency = 440.0;		// Frequency of oscillator
 
 	struct option customOptions[] =
 	{
--- a/projects/basic_network/render.cpp	Mon Jun 15 18:16:00 2015 +0100
+++ b/projects/basic_network/render.cpp	Wed Jul 15 12:10:51 2015 +0100
@@ -5,12 +5,10 @@
  *      Author: parallels
  */
 
-#include "../../include/RTAudioSettings.h"
-#include "../../include/render.h"
+#include <BeagleRT.h>
 #include <cmath>
-#include "../../include/client.h"
-#include "../../include/RTAudio.h"	// to schedule lower prio parallel process
-#include <rtdk.h>
+#include <client.h>
+
 float gFrequency;
 float gPhase;
 float gInverseSampleRate;
@@ -28,7 +26,7 @@
 	closeSockets();
 }
 
-// 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.
 //
@@ -36,24 +34,21 @@
 // in from the call to initAudio().
 //
 // Return true on success; returning false halts the program.
-bool initialise_render(int numMatrixChannels, int numDigitalChannels, int numAudioChannels,
-					   int numMatrixFramesPerPeriod,
-					   int numAudioFramesPerPeriod,
-					   float matrixSampleRate, float audioSampleRate,
-					   void *userData, RTAudioSettings *settings)
+bool setup(BeagleRTContext *context, void *userData)
 {
 	// Retrieve a parameter passed in from the initAudio() call
 	gFrequency = *(float *)userData;
 
-	gInverseSampleRate = 1.0 / audioSampleRate;
+	gInverseSampleRate = 1.0 / context->audioSampleRate;
 	gPhase = 0.0;
 
 	networkObject.counter=&gCount;
 	networkObject.variables[0]=&gFrequency;
 	networkObject.variables[1]=&gPhase;
 	networkObject.numVariables=2;
+
 	setupSockets(settings->receivePort, settings->transmitPort, settings->serverName);
-	transmitReceiveDataTask=createAuxiliaryTaskLoop(*transmitReceiveData, 80, "transmit-receive-data");
+	transmitReceiveDataTask= BeagleRT_createAuxiliaryTask(*transmitReceiveData, 80, "transmit-receive-data");
 	//scheduleAuxiliaryTask(transmitReceiveDataTask); //here it does not work
 	return true;
 }
@@ -63,27 +58,27 @@
 // ADCs and DACs (if available). If only audio is available, numMatrixFrames
 // will be 0.
 
-void render(int numAnalogFrames, int numAudioFrames, int numDigitalFrames, float *audioIn, float *audioOut,
-		float *analogIn, float *analogOut, uint32_t *digital)
+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.7f * sinf(gPhase);
 		gPhase += 2.0 * M_PI * gFrequency * gInverseSampleRate;
 		if(gPhase > 2.0 * M_PI)
 			gPhase -= 2.0 * M_PI;
 
-		for(int channel = 0; channel < gNumAudioChannels; channel++)
-			audioOut[n * gNumAudioChannels + channel] = out;
-		if(gCount==0){
-			scheduleAuxiliaryTask(transmitReceiveDataTask);
+		for(unsigned int channel = 0; channel < context->audioChannels; channel++)
+			context->audioOut[n * context->audioChannels + channel] = out;
+
+		if(gCount == 0){
+			BeagleRT_scheduleAuxiliaryTask(transmitReceiveDataTask);
 		}
 		gCount++;
 	}
 }
 
-// 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)
 {
 }
--- a/projects/basic_passthru/main.cpp	Mon Jun 15 18:16:00 2015 +0100
+++ b/projects/basic_passthru/main.cpp	Wed Jul 15 12:10:51 2015 +0100
@@ -10,7 +10,7 @@
 #include <libgen.h>
 #include <signal.h>
 #include <getopt.h>
-#include "../../include/BeagleRT.h"
+#include <BeagleRT.h>
 
 using namespace std;
 
--- a/projects/basic_passthru/render.cpp	Mon Jun 15 18:16:00 2015 +0100
+++ b/projects/basic_passthru/render.cpp	Wed Jul 15 12:10:51 2015 +0100
@@ -6,11 +6,11 @@
  */
 
 
-#include "../../include/BeagleRT.h"
-#include "../../include/Utilities.h"
+#include <BeagleRT.h>
+#include <Utilities.h>
 #include <rtdk.h>
 
-// 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.
 //
@@ -19,7 +19,7 @@
 //
 // Return true on success; returning false halts the program.
 
-bool initialise_render(BeagleRTContext *context, void *userData)
+bool setup(BeagleRTContext *context, void *userData)
 {
 	// Nothing to do here...
 
@@ -54,10 +54,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(BeagleRTContext *context, void *userData)
+void cleanup(BeagleRTContext *context, void *userData)
 {
 
 }
--- a/projects/cape_test/main.cpp	Mon Jun 15 18:16:00 2015 +0100
+++ b/projects/cape_test/main.cpp	Wed Jul 15 12:10:51 2015 +0100
@@ -10,7 +10,7 @@
 #include <libgen.h>
 #include <signal.h>
 #include <getopt.h>
-#include "../../include/BeagleRT.h"
+#include <BeagleRT.h>
 
 using namespace std;
 
--- a/projects/cape_test/render.cpp	Mon Jun 15 18:16:00 2015 +0100
+++ b/projects/cape_test/render.cpp	Wed Jul 15 12:10:51 2015 +0100
@@ -6,7 +6,7 @@
  */
 
 
-#include "../../include/BeagleRT.h"
+#include <BeagleRT.h>
 #include <cmath>
 
 #define ANALOG_LOW	(2048.0 / 65536.0)
@@ -19,7 +19,7 @@
 float gEnvelopeValue = 0.5;
 float gEnvelopeDecayRate = 0.9995;
 
-// 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.
 //
@@ -28,7 +28,7 @@
 //
 // Return true on success; returning false halts the program.
 
-bool initialise_render(BeagleRTContext *context, void *userData)
+bool setup(BeagleRTContext *context, void *userData)
 {
 	return true;
 }
@@ -132,10 +132,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(BeagleRTContext *context, void *userData)
+void cleanup(BeagleRTContext *context, void *userData)
 {
 
 }
--- a/projects/d-box/main.cpp	Mon Jun 15 18:16:00 2015 +0100
+++ b/projects/d-box/main.cpp	Wed Jul 15 12:10:51 2015 +0100
@@ -33,7 +33,7 @@
 // get_opt_long
 #include <getopt.h>
 
-#include "../../include/BeagleRT.h"
+#include <BeagleRT.h>
 #include "config.h"
 #include "sensors.h"
 #include "OscillatorBank.h"
--- a/projects/d-box/render.cpp	Mon Jun 15 18:16:00 2015 +0100
+++ b/projects/d-box/render.cpp	Wed Jul 15 12:10:51 2015 +0100
@@ -5,8 +5,9 @@
  *      Author: Victor Zappi
  */
 
-#include "../../include/BeagleRT.h"
-#include "../../include/PRU.h"
+#include <BeagleRT.h>
+#include <PRU.h>
+
 #include "StatusLED.h"
 #include "config.h"
 #include "OscillatorBank.h"
@@ -152,7 +153,7 @@
 			uint16_t *matrixIn, uint16_t *matrixOut);
 #endif
 
-bool initialise_render(BeagleRTContext *context, void *userData) {
+bool setup(BeagleRTContext *context, void *userData) {
 	int oscBankHopSize = *(int *)userData;
 
 	if(context->analogChannels != 8) {
@@ -730,7 +731,7 @@
 }
 
 // Clean up at the end of render
-void cleanup_render(BeagleRTContext *context, void *userData)
+void cleanup(BeagleRTContext *context, void *userData)
 {
 	free(gOscillatorBuffer1);
 	free(gOscillatorBuffer2);
--- a/projects/filter_FIR/main.cpp	Mon Jun 15 18:16:00 2015 +0100
+++ b/projects/filter_FIR/main.cpp	Wed Jul 15 12:10:51 2015 +0100
@@ -12,7 +12,8 @@
 #include <string>
 #include <getopt.h>
 #include <sndfile.h>				// to load audio files
-#include "../../include/BeagleRT.h"
+
+#include <BeagleRT.h>
 #include "SampleData.h"
 
 using namespace std;
--- a/projects/filter_FIR/render.cpp	Mon Jun 15 18:16:00 2015 +0100
+++ b/projects/filter_FIR/render.cpp	Wed Jul 15 12:10:51 2015 +0100
@@ -6,10 +6,8 @@
  */
 
 
-#include "../../include/BeagleRT.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"
@@ -26,14 +24,13 @@
 
 void initialise_filter(BeagleRTContext *context);
 
-
 // Task for handling the update of the frequencies using the matrix
 AuxiliaryTask gTriggerSamplesTask;
 
 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.
 //
@@ -42,7 +39,7 @@
 //
 // Return true on success; returning false halts the program.
 
-bool initialise_render(BeagleRTContext *context, void *userData)
+bool setup(BeagleRTContext *context, void *userData)
 {
 
 	// Retrieve a parameter passed in from the initAudio() call
@@ -151,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(BeagleRTContext *context, void *userData)
+void cleanup(BeagleRTContext *context, void *userData)
 {
 	delete[] gSampleData.samples;
 
--- a/projects/filter_IIR/main.cpp	Mon Jun 15 18:16:00 2015 +0100
+++ b/projects/filter_IIR/main.cpp	Wed Jul 15 12:10:51 2015 +0100
@@ -12,7 +12,8 @@
 #include <string>
 #include <getopt.h>
 #include <sndfile.h>				// to load audio files
-#include "../../include/BeagleRT.h"
+
+#include <BeagleRT.h>
 #include "SampleData.h"
 
 using namespace std;
--- a/projects/filter_IIR/render.cpp	Mon Jun 15 18:16:00 2015 +0100
+++ b/projects/filter_IIR/render.cpp	Wed Jul 15 12:10:51 2015 +0100
@@ -6,7 +6,7 @@
  */
 
 
-#include "../../include/BeagleRT.h"	// to schedule lower prio parallel process
+#include <BeagleRT.h>	// to schedule lower prio parallel process
 #include <rtdk.h>
 #include <cmath>
 #include <stdio.h>
@@ -44,7 +44,7 @@
 extern float gCutFreq;
 
 
-// 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.
 //
@@ -53,7 +53,7 @@
 //
 // Return true on success; returning false halts the program.
 
-bool initialise_render(BeagleRTContext *context, void *userData)
+bool setup(BeagleRTContext *context, void *userData)
 {
 
 	// Retrieve a parameter passed in from the initAudio() call
@@ -212,10 +212,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(BeagleRTContext *context, void *userData)
+void cleanup(BeagleRTContext *context, void *userData)
 {
 	delete[] gSampleData.samples;
 }
--- a/projects/oscillator_bank/main.cpp	Mon Jun 15 18:16:00 2015 +0100
+++ b/projects/oscillator_bank/main.cpp	Wed Jul 15 12:10:51 2015 +0100
@@ -10,7 +10,7 @@
 #include <libgen.h>
 #include <signal.h>
 #include <getopt.h>
-#include "../../include/BeagleRT.h"
+#include <BeagleRT.h>
 
 using namespace std;
 
--- a/projects/oscillator_bank/render.cpp	Mon Jun 15 18:16:00 2015 +0100
+++ b/projects/oscillator_bank/render.cpp	Wed Jul 15 12:10:51 2015 +0100
@@ -6,8 +6,8 @@
  */
 
 
-#include "../../include/BeagleRT.h"
-#include "../../include/Utilities.h"
+#include <BeagleRT.h>
+#include <Utilities.h>
 #include <rtdk.h>
 #include <cstdlib>
 #include <cmath>
@@ -34,7 +34,7 @@
 
 // These settings are carried over from main.cpp
 // Setting global variables is an alternative approach
-// to passing a structure to userData in initialise_render()
+// to passing a structure to userData in setup()
 
 extern int gNumOscillators;
 extern int gWavetableLength;
@@ -50,7 +50,7 @@
 							  float *lookupTable);
 }
 
-// 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.
 //
@@ -58,7 +58,7 @@
 // in from the call to initAudio().
 //
 // Return true on success; returning false halts the program.
-bool initialise_render(BeagleRTContext *context, void *userData)
+bool setup(BeagleRTContext *context, void *userData)
 {
 	srandom(time(NULL));
 
@@ -207,10 +207,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(BeagleRTContext *context, void *userData)
+void cleanup(BeagleRTContext *context, void *userData)
 {
 	free(gWavetable);
 	free(gPhases);
--- a/projects/samples/main.cpp	Mon Jun 15 18:16:00 2015 +0100
+++ b/projects/samples/main.cpp	Wed Jul 15 12:10:51 2015 +0100
@@ -12,7 +12,8 @@
 #include <string>
 #include <getopt.h>
 #include <sndfile.h>				// to load audio files
-#include "../../include/BeagleRT.h"
+
+#include <BeagleRT.h>
 #include "SampleData.h"
 
 using namespace std;
--- a/projects/samples/render.cpp	Mon Jun 15 18:16:00 2015 +0100
+++ b/projects/samples/render.cpp	Wed Jul 15 12:10:51 2015 +0100
@@ -6,10 +6,8 @@
  */
 
 
-#include "../../include/BeagleRT.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
@@ -21,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.
 //
@@ -30,7 +28,7 @@
 //
 // Return true on success; returning false halts the program.
 
-bool initialise_render(BeagleRTContext *context, void *userData)
+bool setup(BeagleRTContext *context, void *userData)
 {
 
 	// Retrieve a parameter passed in from the initAudio() call
@@ -52,7 +50,7 @@
 
 void render(BeagleRTContext *context, void *userData)
 {
-	for(int n = 0; n < context->audioFrames; n++) {
+	for(unsigned int n = 0; n < context->audioFrames; n++) {
 		float out = 0;
 
 		// If triggered...
@@ -62,7 +60,7 @@
 		if(gReadPtr >= gSampleData.sampleLen)
 			gReadPtr = -1;
 
-		for(int channel = 0; channel < context->audioChannels; 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
 	}
 
@@ -118,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(BeagleRTContext *context, void *userData)
+void cleanup(BeagleRTContext *context, void *userData)
 {
 	delete[] gSampleData.samples;
 }
--- a/projects/tank_wars/main.cpp	Mon Jun 15 18:16:00 2015 +0100
+++ b/projects/tank_wars/main.cpp	Wed Jul 15 12:10:51 2015 +0100
@@ -11,7 +11,7 @@
 #include <signal.h>
 #include <getopt.h>
 #include <sndfile.h>
-#include "../../include/RTAudio.h"
+#include <BeagleRT.h>
 
 extern int gScreenFramesPerSecond;
 
@@ -77,7 +77,7 @@
 
 int main(int argc, char *argv[])
 {
-	RTAudioSettings settings;	// Standard audio settings
+	BeagleRTInitSettings settings;	// Standard audio settings
 	string musicFileName = "music.wav";
 	string soundBoomFileName = "boom.wav";
 
--- a/projects/tank_wars/render.cpp	Mon Jun 15 18:16:00 2015 +0100
+++ b/projects/tank_wars/render.cpp	Wed Jul 15 12:10:51 2015 +0100
@@ -6,8 +6,8 @@
  */
 
 
-#include "../../include/RTAudio.h"
-#include "../../include/Utilities.h"
+#include <BeagleRT.h>
+#include <Utilities.h>
 #include "game.h"
 #include <rtdk.h>
 #include <cmath>
@@ -78,7 +78,7 @@
 
 void screen_update();
 
-// 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.
 //
@@ -87,26 +87,22 @@
 //
 // Return true on success; returning false halts the program.
 
-bool initialise_render(int numAnalogChannels, int numDigitalChannels, int numAudioChannels,
-					   int numAnalogFramesPerPeriod,
-					   int numAudioFramesPerPeriod,
-					   float analogSampleRate, float audioSampleRate,
-					   void *userData)
+bool setup(BeagleRTContext *context, void *userData)
 {
 	srandom(time(NULL));
 
 	// Verify we are running with matrix enabled
-	if(numAnalogFramesPerPeriod == 0 || numAnalogChannels < 4) {
+	if(context->analogFrames == 0 || context->analogChannels < 4) {
 		rt_printf("Error: this example needs the matrix enabled with at least 4 channels\n");
 		return false;
 	}
 
 	// Initialise audio variables
-	gAudioFramesPerMatrixFrame = numAudioFramesPerPeriod / numAnalogFramesPerPeriod;
-	gOscillatorPhaseScaler = 2.0 * M_PI / audioSampleRate;
+	gAudioFramesPerMatrixFrame = context->audioFrames / context->analogFrames;
+	gOscillatorPhaseScaler = 2.0 * M_PI / context->audioSampleRate;
 
 	// Initialise the screen buffers
-	gScreenBufferMaxLength = 2 * analogSampleRate / gScreenFramesPerSecond;
+	gScreenBufferMaxLength = 2 * context->analogSampleRate / gScreenFramesPerSecond;
 	gScreenBuffer1 = new float[gScreenBufferMaxLength];
 	gScreenBuffer2 = new float[gScreenBufferMaxLength];
 	if(gScreenBuffer1 == 0 || gScreenBuffer2 == 0) {
@@ -123,12 +119,12 @@
 
 	// Initialise the game
 	setupGame(gScreenWidth, gScreenHeight);
-	gGameFrameInterval = analogSampleRate / gGameFramesPerSecond;
+	gGameFrameInterval = context->analogSampleRate / gGameFramesPerSecond;
 	gSamplesUntilNextFrame = gGameFrameInterval;
 
 	// Initialise auxiliary tasks
-	if((gScreenUpdateTask = createAuxiliaryTaskLoop(&screen_update, 90,
-													"beaglert-screen-update")) == 0)
+	if((gScreenUpdateTask = BeagleRT_createAuxiliaryTask(&screen_update, 90,
+														 "beaglert-screen-update")) == 0)
 		return false;
 
 	return true;
@@ -159,12 +155,11 @@
 // ADCs and DACs (if available). If only audio is available, numMatrixFrames
 // will be 0.
 
-void render(int numAnalogFrames, int numDigitalFrames, int numAudioFrames, float *audioIn, float *audioOut,
-			float *analogIn, float *analogOut, uint32_t *digital)
+void render(BeagleRTContext *context, void *userData)
 {
 	int audioIndex = 0;
 
-	for(int n = 0; n < numAnalogFrames; n++) {
+	for(unsigned int n = 0; n < context->analogFrames; n++) {
 		for(int k = 0; k < gAudioFramesPerMatrixFrame; k++) {
 			// Render music and sound
 			float audioSample = 0;
@@ -193,12 +188,12 @@
 					gSoundProjectileOscillatorPhase -= 2.0 * M_PI;
 			}
 
-			audioOut[2*audioIndex] = audioOut[2*audioIndex + 1] = audioSample;
+			context->audioOut[2*audioIndex] = context->audioOut[2*audioIndex + 1] = audioSample;
 			audioIndex++;
 		}
 
 		// First-order lowpass filter to remove noise on launch FSR
-		float rawSample = AnalogRead(gInputLauncher, n);
+		float rawSample = analogReadFrame(context, n, gInputLauncher);
 		float launchSample = gLauncherFilterPole * gLauncherLastSample +
 							(1.0f - gLauncherFilterPole) * rawSample;
 		gLauncherLastSample = launchSample;
@@ -232,9 +227,9 @@
 			// Update game physics and cannon angles
 			gSamplesUntilNextFrame = gGameFrameInterval;
 
-			setTank1CannonAngle(map(AnalogRead(gInputTank1Angle, n),
+			setTank1CannonAngle(map(analogReadFrame(context, n, gInputTank1Angle),
 									0, 1.0, M_PI, 0));
-			setTank2CannonAngle(map(AnalogRead(gInputTank2Angle, n),
+			setTank2CannonAngle(map(analogReadFrame(context, n, gInputTank2Angle),
 									0, 1.0, M_PI, 0));
 			nextGameFrame();
 
@@ -257,21 +252,21 @@
 
 			// Rescale screen coordinates to matrix ranges; invert the Y
 			// coordinate to go from normal screen coordinates to scope coordinates
-			AnalogWriteFrame(gOutputX, n, constrain(map(x, 0, gScreenWidth, 0, 1.0), 0, 1.0));
-			AnalogWriteFrame(gOutputY, n, constrain(map(y, 0, gScreenHeight, 1.0, 0), 0, 1.0));
+			analogWriteFrameOnce(context, n, gOutputX, constrain(map(x, 0, gScreenWidth, 0, 1.0), 0, 1.0));
+			analogWriteFrameOnce(context, n, gOutputY, constrain(map(y, 0, gScreenHeight, 1.0, 0), 0, 1.0));
 		}
 		else {
 			// Still not ready! Write 0 until something happens
-			AnalogWriteFrame(gOutputX, n, 0);
-			AnalogWriteFrame(gOutputY, n, 0);
+			analogWriteFrameOnce(context, n, gOutputX, 0);
+			analogWriteFrameOnce(context, n, gOutputY, 0);
 		}
 
 		if(gameStatusWinner() != 0) {
 			// Blink one LED to show who won
 			// Blink both LEDs when projectile is in motion
 			float val = (gSampleCounter % 4000 > 2000) ? 1.0 : 0;
-			AnalogWriteFrame(gOutputPlayer1LED, n, gameStatusWinner() == 1 ? val : 0);
-			AnalogWriteFrame(gOutputPlayer2LED, n, gameStatusWinner() == 2 ? val : 0);
+			analogWriteFrameOnce(context, n, gOutputPlayer1LED, gameStatusWinner() == 1 ? val : 0);
+			analogWriteFrameOnce(context, n, gOutputPlayer2LED, gameStatusWinner() == 2 ? val : 0);
 
 			// After 5 seconds, restart the game
 			gSamplesSinceFinish++;
@@ -281,23 +276,23 @@
 		else if(gameStatusProjectileInMotion()) {
 			// Blink both LEDs when projectile is in motion
 			float val = (gSampleCounter % 2000 > 1000) ? 1.0 : 0;
-			AnalogWriteFrame(gOutputPlayer1LED, n, val);
-			AnalogWriteFrame(gOutputPlayer2LED, n, val);
+			analogWriteFrameOnce(context, n, gOutputPlayer1LED, val);
+			analogWriteFrameOnce(context, n, gOutputPlayer2LED, val);
 		}
 		else if(gameStatusPlayer1Turn()) {
-			AnalogWriteFrame(gOutputPlayer1LED, n, 1.0);
-			AnalogWriteFrame(gOutputPlayer2LED, n, 0);
+			analogWriteFrameOnce(context, n, gOutputPlayer1LED, 1.0);
+			analogWriteFrameOnce(context, n, gOutputPlayer2LED, 0);
 		}
 		else {
-			AnalogWriteFrame(gOutputPlayer2LED, n, 1.0);
-			AnalogWriteFrame(gOutputPlayer1LED, n, 0);
+			analogWriteFrameOnce(context, n, gOutputPlayer2LED, 1.0);
+			analogWriteFrameOnce(context, n, gOutputPlayer1LED, 0);
 		}
 
 		// Check if we have reached the point where we should next update
 		if(gScreenBufferReadPointer >= gScreenBufferNextUpdateLocation &&
 		   !gScreenNextBufferReady) {
 			// Update the screen at lower priority than the audio thread
-			scheduleAuxiliaryTask(gScreenUpdateTask);
+			BeagleRT_scheduleAuxiliaryTask(gScreenUpdateTask);
 		}
 
 		gSampleCounter++;
@@ -320,10 +315,10 @@
 	gScreenNextBufferReady = true;
 }
 
-// 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)
 {
 	// Clean up the game state
 	cleanupGame();
Binary file pru_rtaudio.bin has changed