changeset 314:611306d840b3 prerelease

Merge
author Giulio Moro <giuliomoro@yahoo.it>
date Fri, 27 May 2016 19:00:43 +0100
parents c770cdf3d8b2 (current diff) 00725dfc1b87 (diff)
children 868cfb137fe5
files
diffstat 30 files changed, 328 insertions(+), 249 deletions(-) [+]
line wrap: on
line diff
--- a/core/PRU.cpp	Fri May 27 18:55:34 2016 +0100
+++ b/core/PRU.cpp	Fri May 27 19:00:43 2016 +0100
@@ -111,7 +111,7 @@
 extern int gRTAudioVerbose;
 
 // Constructor: specify a PRU number (0 or 1)
-PRU::PRU(BelaContext *input_context)
+PRU::PRU(InternalBelaContext *input_context)
 : context(input_context), pru_number(0), running(false), analog_enabled(false),
   digital_enabled(false), gpio_enabled(false), led_enabled(false),
   mux_channels(0),
@@ -630,7 +630,7 @@
 
 		// Call user render function
         // ***********************
-		render(context, userData);
+		render((BelaContext *)context, userData);
 		// ***********************
 
 		if(analog_enabled) {
@@ -666,7 +666,7 @@
 		}
 
 		// Increment total number of samples that have elapsed
-		context->audioSampleCount += context->audioFrames;
+		context->audioFramesElapsed += context->audioFrames;
 
 		if(xenomai_gpio != 0) {
 			// Set the test pin high
--- a/core/PulseIn.cpp	Fri May 27 18:55:34 2016 +0100
+++ b/core/PulseIn.cpp	Fri May 27 19:00:43 2016 +0100
@@ -13,7 +13,7 @@
 	_pulseOnState = direction == 1 ? 1 : 0;
 	_array.resize(context->digitalFrames);
 	_lastContext = (uint64_t)-1;
-	pinModeFrame(context, 0, digitalInput, INPUT); //context is used to allocate the number of elements in the array
+	pinMode(context, 0, digitalInput, INPUT); //context is used to allocate the number of elements in the array
 }
 
 void PulseIn::check(BelaContext* context){
@@ -25,18 +25,18 @@
 	}
 	for(unsigned int n = 0; n < context->digitalFrames; n++){
 		if(_pulseIsOn == false){ // look for start edge
-			if(digitalReadFrame(context, n, _digitalInput) == _pulseOnState){
-				_pulseStart = context->audioSampleCount + n; // store location of start edge
+			if(digitalRead(context, n, _digitalInput) == _pulseOnState){
+				_pulseStart = context->audioFramesElapsed + n; // store location of start edge
 				_pulseIsOn = true;
 			}
 		} else { // _pulseIsOn == true;
-			if(digitalReadFrame(context, n, _digitalInput) == !_pulseOnState){ // look for stop edge
-				_array[n] = context->audioSampleCount + n - _pulseStart; // compute and store pulse duration
+			if(digitalRead(context, n, _digitalInput) == !_pulseOnState){ // look for stop edge
+				_array[n] = context->audioFramesElapsed + n - _pulseStart; // compute and store pulse duration
 				_pulseIsOn = false;
 			}
 		}
 	}
-	_lastContext = context->audioSampleCount;
+	_lastContext = context->audioFramesElapsed;
 };
 
 PulseIn::~PulseIn() {
--- a/core/RTAudio.cpp	Fri May 27 18:55:34 2016 +0100
+++ b/core/RTAudio.cpp	Fri May 27 19:00:43 2016 +0100
@@ -51,14 +51,15 @@
 	bool autoSchedule;
 } InternalAuxiliaryTask;
 
-const char gRTAudioThreadName[] = "bela-audio";
-const char gRTAudioInterruptName[] = "bela-pru-irq";
-
 // Real-time tasks and objects
 RT_TASK gRTAudioThread;
+const char gRTAudioThreadName[] = "bela-audio";
+
 #ifdef BELA_USE_XENOMAI_INTERRUPTS
 RT_INTR gRTAudioInterrupt;
+const char gRTAudioInterruptName[] = "bela-pru-irq";
 #endif
+
 PRU *gPRU = 0;
 I2c_Codec *gAudioCodec = 0;
 
@@ -77,7 +78,7 @@
 int gAmplifierShouldBeginMuted = 0;
 
 // Context which holds all the audio/sensor data passed to the render routines
-BelaContext gContext;
+InternalBelaContext gContext;
 
 // User data passed in from main()
 void *gUserData;
@@ -244,7 +245,7 @@
 	Bela_setHeadphoneLevel(settings->headphoneLevel);
 
 	// Call the user-defined initialisation function
-	if(!setup(&gContext, userData)) {
+	if(!setup((BelaContext *)&gContext, userData)) {
 		cout << "Couldn't initialise audio rendering\n";
 		return 1;
 	}
@@ -485,7 +486,7 @@
 // Free any resources associated with PRU real-time audio
 void Bela_cleanupAudio()
 {
-	cleanup(&gContext, gUserData);
+	cleanup((BelaContext *)&gContext, gUserData);
 
 	// Clean up the auxiliary tasks
 	vector<InternalAuxiliaryTask*>::iterator it;
--- a/examples/7segment/render.cpp	Fri May 27 18:55:34 2016 +0100
+++ b/examples/7segment/render.cpp	Fri May 27 19:00:43 2016 +0100
@@ -58,7 +58,7 @@
 	}
 	
 	for(int i = 0; i < NUM_PINS; i++) {
-		pinModeFrame(context, 0, kPins[i], OUTPUT);
+		pinMode(context, 0, kPins[i], OUTPUT);
 	}
 
 	return true;
@@ -80,25 +80,25 @@
 	
 		// Write the currently displaying digit low and the rest high
 		for(int i = 0; i < 4; i++)
-				digitalWriteFrameOnce(context, n, kPins[kDigits[i]], HIGH);
-		digitalWriteFrameOnce(context, n, kPins[kDigits[gCurrentlyDisplayingDigit]], LOW);
+				digitalWriteOnce(context, n, kPins[kDigits[i]], HIGH);
+		digitalWriteOnce(context, n, kPins[kDigits[gCurrentlyDisplayingDigit]], LOW);
 		
 		// Write the digit to the other outputs
-		digitalWriteFrameOnce(context, n, kPins[11],
+		digitalWriteOnce(context, n, kPins[11],
 			gCharacterToDisplay[gCurrentlyDisplayingDigit] & 0x01);	// a
-		digitalWriteFrameOnce(context, n, kPins[6], 
+		digitalWriteOnce(context, n, kPins[6], 
 			gCharacterToDisplay[gCurrentlyDisplayingDigit] & 0x02);	// b
-		digitalWriteFrameOnce(context, n, kPins[4], 
+		digitalWriteOnce(context, n, kPins[4], 
 			gCharacterToDisplay[gCurrentlyDisplayingDigit] & 0x04);	// c
-		digitalWriteFrameOnce(context, n, kPins[1],
+		digitalWriteOnce(context, n, kPins[1],
 			gCharacterToDisplay[gCurrentlyDisplayingDigit] & 0x08);	// d
-		digitalWriteFrameOnce(context, n, kPins[0],
+		digitalWriteOnce(context, n, kPins[0],
 			gCharacterToDisplay[gCurrentlyDisplayingDigit] & 0x10);	// e
-		digitalWriteFrameOnce(context, n, kPins[10],
+		digitalWriteOnce(context, n, kPins[10],
 			gCharacterToDisplay[gCurrentlyDisplayingDigit] & 0x20);	// f
-		digitalWriteFrameOnce(context, n, kPins[5],
+		digitalWriteOnce(context, n, kPins[5],
 			gCharacterToDisplay[gCurrentlyDisplayingDigit] & 0x40);	// g
-		digitalWriteFrameOnce(context, n, kPins[2],
+		digitalWriteOnce(context, n, kPins[2],
 			gCharacterToDisplay[gCurrentlyDisplayingDigit] & 0x80);	// .
 			
 		// Check for changing state
--- a/examples/analogDigitalDemo/render.cpp	Fri May 27 18:55:34 2016 +0100
+++ b/examples/analogDigitalDemo/render.cpp	Fri May 27 19:00:43 2016 +0100
@@ -36,27 +36,27 @@
   /*
   * TODO: as an exercise, you will need to set the pin mode before writing or reading the digital pins.
   */
-	if((context->audioSampleCount&31)==0){ //every 32 frames...
+	if((context->audioFramesElapsed&31)==0){ //every 32 frames...
         //ANALOG channels
-		analogWriteFrame(context, 0, 0, analogReadFrame(context, 0,0));
+		analogWrite(context, 0, 0, analogRead(context, 0,0));
 		// read the input0 at frame0  and write it to output0 frame0. Using analogWrite will fill the rest of the buffer with the same value
                                             // The value at the last frame will persist through the successive buffers until is set again.
                                             // This effectively is a pass-through with downsampling by 32 times
-        analogWriteFrame(context, 0, 3, 1.0);  // write 1.0 to channel3 from frame0 to the end of the buffer
-        analogWriteFrame(context, 4, 3, 0.1);  // write 0.1  to channel3 from frame4 to the end of the buffer
-        analogWriteFrameOnce(context, 6, 3, 0.2); //write 0.2 to channel3 only on frame 6
+        analogWrite(context, 0, 3, 1.0);  // write 1.0 to channel3 from frame0 to the end of the buffer
+        analogWrite(context, 4, 3, 0.1);  // write 0.1  to channel3 from frame4 to the end of the buffer
+        analogWriteOnce(context, 6, 3, 0.2); //write 0.2 to channel3 only on frame 6
         //this buffer for channel 3 will look like this:  1 1 1 1 0.1 0.1 0.2 0.1 
         //the next buffers for channel 3 will be filled up with 0.1 ....
         //DIGITAL channels
-        digitalWriteFrame(context, 0, P8_07, GPIO_HIGH); //sets all the frames  to HIGH for channel 0
-        digitalWriteFrameOnce(context, 4, P8_07, GPIO_LOW); //only frame 4 will be LOW  for channel 0
+        digitalWrite(context, 0, P8_07, GPIO_HIGH); //sets all the frames  to HIGH for channel 0
+        digitalWriteOnce(context, 4, P8_07, GPIO_LOW); //only frame 4 will be LOW  for channel 0
         // in this buffer the frames of channel 0 will look like this: 1 1 1 1 0 1 1 1 ...... 1 
         // in the next buffer each frame of channel 0 will be initialized to 1 (the last value of this buffer)
-        digitalWriteFrame(context, 0, P8_08, GPIO_HIGH);
-        digitalWriteFrame(context, 2, P8_08, GPIO_LOW);
-        digitalWriteFrame(context, 4, P8_08, GPIO_HIGH);
-        digitalWriteFrame(context, 5, P8_08, GPIO_LOW);
-        pinModeFrame(context, 0, P9_16, GPIO_INPUT); // set channel 10 to input
+        digitalWrite(context, 0, P8_08, GPIO_HIGH);
+        digitalWrite(context, 2, P8_08, GPIO_LOW);
+        digitalWrite(context, 4, P8_08, GPIO_HIGH);
+        digitalWrite(context, 5, P8_08, GPIO_LOW);
+        pinMode(context, 0, P9_16, GPIO_INPUT); // set channel 10 to input
         // in this buffer the frames of channel 1 will look like this: 1 1 0 0 1 0 0 0 .... 0
         // in the next buffer each frame of channel 1 will be initialized to 0 (the last value of this buffer)
 	}
@@ -67,15 +67,15 @@
         //use digital channels 2-8 to create a 7 bit binary counter
         context->digital[n]=context->digital[n] & (~0b111111100); // set to zero (GPIO_OUTPUT) the bits in the lower word
         context->digital[n]=context->digital[n] & ((~0b111111100<<16) | 0xffff ); //initialize to zero the bits in the higher word (output value)
-        context->digital[n]=context->digital[n] | ( ((context->audioSampleCount&0b1111111)<<(16+2)) ) ;  // set the bits in the higher word to the desired output value, keeping the lower word unchanged
-        digitalWriteFrame(context, n, P8_29, digitalReadFrame(context, n, P8_30)); // echo the input from from channel 15 to channel 14
-        digitalWriteFrame(context, n, P8_28, digitalReadFrame(context, n, P9_16)); // echo the input from from channel 10 to channel 13
-        pinModeFrame(context, 0, P8_30, 0); //set channel 15 to input
+        context->digital[n]=context->digital[n] | ( ((context->audioFramesElapsed&0b1111111)<<(16+2)) ) ;  // set the bits in the higher word to the desired output value, keeping the lower word unchanged
+        digitalWrite(context, n, P8_29, digitalRead(context, n, P8_30)); // echo the input from from channel 15 to channel 14
+        digitalWrite(context, n, P8_28, digitalRead(context, n, P9_16)); // echo the input from from channel 10 to channel 13
+        pinMode(context, 0, P8_30, 0); //set channel 15 to input
 	}
 
 	for(unsigned int n=0; n<context->analogFrames; n++){
-    	analogWriteFrame(context, n, 1, (context->audioSampleCount&8191)/8192.0); // writes a single frame. channel 1 is a ramp that follows gCountFrames
-    	analogWriteFrame(context, n, 2, analogReadFrame(context, n, 2)); // writes a single frame. channel2 is just a passthrough
+    	analogWrite(context, n, 1, (context->audioFramesElapsed&8191)/8192.0); // writes a single frame. channel 1 is a ramp that follows gCountFrames
+    	analogWrite(context, n, 2, analogRead(context, n, 2)); // writes a single frame. channel2 is just a passthrough
 //		rt_printf("Analog out frame %d :",n);
 //		for(int c=0; c<gNumAnalogChannels; c++)
 //			rt_printf("%.1f ",analogOut[n*gNumAnalogChannels + c]);
--- a/examples/basic/render.cpp	Fri May 27 18:55:34 2016 +0100
+++ b/examples/basic/render.cpp	Fri May 27 19:00:43 2016 +0100
@@ -55,7 +55,7 @@
 			// context->audioOut[n * context->audioChannels + channel] = out;
 
 			// Or using the macros:
-			audioWriteFrame(context, n, channel, out);
+			audioWrite(context, n, channel, out);
 		}
 	}
 }
--- a/examples/basic_FFT_phase_vocoder/render.cpp	Fri May 27 18:55:34 2016 +0100
+++ b/examples/basic_FFT_phase_vocoder/render.cpp	Fri May 27 19:00:43 2016 +0100
@@ -216,7 +216,7 @@
 	for(int n = 0; n < numAudioFrames; n++) {
 		if(gReadPtr < gSampleData.sampleLen)
 			audioIn[2*n] = audioIn[2*n+1] = gSampleData.samples[gReadPtr]*(1-gPlaybackLive) +
-			gPlaybackLive*0.5f*(audioReadFrame(context,n,0)+audioReadFrame(context,n,1));
+			gPlaybackLive*0.5f*(audioRead(context,n,0)+audioRead(context,n,1));
 		else
 			audioIn[2*n] = audioIn[2*n+1] = 0;
 		if(++gReadPtr >= gSampleData.sampleLen)
--- a/examples/basic_analog_input/render.cpp	Fri May 27 18:55:34 2016 +0100
+++ b/examples/basic_analog_input/render.cpp	Fri May 27 19:00:43 2016 +0100
@@ -61,8 +61,8 @@
 	for(unsigned int n = 0; n < context->audioFrames; n++) {
 		if(!(n % gAudioFramesPerAnalogFrame)) {
 			// Even audio samples: update frequency and amplitude from the matrix
-			frequency = map(analogReadFrame(context, n/gAudioFramesPerAnalogFrame, gSensorInputFrequency), 0, 1, 100, 1000);
-			amplitude = analogReadFrame(context, n/gAudioFramesPerAnalogFrame, gSensorInputAmplitude);
+			frequency = map(analogRead(context, n/gAudioFramesPerAnalogFrame, gSensorInputFrequency), 0, 1, 100, 1000);
+			amplitude = analogRead(context, n/gAudioFramesPerAnalogFrame, gSensorInputAmplitude);
 		}
 
 		float out = amplitude * sinf(gPhase);
--- a/examples/basic_analog_output/render.cpp	Fri May 27 18:55:34 2016 +0100
+++ b/examples/basic_analog_output/render.cpp	Fri May 27 19:00:43 2016 +0100
@@ -57,7 +57,7 @@
 		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);
+			analogWrite(context, n, channel, out);
 
 			// Advance by pi/4 (1/8 of a full rotation) for each channel
 			relativePhase += M_PI * 0.25;
--- a/examples/basic_blink/render.cpp	Fri May 27 18:55:34 2016 +0100
+++ b/examples/basic_blink/render.cpp	Fri May 27 19:00:43 2016 +0100
@@ -14,7 +14,7 @@
 
 bool setup(BelaContext *context, void *userData)
 {
-    pinModeFrame(context, 0, P8_07, OUTPUT);
+    pinMode(context, 0, P8_07, OUTPUT);
 	return true;
 }
 
@@ -36,13 +36,13 @@
 	for(unsigned int n=0; n<context->digitalFrames; n++){
     if(count==context->digitalSampleRate*interval){ //if enough samples have elapsed
       count=0; //reset the counter
-    // status=digitalReadFrame(context, 0, P8_07);
+    // status=digitalRead(context, 0, P8_07);
       if(status==GPIO_LOW) { //toggle the status
-          digitalWriteFrame(context, n, P8_07, status); //write the status to the LED
+          digitalWrite(context, n, P8_07, status); //write the status to the LED
           status=GPIO_HIGH;
       }
       else {
-          digitalWriteFrame(context, n, P8_07, status); //write the status to the LED
+          digitalWrite(context, n, P8_07, status); //write the status to the LED
           status=GPIO_LOW;
       }
     }
--- a/examples/basic_button/render.cpp	Fri May 27 18:55:34 2016 +0100
+++ b/examples/basic_button/render.cpp	Fri May 27 19:00:43 2016 +0100
@@ -21,8 +21,8 @@
 
 bool setup(BelaContext *context, void *userData)
 {
-	pinModeFrame(context, 0, P8_08, INPUT);
-	pinModeFrame(context, 0, P8_07, OUTPUT);
+	pinMode(context, 0, P8_08, INPUT);
+	pinMode(context, 0, P8_07, OUTPUT);
 	return true;
 }
 
@@ -42,11 +42,11 @@
 void render(BelaContext *context, void *userData)
 {
 	for(unsigned int n=0; n<context->digitalFrames; n++){
-		int status=digitalReadFrame(context, 0, P8_08); //read the value of the button
-		digitalWriteFrameOnce(context, n, P8_07, status); //write the status to the LED
+		int status=digitalRead(context, 0, P8_08); //read the value of the button
+		digitalWriteOnce(context, n, P8_07, status); //write the status to the LED
 		float out = 0.1 * status * rand() / (float)RAND_MAX * 2 - 1; //generate some noise, gated by the button
 		for(unsigned int j = 0; j < context->audioChannels; j++){
-			audioWriteFrame(context, n, j, out); //write the audio output
+			audioWrite(context, n, j, out); //write the audio output
 		}
 	}
 }
--- a/examples/basic_libpd/render.cpp	Fri May 27 18:55:34 2016 +0100
+++ b/examples/basic_libpd/render.cpp	Fri May 27 19:00:43 2016 +0100
@@ -115,21 +115,21 @@
 	// rt_printf("channelsInUse: %d, analogChannels in Use: %d\n", gChannelsInUse, analogChannelsInUse);
 	for(unsigned int n = 0; n < context->audioFrames; ++n){ //pd buffers are interleaved
 		for(unsigned int ch = 0; ch < context->audioChannels; ++ch){ //first two channels are audio
-			gInBuf[inW++] = audioReadFrame(context, n, ch);
+			gInBuf[inW++] = audioRead(context, n, ch);
 		}
 		// then analogs
 		// this loop resamples by ZOH, as needed, using m
 		if(context->analogChannels == 8 ){ //hold the value for two frames
 			for(int analogCh = 0; analogCh < analogChannelsInUse; ++analogCh){
-				gInBuf[inW++] = analogReadFrame(context, n/2, analogCh); // n/2 wil be the same for n and n+1 when n is even
+				gInBuf[inW++] = analogRead(context, n/2, analogCh); // n/2 wil be the same for n and n+1 when n is even
 			}
 		} else if(context->analogChannels == 4){ //write every frame
 			for(int analogCh = 0; analogCh < analogChannelsInUse; ++analogCh){
-				gInBuf[inW++] = analogReadFrame(context, n, analogCh);
+				gInBuf[inW++] = analogRead(context, n, analogCh);
 			}
 		} else if(context->analogChannels == 2){ //drop every other frame
 			for(int analogCh = 0; analogCh < analogChannelsInUse; ++analogCh){
-				gInBuf[inW++] = analogReadFrame(context, n*2, analogCh);
+				gInBuf[inW++] = analogRead(context, n*2, analogCh);
 			}
 		}
 		if(inW == gBufLength * gChannelsInUse){
@@ -145,14 +145,14 @@
 
 	for(unsigned int n = 0; n < context->audioFrames; n++){ //pd buffers are interleaved
 		for(unsigned int ch = 0; ch < context->audioChannels; ++ch){
-			audioWriteFrame(context, n, ch, gOutBuf[outR++]);
+			audioWrite(context, n, ch, gOutBuf[outR++]);
 		}
 		//and analogs
 		if(context->analogChannels == 8){
 			for(unsigned int analogCh = 0; analogCh < analogChannelsInUse; ++analogCh){
 				float analogOut = gOutBuf[outR++];				
 				if((n&1) == 0){//write every two frames
-					analogWriteFrame(context, n/2, analogCh, analogOut);
+					analogWrite(context, n/2, analogCh, analogOut);
 				} else {
 					// discard this sample
 				}
@@ -160,13 +160,13 @@
 		} else if(context->analogChannels == 4){ //write every frame
 			for(int analogCh = 0; analogCh < analogChannelsInUse; ++analogCh){
 				float analogOut = gOutBuf[outR++];
-				analogWriteFrame(context, n, analogCh, analogOut);
+				analogWrite(context, n, analogCh, analogOut);
 			}
 		} else if(context->analogChannels == 2){ //write twice every frame
 			for(unsigned int analogCh = 0; analogCh < analogChannelsInUse; ++analogCh){
 				float analogOut = gOutBuf[outR++];
-				analogWriteFrame(context, 2*n, analogCh, analogOut);
-				analogWriteFrame(context, 2*n + 1, analogCh, analogOut);
+				analogWrite(context, 2*n, analogCh, analogOut);
+				analogWrite(context, 2*n + 1, analogCh, analogOut);
 			}
 		}
 		if(outR == gBufLength * gChannelsInUse){
--- a/examples/basic_midi/render.cpp	Fri May 27 18:55:34 2016 +0100
+++ b/examples/basic_midi/render.cpp	Fri May 27 19:00:43 2016 +0100
@@ -133,7 +133,7 @@
 	for(unsigned int n = 0; n < context->analogFrames; n++){
 		static int count = 0;
 		static bool state = 0;
-		analogWriteFrameOnce(context, n, 1, state);
+		analogWriteOnce(context, n, 1, state);
 		if(count % 40000 == 0){
 			state = !state;
 			midi_byte_t bytes[6] = {176, 30, (char)(state*127), 176, 67, 30}; // toggle the OWL led and ask for the led status
@@ -148,11 +148,11 @@
 			if(phase > 2 * M_PI)
 				phase -= 2 * M_PI;
 			float value = sinf(phase) * gVelocity/128.0f;
-			audioWriteFrame(context, n, 0, value);
-			audioWriteFrame(context, n, 1, value);
+			audioWrite(context, n, 0, value);
+			audioWrite(context, n, 1, value);
 		} else {
-			audioWriteFrame(context, n, 0, 0);
-			audioWriteFrame(context, n, 1, 0);
+			audioWrite(context, n, 0, 0);
+			audioWrite(context, n, 1, 0);
 		}
 	}
 }
--- a/examples/basic_network/render.cpp	Fri May 27 18:55:34 2016 +0100
+++ b/examples/basic_network/render.cpp	Fri May 27 19:00:43 2016 +0100
@@ -56,7 +56,7 @@
 		float in;
 		int ret = receive.getSamplesSrc(&in, 1, 1);
 		for(unsigned int channel = 0; channel < context->audioChannels; channel++){
-			audioWriteFrame(context, n, channel, in);
+			audioWrite(context, n, channel, in);
 		}
 	}
 }
--- a/examples/basic_passthru/render.cpp	Fri May 27 18:55:34 2016 +0100
+++ b/examples/basic_passthru/render.cpp	Fri May 27 19:00:43 2016 +0100
@@ -42,7 +42,7 @@
 			// 		context->audioIn[n * context->audioChannels + ch];
 
 			// Or using the macros:
-			audioWriteFrame(context, n, ch, audioReadFrame(context, n, ch));
+			audioWrite(context, n, ch, audioRead(context, n, ch));
 		}
 	}
 
@@ -55,7 +55,7 @@
 			// context->analogOut[n * context->analogChannels + ch] = context->analogIn[n * context->analogChannels + ch];
 
 			// Or using the macros:
-			analogWriteFrame(context, n, ch, analogReadFrame(context, n, ch));
+			analogWrite(context, n, ch, analogRead(context, n, ch));
 		}
 	}
 }
--- a/examples/basic_pulseIn/render.cpp	Fri May 27 18:55:34 2016 +0100
+++ b/examples/basic_pulseIn/render.cpp	Fri May 27 19:00:43 2016 +0100
@@ -28,7 +28,7 @@
 
 bool setup(BelaContext *context, void *userData)
 {
-	pinModeFrame(context, 0, gDigitalOutPin, OUTPUT);
+	pinMode(context, 0, gDigitalOutPin, OUTPUT);
 	pulseIn.init(context, gPulseInPin, 1); //third parameter is direction
 	return true;
 }
@@ -59,7 +59,7 @@
 			pulseOut = true;
 			count = 0;
 		}
-		digitalWriteFrame(context, n, gDigitalOutPin, pulseOut);
+		digitalWrite(context, n, gDigitalOutPin, pulseOut);
 		count++;
 	}
 }
--- a/examples/bucket_brigade_chorus/render.cpp	Fri May 27 18:55:34 2016 +0100
+++ b/examples/bucket_brigade_chorus/render.cpp	Fri May 27 19:00:43 2016 +0100
@@ -93,11 +93,11 @@
 
 	for(unsigned int n = 0; n < context->audioFrames; n++) {
 		feedback = 0.4;
-		float input = audioReadFrame(context, n, 0) + audioReadFrame(context, n, 1);
+		float input = audioRead(context, n, 0) + audioRead(context, n, 1);
 	    delay[writePointer++] = input + delay[readPointer]*feedback;
 	    float output = (input + 0.9*delay[readPointer++] ) * 0.5;
-		audioWriteFrame(context, n, 0, output);
-		audioWriteFrame(context, n, 1, output);
+		audioWrite(context, n, 0, output);
+		audioWrite(context, n, 1, output);
 		if(writePointer>=delayLength)
 			writePointer-=delayLength;
 		if(readPointer>=delayLength)
--- a/examples/cape_test/render.cpp	Fri May 27 18:55:34 2016 +0100
+++ b/examples/cape_test/render.cpp	Fri May 27 19:00:43 2016 +0100
@@ -110,7 +110,7 @@
 
 				}
 				else {
-					if(!((context->audioSampleCount + n) % 22050)) {
+					if(!((context->audioFramesElapsed + n) % 22050)) {
 						// Debugging print messages
 						if((gPositivePeakLevels[0] - gNegativePeakLevels[0]) < gPeakLevelHighThreshold)
 							rt_printf("Left Audio In FAIL: insufficient signal: %f\n", 
@@ -155,7 +155,7 @@
 					}
 				}
 				else {
-					if(!((context->audioSampleCount + n) % 22050)) {
+					if(!((context->audioFramesElapsed + n) % 22050)) {
 						// Debugging print messages
 						if((gPositivePeakLevels[1] - gNegativePeakLevels[1]) < gPeakLevelHighThreshold)
 							rt_printf("Right Audio In FAIL: insufficient signal: %f\n", 
@@ -182,7 +182,7 @@
 
 			// If one second has gone by with no error, play one sound, else
 			// play another
-			if(context->audioSampleCount + n - gLastErrorFrame > 44100) {
+			if(context->audioFramesElapsed + n - gLastErrorFrame > 44100) {
 				gEnvelopeValueL *= gEnvelopeDecayRate;
 				gEnvelopeValueR *= gEnvelopeDecayRate;
 				gEnvelopeSampleCount++;
@@ -233,13 +233,13 @@
 				if(k == invertChannel) {
 					if(context->analogIn[n*8 + k] < ANALOG_HIGH) {
 						rt_printf("FAIL [output %d, input %d] -- output HIGH input %f (inverted)\n", gDACPinOrder[k], k, context->analogIn[n*8 + k]);
-						gLastErrorFrame = context->audioSampleCount + n;
+						gLastErrorFrame = context->audioFramesElapsed + n;
 					}
 				}
 				else {
 					if(context->analogIn[n*8 + k] > ANALOG_LOW) {
 						rt_printf("FAIL [output %d, input %d] -- output LOW --> input %f\n", gDACPinOrder[k], k, context->analogIn[n*8 + k]);
-						gLastErrorFrame = context->audioSampleCount + n;
+						gLastErrorFrame = context->audioFramesElapsed + n;
 					}
 				}
 			}
@@ -249,13 +249,13 @@
 				if(k == invertChannel) {
 					if(context->analogIn[n*8 + k] > ANALOG_LOW) {
 						rt_printf("FAIL [output %d, input %d] -- output LOW input %f (inverted)\n", gDACPinOrder[k], k, context->analogIn[n*8 + k]);
-						gLastErrorFrame = context->audioSampleCount + n;
+						gLastErrorFrame = context->audioFramesElapsed + n;
 					}
 				}
 				else {
 					if(context->analogIn[n*8 + k] < ANALOG_HIGH) {
 						rt_printf("FAIL [output %d, input %d] -- output HIGH input %f\n", gDACPinOrder[k], k, context->analogIn[n*8 + k]);
-						gLastErrorFrame = context->audioSampleCount + n;
+						gLastErrorFrame = context->audioFramesElapsed + n;
 					}
 				}
 			}
--- a/examples/d-box/config.h	Fri May 27 18:55:34 2016 +0100
+++ b/examples/d-box/config.h	Fri May 27 19:00:43 2016 +0100
@@ -21,9 +21,6 @@
 #define DBOX_USE_XENOMAI
 //#define OLD_OSCBANK
 
-/* Define this if the new cape is in use (changes pinouts and I2C address) */
-#define DBOX_CAPE
-
 #ifdef DBOX_USE_XENOMAI
 // Xenomai-specific includes
 #include <sys/mman.h>
--- a/examples/gpioAnalogLoopbackTest/render.cpp	Fri May 27 18:55:34 2016 +0100
+++ b/examples/gpioAnalogLoopbackTest/render.cpp	Fri May 27 19:00:43 2016 +0100
@@ -34,9 +34,9 @@
 			context->analogChannels, context->audioFrames);
 
 	for(unsigned int n = 0; n < context->digitalFrames; n++){
-		pinModeFrame(context, n, gDigitalInACh, INPUT);
-		pinModeFrame(context, n, gDigitalInDCh, INPUT);
-		pinModeFrame(context, n, gDigitalOutCh, OUTPUT);
+		pinMode(context, n, gDigitalInACh, INPUT);
+		pinMode(context, n, gDigitalInDCh, INPUT);
+		pinMode(context, n, gDigitalOutCh, OUTPUT);
 	}
 	switch (context->analogChannels){
 		case 2:
@@ -99,20 +99,20 @@
 		static int count = 0;
 		bool doReadWrite = context->analogChannels<=4 ? true : ((context->analogChannels == 8) && (n&1)==0);
 		if(doReadWrite){
-			digitalAIn = digitalReadFrame(context, n, gDigitalInACh);
+			digitalAIn = digitalRead(context, n, gDigitalInACh);
 			switch(context->analogChannels){
 			case 8:
-				analog0In = analogReadFrame(context, n/2, 0) > 0.5;
-				analogWriteFrame(context, n/2, analogOut, writePattern[outPointer]);
+				analog0In = analogRead(context, n/2, 0) > 0.5;
+				analogWrite(context, n/2, analogOut, writePattern[outPointer]);
 				break;
 			case 4:
-				analog0In = analogReadFrame(context, n, 0) > 0.5;
-				analogWriteFrame(context, n, analogOut, writePattern[outPointer]);
+				analog0In = analogRead(context, n, 0) > 0.5;
+				analogWrite(context, n, analogOut, writePattern[outPointer]);
 				break;
 			case 2:
-				analog0In = analogReadFrame(context, n * 2 + 1, 0) > 0.5;
-				analogWriteFrame(context, 2 * n, analogOut, writePattern[outPointer]);
-				analogWriteFrame(context, 2 * n + 1, analogOut, writePattern[outPointer]);
+				analog0In = analogRead(context, n * 2 + 1, 0) > 0.5;
+				analogWrite(context, 2 * n, analogOut, writePattern[outPointer]);
+				analogWrite(context, 2 * n + 1, analogOut, writePattern[outPointer]);
 				break;
 			}
 			gAnalogOutLoopDelay--;
@@ -150,24 +150,24 @@
  */
 		bool doReadWrite = false;
 		static bool pastAnalog1In = false;
-		digitalWriteFrameOnce(context, n, gDigitalOutCh,  writePattern[digitalOutPointer]);
+		digitalWriteOnce(context, n, gDigitalOutCh,  writePattern[digitalOutPointer]);
 		if(context->analogChannels == 8){
 			if((n&1) == 0){ //do it every other sample
-				pastAnalog1In = analogReadFrame(context, n/2, 1) > 0.5;
-				digitalDIn = digitalReadFrame(context, n, gDigitalInDCh);
+				pastAnalog1In = analogRead(context, n/2, 1) > 0.5;
+				digitalDIn = digitalRead(context, n, gDigitalInDCh);
 				doReadWrite = true;
 			}
 		}
 		if(context->analogChannels == 4){
-			pastAnalog1In = analogReadFrame(context, n, 1) > 0.5;
-			digitalDIn = digitalReadFrame(context, n, gDigitalInDCh);
-			digitalWriteFrameOnce(context, n, gDigitalOutCh,  writePattern[digitalOutPointer]);
+			pastAnalog1In = analogRead(context, n, 1) > 0.5;
+			digitalDIn = digitalRead(context, n, gDigitalInDCh);
+			digitalWriteOnce(context, n, gDigitalOutCh,  writePattern[digitalOutPointer]);
 			doReadWrite = true;
 		}
 		if(context->analogChannels == 2){
-			pastAnalog1In = analogReadFrame(context, n * 2, 1) > 0.5;
-			digitalDIn = digitalReadFrame(context, n, gDigitalInDCh);
-			digitalWriteFrameOnce(context, n, gDigitalOutCh,  writePattern[digitalOutPointer]);
+			pastAnalog1In = analogRead(context, n * 2, 1) > 0.5;
+			digitalDIn = digitalRead(context, n, gDigitalInDCh);
+			digitalWriteOnce(context, n, gDigitalOutCh,  writePattern[digitalOutPointer]);
 			doReadWrite = true;
 		}
 		bool expectedDigitalIn = writePattern[digitalInPointer];
@@ -190,7 +190,7 @@
 		}
 		count++;
 	}
-	if(context->audioSampleCount > 30000){
+	if(context->audioFramesElapsed > 30000){
 		gShouldStop = true;
 	}
 }
@@ -202,7 +202,7 @@
 		rt_printf("Test was succesful with %d analog channels and a buffer size of %d\n", context->analogChannels, context->audioFrames);
 	} else {
 		rt_printf("------------------------\n%danalog %ddigital errors over %dsamples while running test with ",
-				anaErrorCount, digErrorCount, context->audioSampleCount);
+				anaErrorCount, digErrorCount, context->audioFramesElapsed);
 		rt_printf("%d analog channels and a buffer size of %d \n\n\n",
 				context->analogChannels, context->audioFrames);
 		exit(1);
--- a/examples/level_meter/render.cpp	Fri May 27 18:55:34 2016 +0100
+++ b/examples/level_meter/render.cpp	Fri May 27 19:00:43 2016 +0100
@@ -60,7 +60,7 @@
 	
 	for(int i = 0; i < NUMBER_OF_SEGMENTS; i++) {
 		gSamplesToLight[i] = 0;
-		pinModeFrame(context, 0, i, OUTPUT);
+		pinMode(context, 0, i, OUTPUT);
 	}
 
 	return true;
@@ -105,7 +105,7 @@
 		else {
 			// Make peak decay slowly by only multiplying
 			// every few samples
-			if(((context->audioSampleCount + n) & 31) == 0)
+			if(((context->audioFramesElapsed + n) & 31) == 0)
 				gAudioPeakLevel *= gPeakDecayRate;
 		}	
 		// LED bargraph on digital outputs 0-9
@@ -126,7 +126,7 @@
 				state = HIGH;
 			
 			// Write LED
-			digitalWriteFrameOnce(context, n, led, state);
+			digitalWriteOnce(context, n, led, state);
 		}
 	}
 }
--- a/examples/scope_analogue/render.cpp	Fri May 27 18:55:34 2016 +0100
+++ b/examples/scope_analogue/render.cpp	Fri May 27 19:00:43 2016 +0100
@@ -30,8 +30,8 @@
 	for(unsigned int n = 0; n < context->audioFrames; n++) {
 	    
 	    // read analogIn channels 0 and 1
-	    float in1 = analogReadFrame(context, n, 0);
-	    float in2 = analogReadFrame(context, n, 1);
+	    float in1 = analogRead(context, n, 0);
+	    float in2 = analogRead(context, n, 1);
 	    
 	    // map in1 to amplitude and in2 to frequency
 	    float amplitude = in1 * 0.8f;
--- a/examples/stepper/render.cpp	Fri May 27 18:55:34 2016 +0100
+++ b/examples/stepper/render.cpp	Fri May 27 19:00:43 2016 +0100
@@ -58,11 +58,11 @@
 		return false;
 	}
 	
-	pinModeFrame(context, 0, gPinA1, OUTPUT);
-	pinModeFrame(context, 0, gPinA2, OUTPUT);
-	pinModeFrame(context, 0, gPinB1, OUTPUT);
-	pinModeFrame(context, 0, gPinB2, OUTPUT);
-	pinModeFrame(context, 0, gPinServo, OUTPUT);
+	pinMode(context, 0, gPinA1, OUTPUT);
+	pinMode(context, 0, gPinA2, OUTPUT);
+	pinMode(context, 0, gPinB1, OUTPUT);
+	pinMode(context, 0, gPinB2, OUTPUT);
+	pinMode(context, 0, gPinServo, OUTPUT);
 		
 	return true;
 }
@@ -76,27 +76,27 @@
 {
 	for(unsigned int n = 0; n < context->audioFrames; n++) {
 		if(gPhase == 0 || gPhase == 1) {
-			digitalWriteFrameOnce(context, n, gPinB1, HIGH);
-			digitalWriteFrameOnce(context, n, gPinB2, LOW);
+			digitalWriteOnce(context, n, gPinB1, HIGH);
+			digitalWriteOnce(context, n, gPinB2, LOW);
 		}
 		else {
-			digitalWriteFrameOnce(context, n, gPinB1, LOW);
-			digitalWriteFrameOnce(context, n, gPinB2, HIGH);			
+			digitalWriteOnce(context, n, gPinB1, LOW);
+			digitalWriteOnce(context, n, gPinB2, HIGH);			
 		}
 		
 		if(gPhase == 1 || gPhase == 2) {
-			digitalWriteFrameOnce(context, n, gPinA1, HIGH);
-			digitalWriteFrameOnce(context, n, gPinA2, LOW);
+			digitalWriteOnce(context, n, gPinA1, HIGH);
+			digitalWriteOnce(context, n, gPinA2, LOW);
 		}
 		else {
-			digitalWriteFrameOnce(context, n, gPinA1, LOW);
-			digitalWriteFrameOnce(context, n, gPinA2, HIGH);			
+			digitalWriteOnce(context, n, gPinA1, LOW);
+			digitalWriteOnce(context, n, gPinA2, HIGH);			
 		}
 		
 		if(--gServoCounter > 0) 
-			digitalWriteFrameOnce(context, n, gPinServo, HIGH);
+			digitalWriteOnce(context, n, gPinServo, HIGH);
 		else
-			digitalWriteFrameOnce(context, n, gPinServo, LOW);
+			digitalWriteOnce(context, n, gPinServo, LOW);
 		
 		if(++gStepCounter >= gStepLengthSamples) {
 			gStateCounter++;
--- a/examples/tank_wars/render.cpp	Fri May 27 18:55:34 2016 +0100
+++ b/examples/tank_wars/render.cpp	Fri May 27 19:00:43 2016 +0100
@@ -202,7 +202,7 @@
 		}
 
 		// First-order lowpass filter to remove noise on launch FSR
-		float rawSample = analogReadFrame(context, n, gInputLauncher);
+		float rawSample = analogRead(context, n, gInputLauncher);
 		float launchSample = gLauncherFilterPole * gLauncherLastSample +
 							(1.0f - gLauncherFilterPole) * rawSample;
 		gLauncherLastSample = launchSample;
@@ -236,9 +236,9 @@
 			// Update game physics and cannon angles
 			gSamplesUntilNextFrame = gGameFrameInterval;
 
-			setTank1CannonAngle(map(analogReadFrame(context, n, gInputTank1Angle),
+			setTank1CannonAngle(map(analogRead(context, n, gInputTank1Angle),
 									0, 1.0, M_PI, 0));
-			setTank2CannonAngle(map(analogReadFrame(context, n, gInputTank2Angle),
+			setTank2CannonAngle(map(analogRead(context, n, gInputTank2Angle),
 									0, 1.0, M_PI, 0));
 			nextGameFrame();
 
@@ -265,21 +265,21 @@
 
 			// Rescale screen coordinates to matrix ranges; invert the Y
 			// coordinate to go from normal screen coordinates to scope coordinates
-			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));
+			analogWriteOnce(context, n, gOutputX, constrain(map(x, 0, gScreenWidth, 0, 1.0), 0, 1.0));
+			analogWriteOnce(context, n, gOutputY, constrain(map(y, 0, gScreenHeight, 1.0, 0), 0, 1.0));
 		}
 		else {
 			// Still not ready! Write 0 until something happens
-			analogWriteFrameOnce(context, n, gOutputX, 0);
-			analogWriteFrameOnce(context, n, gOutputY, 0);
+			analogWriteOnce(context, n, gOutputX, 0);
+			analogWriteOnce(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;
-			analogWriteFrameOnce(context, n, gOutputPlayer1LED, gameStatusWinner() == 1 ? val : 0);
-			analogWriteFrameOnce(context, n, gOutputPlayer2LED, gameStatusWinner() == 2 ? val : 0);
+			analogWriteOnce(context, n, gOutputPlayer1LED, gameStatusWinner() == 1 ? val : 0);
+			analogWriteOnce(context, n, gOutputPlayer2LED, gameStatusWinner() == 2 ? val : 0);
 
 			// After 5 seconds, restart the game
 			gSamplesSinceFinish++;
@@ -289,16 +289,16 @@
 		else if(gameStatusProjectileInMotion()) {
 			// Blink both LEDs when projectile is in motion
 			float val = (gSampleCounter % 2000 > 1000) ? 1.0 : 0;
-			analogWriteFrameOnce(context, n, gOutputPlayer1LED, val);
-			analogWriteFrameOnce(context, n, gOutputPlayer2LED, val);
+			analogWriteOnce(context, n, gOutputPlayer1LED, val);
+			analogWriteOnce(context, n, gOutputPlayer2LED, val);
 		}
 		else if(gameStatusPlayer1Turn()) {
-			analogWriteFrameOnce(context, n, gOutputPlayer1LED, 1.0);
-			analogWriteFrameOnce(context, n, gOutputPlayer2LED, 0);
+			analogWriteOnce(context, n, gOutputPlayer1LED, 1.0);
+			analogWriteOnce(context, n, gOutputPlayer2LED, 0);
 		}
 		else {
-			analogWriteFrameOnce(context, n, gOutputPlayer2LED, 1.0);
-			analogWriteFrameOnce(context, n, gOutputPlayer1LED, 0);
+			analogWriteOnce(context, n, gOutputPlayer2LED, 1.0);
+			analogWriteOnce(context, n, gOutputPlayer1LED, 0);
 		}
 
 		// Check if we have reached the point where we should next update
--- a/include/Bela.h	Fri May 27 18:55:34 2016 +0100
+++ b/include/Bela.h	Fri May 27 19:00:43 2016 +0100
@@ -37,12 +37,7 @@
 // Useful constants
 
 /** \cond PRIVATE */
-#define DBOX_CAPE					// New custom cape
-#ifdef DBOX_CAPE
 #define CODEC_I2C_ADDRESS  0x18		// Address of TLV320AIC3104 codec
-#else
-#define CODEC_I2C_ADDRESS  0x1B		// Address of TLV320AIC3106 codec
-#endif
 
 #define MAX_PRU_FILENAME_LENGTH 256
 #define MAX_SERVERNAME_LENGTH 256
@@ -181,50 +176,50 @@
 	/// This buffer may be in either interleaved or non-interleaved format,
 	/// depending on the contents of the BelaInitSettings structure.
 	/// \b Note: this element is available in render() only.
-	float *audioIn;
+	const float * const audioIn;
 
 	/// \brief Buffer holding audio output samples
 	///
 	/// This buffer may be in either interleaved or non-interleaved format,
 	/// depending on the contents of the BelaInitSettings structure.
 	/// \b Note: this element is available in render() only.
-	float *audioOut;
+	float * const audioOut;
 
 	/// \brief Buffer holding analog input samples
 	///
 	/// This buffer may be in either interleaved or non-interleaved format,
 	/// depending on the contents of the BelaInitSettings structure.
 	/// \b Note: this element is available in render() only.
-	float *analogIn;
+	const float * const analogIn;
 
 	/// \brief Buffer holding analog output samples
 	///
 	/// This buffer may be in either interleaved or non-interleaved format,
 	/// depending on the contents of the BelaInitSettings structure.
 	/// \b Note: this element is available in render() only.
-	float *analogOut;
+	float * const analogOut;
 
 	/// \brief Buffer holding digital input/output samples
 	///
 	/// \b Note: this element is available in render() only.
-	uint32_t *digital;
+	uint32_t * const digital;
 
 	/// Number of audio frames per period
-	uint32_t audioFrames;
+	const uint32_t audioFrames;
 	/// Number of audio channels (currently always 2)
-	uint32_t audioChannels;
+	const uint32_t audioChannels;
 	/// Audio sample rate in Hz (currently always 44100.0)
-	float audioSampleRate;
+	const float audioSampleRate;
 
 	/// \brief Number of analog frames per period
 	///
 	/// This will be 0 if analog I/O is disabled.
-	uint32_t analogFrames;
+	const uint32_t analogFrames;
 
 	/// \brief Number of analog channels
 	///
 	/// This could take a value of 8, 4 or 2. This will be 0 if analog I/O is disabled.
-	uint32_t analogChannels;
+	const uint32_t analogChannels;
 
 	/// \brief Analog sample rate in Hz
 	///
@@ -232,24 +227,24 @@
 	/// 8 channels are used, the sample rate is 22050. If 4 channels are used, the sample
 	/// rate is 44100. If 2 channels are used, the sample rate is 88200. If analog I/O
 	/// is disabled, the sample rate is 0.
-	float analogSampleRate;
+	const float analogSampleRate;
 
 	/// Number of digital frames per period
-	uint32_t digitalFrames;
+	const uint32_t digitalFrames;
 	/// \brief Number of digital channels
 	///
 	/// Currently this will always be 16, unless digital I/O is disabled, in which case it will be 0.
-	uint32_t digitalChannels;
+	const uint32_t digitalChannels;
 	/// Digital sample rate in Hz (currently always 44100.0)
-	float digitalSampleRate;
+	const float digitalSampleRate;
 
-	/// \brief Number of elapsed audio samples since the start of rendering.
+	/// \brief Number of elapsed audio frames since the start of rendering.
 	///
-	/// This holds the total number of audio samples as of the beginning of the current period. To
-	/// find the current number of analog or digital samples elapsed, multiply by the ratio of the
-	/// sample rates (e.g. half the number of analog samples will have elapsed if the analog sample
+	/// This holds the total number of audio frames as of the beginning of the current period. To
+	/// find the current number of analog or digital frames elapsed, multiply by the ratio of the
+	/// sample rates (e.g. half the number of analog frames will have elapsed if the analog sample
 	/// rate is 22050).
-	uint64_t audioSampleCount;
+	const uint64_t audioFramesElapsed;
 
 	/// \brief Other audio/sensor settings
 	///
@@ -259,7 +254,7 @@
 	///
 	/// BELA_FLAG_ANALOG_OUTPUTS_PERSIST: indicates that writes to the analog outputs will
 	/// persist for future frames. If not set, writes affect one frame only.
-	uint32_t flags;
+	const uint32_t flags;
 } BelaContext;
 
 /** \ingroup auxtask
--- a/include/PRU.h	Fri May 27 18:55:34 2016 +0100
+++ b/include/PRU.h	Fri May 27 19:00:43 2016 +0100
@@ -12,6 +12,101 @@
 #include <native/intr.h>
 #include "../include/Bela.h"
 
+/**
+ * Internal version of the BelaContext struct which does not have const
+ * elements, so it can be modified by the code. When it's passed to the user
+ * code, it is typecast to the standard BelaContext.
+ *
+ * Important: make sure this retains the same structure as BelaContext!
+ */
+typedef struct {
+	/// \brief Buffer holding audio input samples
+	///
+	/// This buffer may be in either interleaved or non-interleaved format,
+	/// depending on the contents of the BelaInitSettings structure.
+	/// \b Note: this element is available in render() only.
+	float *audioIn;
+
+	/// \brief Buffer holding audio output samples
+	///
+	/// This buffer may be in either interleaved or non-interleaved format,
+	/// depending on the contents of the BelaInitSettings structure.
+	/// \b Note: this element is available in render() only.
+	float *audioOut;
+
+	/// \brief Buffer holding analog input samples
+	///
+	/// This buffer may be in either interleaved or non-interleaved format,
+	/// depending on the contents of the BelaInitSettings structure.
+	/// \b Note: this element is available in render() only.
+	float *analogIn;
+
+	/// \brief Buffer holding analog output samples
+	///
+	/// This buffer may be in either interleaved or non-interleaved format,
+	/// depending on the contents of the BelaInitSettings structure.
+	/// \b Note: this element is available in render() only.
+	float *analogOut;
+
+	/// \brief Buffer holding digital input/output samples
+	///
+	/// \b Note: this element is available in render() only.
+	uint32_t *digital;
+
+	/// Number of audio frames per period
+	uint32_t audioFrames;
+	/// Number of audio channels (currently always 2)
+	uint32_t audioChannels;
+	/// Audio sample rate in Hz (currently always 44100.0)
+	float audioSampleRate;
+
+	/// \brief Number of analog frames per period
+	///
+	/// This will be 0 if analog I/O is disabled.
+	uint32_t analogFrames;
+
+	/// \brief Number of analog channels
+	///
+	/// This could take a value of 8, 4 or 2. This will be 0 if analog I/O is disabled.
+	uint32_t analogChannels;
+
+	/// \brief Analog sample rate in Hz
+	///
+	/// The analog sample rate depends on the number of analog channels used. If
+	/// 8 channels are used, the sample rate is 22050. If 4 channels are used, the sample
+	/// rate is 44100. If 2 channels are used, the sample rate is 88200. If analog I/O
+	/// is disabled, the sample rate is 0.
+	float analogSampleRate;
+
+	/// Number of digital frames per period
+	uint32_t digitalFrames;
+	/// \brief Number of digital channels
+	///
+	/// Currently this will always be 16, unless digital I/O is disabled, in which case it will be 0.
+	uint32_t digitalChannels;
+	/// Digital sample rate in Hz (currently always 44100.0)
+	float digitalSampleRate;
+
+	/// \brief Number of elapsed audio frames since the start of rendering.
+	///
+	/// This holds the total number of audio frames as of the beginning of the current period. To
+	/// find the current number of analog or digital frames elapsed, multiply by the ratio of the
+	/// sample rates (e.g. half the number of analog frames will have elapsed if the analog sample
+	/// rate is 22050).
+	uint64_t audioFramesElapsed;
+
+	/// \brief Other audio/sensor settings
+	///
+	/// Binary combination of flags including:
+	///
+	/// BELA_FLAG_INTERLEAVED: indicates the audio and analog buffers are interleaved
+	///
+	/// BELA_FLAG_ANALOG_OUTPUTS_PERSIST: indicates that writes to the analog outputs will
+	/// persist for future frames. If not set, writes affect one frame only.
+	uint32_t flags;
+} InternalBelaContext;
+
+
 class PRU
 {
 private:
@@ -23,7 +118,7 @@
 
 public:
 	// Constructor
-	PRU(BelaContext *input_context);
+	PRU(InternalBelaContext *input_context);
 
 	// Destructor
 	~PRU();
@@ -56,7 +151,7 @@
 	void clearGPIOTestPin();
 
 private:
-	BelaContext *context;	// Overall settings
+	InternalBelaContext *context;	// Overall settings
 
 	int pru_number;		// Which PRU we use
 	bool running;		// Whether the PRU is running
--- a/include/PulseIn.h	Fri May 27 18:55:34 2016 +0100
+++ b/include/PulseIn.h	Fri May 27 19:00:43 2016 +0100
@@ -46,7 +46,7 @@
 	 * than hasPulsed() is because user might not query for hasPulsed() every sample,
 	 * so we are safe so long as they call hasPulsed() or check() at least once per buffer.
 	 * Also, results are cached (i.e.: we do not check() for pulses twice for the same context.
-	 * context->audioSampleCount is used as an identifier.
+	 * context->audioFramesElapsed is used as an identifier.
 	 */
 	void check(BelaContext* context);
 
@@ -58,7 +58,7 @@
 	 * @return the length of the pulse if a pulse ending was detected at sample n, zero otherwise.
 	 */
 	int hasPulsed(BelaContext* context, int frame){//let's leave this in PulseIn.h to allow the compiler to optimize out the call.
-		if(_lastContext != context->audioSampleCount){ // check for pulses in the whole context and cache the result
+		if(_lastContext != context->audioFramesElapsed){ // check for pulses in the whole context and cache the result
 			check(context);
 		}
 		return _array[frame];
--- a/include/Utilities.h	Fri May 27 18:55:34 2016 +0100
+++ b/include/Utilities.h	Fri May 27 19:00:43 2016 +0100
@@ -67,7 +67,6 @@
  * @{
  */
 
-#if 1
 // 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?
@@ -85,7 +84,7 @@
  * (context->audioChannels - 1), typically 0 to 1 by default.
  * \return Value of the analog input, range  to 1.
  */
-static inline float audioReadFrame(BelaContext *context, int frame, int channel);
+static inline float audioRead(BelaContext *context, int frame, int channel);
 
 /**
  * \brief Write an audio output, specifying the frame number (when to write) and the channel.
@@ -100,7 +99,7 @@
  * (context->audioChannels - 1), typically 0 to 1 by default.
  * \param value Value to write to the output, range -1 to 1.
  */
-static inline void audioWriteFrame(BelaContext *context, int frame, int channel, float value);
+static inline void audioWrite(BelaContext *context, int frame, int channel, float value);
 
 /**
  * \brief Read an analog input, specifying the frame number (when to read) and the channel.
@@ -115,7 +114,7 @@
  * (context->analogChannels - 1), typically 0 to 7 by default.
  * \return Value of the analog input, range 0 to 1.
  */
-static inline float analogReadFrame(BelaContext *context, int frame, int channel);
+static inline float analogRead(BelaContext *context, int frame, int channel);
 
 /**
  * \brief Write an analog output, specifying the frame number (when to write) and the channel.
@@ -133,7 +132,7 @@
  * (context->analogChannels - 1), typically 0 to 7 by default.
  * \param value Value to write to the output, range 0 to 1.
  */
-static inline void analogWriteFrame(BelaContext *context, int frame, int channel, float value);
+static inline void analogWrite(BelaContext *context, int frame, int channel, float value);
 
 /**
  * \brief Write an analog output, specifying the frame number (when to write) and the channel.
@@ -141,11 +140,11 @@
  * This function sets the value of an analog output, at the time indicated by \c frame. Valid
  * values are between 0 and 1, corresponding to the range 0 to 5V.
  *
- * Unlike analogWriteFrame(), the value written will affect \b only the frame specified, with
- * future values unchanged. This is faster than analogWriteFrame() so is better suited
+ * Unlike analogWrite(), the value written will affect \b only the frame specified, with
+ * future values unchanged. This is faster than analogWrite() so is better suited
  * to applications where every frame will be written to a different value. If
  * BELA_FLAG_ANALOG_OUTPUTS_PERSIST is not set within context->flags, then
- * analogWriteFrameOnce() and analogWriteFrame() are equivalent.
+ * analogWriteOnce() and analogWrite() are equivalent.
  *
  * \param context The I/O data structure which is passed by Bela to render().
  * \param frame Which frame (i.e. what time) to write the analog output. Valid values range
@@ -154,7 +153,7 @@
  * (context->analogChannels - 1), typically 0 to 7 by default.
  * \param value Value to write to the output, range 0 to 1.
  */
-static inline void analogWriteFrameOnce(BelaContext *context, int frame, int channel, float value);
+static inline void analogWriteOnce(BelaContext *context, int frame, int channel, float value);
 
 /**
  * \brief Read a digital input, specifying the frame number (when to read) and the pin.
@@ -170,7 +169,7 @@
  * digital_gpio_mapping.h.
  * \return Value of the digital input.
  */
-static inline int digitalReadFrame(BelaContext *context, int frame, int channel);
+static inline int digitalRead(BelaContext *context, int frame, int channel);
 
 /**
  * \brief Write a digital output, specifying the frame number (when to write) and the pin.
@@ -188,7 +187,7 @@
  * digital_gpio_mapping.h.
  * \param value Value to write to the output.
  */
-static inline void digitalWriteFrame(BelaContext *context, int frame, int channel, int value);
+static inline void digitalWrite(BelaContext *context, int frame, int channel, int value);
 
 /**
  * \brief Write a digital output, specifying the frame number (when to write) and the pin.
@@ -196,8 +195,8 @@
  * This function sets the value of a digital output, at the time indicated by \c frame.
  * A value of 0 sets the pin low; any other value sets the pin high (3.3V).
  *
- * Unlike digitalWriteFrame(), the value written will affect \b only the frame specified, with
- * future values unchanged. This is faster than digitalWriteFrame() so is better suited
+ * Unlike digitalWrite(), the value written will affect \b only the frame specified, with
+ * future values unchanged. This is faster than digitalWrite() so is better suited
  * to applications where every frame will be written to a different value.
  *
  * \param context The I/O data structure which is passed by Bela to render().
@@ -208,7 +207,7 @@
  * digital_gpio_mapping.h.
  * \param value Value to write to the output.
  */
-static inline void digitalWriteFrameOnce(BelaContext *context, int frame, int channel, int value);
+static inline void digitalWriteOnce(BelaContext *context, int frame, int channel, int value);
 
 /**
  * \brief Set the direction of a digital pin to input or output.
@@ -226,7 +225,7 @@
  * digital_gpio_mapping.h.
  * \param value Direction of the pin (\c INPUT or \c OUTPUT).
  */
-static inline void pinModeFrame(BelaContext *context, int frame, int channel, int mode);
+static inline void pinMode(BelaContext *context, int frame, int channel, int mode);
 
 /**
  * \brief Set the direction of a digital pin to input or output.
@@ -244,46 +243,10 @@
  * digital_gpio_mapping.h.
  * \param value Direction of the pin (\c INPUT or \c OUTPUT).
  */
-static inline void pinModeFrameOnce(BelaContext *context, int frame, int channel, int mode);
+static inline void pinModeOnce(BelaContext *context, int frame, int channel, int mode);
 
 /** @} */
 
-#else
-
-// Macros for accessing the analog values: usable _only_ within render()
-
-// Read an Analog input from input pin p at frame f
-#define analogRead(p, f) (analogIn[(f)*gNumAnalogChannels + (p)])
-// Write an Analog output frame at output pin p, frame f, to value v
-#define analogWriteFrame(p, f, v) (analogOut[(f)*gNumAnalogChannels + (p)] = (v))
-#define analogWrite(pin, frame, value) \
-(({do {\
-	for (int _privateI=(frame); _privateI<numAnalogFrames; _privateI++){ \
-		analogWriteFrame(pin,_privateI,value); \
-	}\
-	} while (0);}),(void)0)\
-
-
-//digital API:
-#define setDigitalDirectionFrame(pin,frame,direction) digital[(frame)]=changeBit(digital[(frame)],(pin),(direction)),void(0)
-#define setDigitalDirection(pin,frame,direction)\
-		(({do {\
-			for(int _privateI=(frame); _privateI<numDigitalFrames; _privateI++)\
-				setDigitalDirectionFrame(pin,_privateI,direction);\
-			} while (0);}), (void)0)
-#define digitalWriteAll(frame,value) digital[(frame)]=0xffff0000*(!(!value));
-//sets the bit in the high word, clears the bit in the low word (just in case the direction was not previously set)
-#define digitalWriteFrame(pin, frame, value) digital[(frame)]=( changeBit(digital[(frame)], (pin+16), (value)) & (0xffffffff-(1<<(pin))) ) //could have been done with two subsequent assignments
-#define digitalWrite(pin, frame, value) \
-	(({do {\
-		for (int _privateI=(frame); _privateI<numDigitalFrames; _privateI++) \
-			digitalWriteFrame(pin,_privateI,value); \
-		} while (0);}),(void)0)\
-
-#define digitalRead(pin, frame) ( getBit(digital[(frame)], pin+16) )
-
-#endif
-
 /**
  * \defgroup wiring Wiring language support
  *
@@ -332,32 +295,32 @@
 static inline float constrain(float x, float min_val, float max_val);
 
 /** @} */
-// audioReadFrame()
+// audioRead()
 //
 // Returns the value of the given audio input at the given frame number.
-static inline float audioReadFrame(BelaContext *context, int frame, int channel) {
+static inline float audioRead(BelaContext *context, int frame, int channel) {
 	return context->audioIn[frame * context->audioChannels + channel];
 }
 
-// audioWriteFrame()
+// audioWrite()
 //
 // Sets a given audio output channel to a value for the current frame
-static inline void audioWriteFrame(BelaContext *context, int frame, int channel, float value) {
+static inline void audioWrite(BelaContext *context, int frame, int channel, float value) {
 	context->audioOut[frame * context->audioChannels + channel] = value;
 }
 
-// analogReadFrame()
+// analogRead()
 //
 // Returns the value of the given analog input at the given frame number.
-static inline float analogReadFrame(BelaContext *context, int frame, int channel) {
+static inline float analogRead(BelaContext *context, int frame, int channel) {
 	return context->analogIn[frame * context->analogChannels + channel];
 }
 
-// analogWriteFrame()
+// analogWrite()
 //
 // Sets a given analog output channel to a value for the current frame and, if persistent outputs are
 // enabled, for all subsequent frames
-static inline void analogWriteFrame(BelaContext *context, int frame, int channel, float value) {
+static inline void analogWrite(BelaContext *context, int frame, int channel, float value) {
 	if(context->flags & BELA_FLAG_ANALOG_OUTPUTS_PERSIST) {
 		for(unsigned int f = frame; f < context->analogFrames; f++)
 			context->analogOut[frame * context->analogChannels + channel] = value;
@@ -366,24 +329,24 @@
 		context->analogOut[frame * context->analogChannels + channel] = value;
 }
 
-// analogWriteFrameOnce()
+// analogWriteOnce()
 //
 // Sets a given channel to a value for only the current frame
-static inline void analogWriteFrameOnce(BelaContext *context, int frame, int channel, float value) {
+static inline void analogWriteOnce(BelaContext *context, int frame, int channel, float value) {
 	context->analogOut[frame * context->analogChannels + channel] = value;
 }
 
-// digitalReadFrame()
+// digitalRead()
 //
 // Returns the value of a given digital input at the given frame number
-static inline int digitalReadFrame(BelaContext *context, int frame, int channel) {
+static inline int digitalRead(BelaContext *context, int frame, int channel) {
 	return getBit(context->digital[frame], channel + 16);
 }
 
-// digitalWriteFrame()
+// digitalWrite()
 //
 // Sets a given digital output channel to a value for the current frame and all subsequent frames
-static inline void digitalWriteFrame(BelaContext *context, int frame, int channel, int value) {
+static inline void digitalWrite(BelaContext *context, int frame, int channel, int value) {
 	for(unsigned int f = frame; f < context->digitalFrames; f++) {
 		if(value)
 			context->digital[f] |= 1 << (channel + 16);
@@ -392,20 +355,20 @@
 	}
 }
 
-// digitalWriteFrameOnce()
+// digitalWriteOnce()
 //
 // Sets a given digital output channel to a value for the current frame only
-static inline void digitalWriteFrameOnce(BelaContext *context, int frame, int channel, int value) {
+static inline void digitalWriteOnce(BelaContext *context, int frame, int channel, int value) {
 	if(value)
 		context->digital[frame] |= 1 << (channel + 16);
 	else
 		context->digital[frame] &= ~(1 << (channel + 16));
 }
 
-// pinModeFrame()
+// pinMode()
 //
 // Sets the direction of a digital pin for the current frame and all subsequent frames
-static inline void pinModeFrame(BelaContext *context, int frame, int channel, int mode) {
+static inline void pinMode(BelaContext *context, int frame, int channel, int mode) {
 	for(unsigned int f = frame; f < context->digitalFrames; f++) {
 		if(mode == INPUT)
 			context->digital[f] |= (1 << channel);
@@ -414,10 +377,10 @@
 	}
 }
 
-// pinModeFrameOnce()
+// pinModeOnce()
 //
 // Sets the direction of a digital pin for the current frame only
-static inline void pinModeFrameOnce(BelaContext *context, int frame, int channel, int mode) {
+static inline void pinModeOnce(BelaContext *context, int frame, int channel, int mode) {
 	if(mode == INPUT)
 		context->digital[frame] |= (1 << channel);
 	else
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/resources/initd-bela	Fri May 27 19:00:43 2016 +0100
@@ -0,0 +1,28 @@
+#! /bin/sh
+# /etc/init.d/bela
+#
+
+# Some things that run always
+# ...nothing to do here
+
+# Carry out specific functions when asked to by the system
+case "$1" in
+  start)
+    echo "Adding Bela PRU Overlay..."
+    echo BB-BONE-PRU-BELA > /sys/devices/bone_capemgr.9/slots
+    echo "Adding Bela Audio Cape Overlay..."
+    echo BB-BONE-BAREAUDI-02 > /sys/devices/bone_capemgr.9/slots
+    cd /root
+    sh BeagleRT_startup.sh
+    sh BeagleRT_node.sh
+    ;;
+  stop)
+    pkill BeagleRT
+    ;;
+  *)
+    echo "Usage: /etc/init.d/bela {start|stop}"
+    exit 1
+    ;;
+esac
+
+exit 0
--- a/scripts/setup_board.sh	Fri May 27 18:55:34 2016 +0100
+++ b/scripts/setup_board.sh	Fri May 27 19:00:43 2016 +0100
@@ -38,7 +38,7 @@
 SCRIPTPATH=$(readlink "$0")
 SCRIPTDIR=$(dirname "$SCRIPTPATH")
 
-read -p "Warning: this script will DELETE any existing BeagleRT files from your BeagleBone! Continue? (y/N)" -r
+read -p "Warning: this script will DELETE any existing BeagleRT files from your BeagleBone! Continue? (y/N) " -r
 echo
 if [[ $REPLY = [yY]  ]]
 then