changeset 311:493a07f6ec09 prerelease

Renamed BelaContext->audioSampleCount to BelaContext->audioFramesElapsed for consistency of terminology
author andrewm
date Fri, 27 May 2016 18:37:51 +0100
parents 02c4ca0e3718
children 00725dfc1b87
files core/PRU.cpp core/PulseIn.cpp examples/analogDigitalDemo/render.cpp examples/cape_test/render.cpp examples/gpioAnalogLoopbackTest/render.cpp examples/level_meter/render.cpp examples/tank_wars/render.cpp include/Bela.h include/PRU.h include/PulseIn.h
diffstat 10 files changed, 44 insertions(+), 44 deletions(-) [+]
line wrap: on
line diff
--- a/core/PRU.cpp	Fri May 27 18:29:20 2016 +0100
+++ b/core/PRU.cpp	Fri May 27 18:37:51 2016 +0100
@@ -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:29:20 2016 +0100
+++ b/core/PulseIn.cpp	Fri May 27 18:37:51 2016 +0100
@@ -26,17 +26,17 @@
 	for(unsigned int n = 0; n < context->digitalFrames; n++){
 		if(_pulseIsOn == false){ // look for start edge
 			if(digitalRead(context, n, _digitalInput) == _pulseOnState){
-				_pulseStart = context->audioSampleCount + n; // store location of start edge
+				_pulseStart = context->audioFramesElapsed + n; // store location of start edge
 				_pulseIsOn = true;
 			}
 		} else { // _pulseIsOn == true;
 			if(digitalRead(context, n, _digitalInput) == !_pulseOnState){ // look for stop edge
-				_array[n] = context->audioSampleCount + n - _pulseStart; // compute and store pulse duration
+				_array[n] = context->audioFramesElapsed + n - _pulseStart; // compute and store pulse duration
 				_pulseIsOn = false;
 			}
 		}
 	}
-	_lastContext = context->audioSampleCount;
+	_lastContext = context->audioFramesElapsed;
 };
 
 PulseIn::~PulseIn() {
--- a/examples/analogDigitalDemo/render.cpp	Fri May 27 18:29:20 2016 +0100
+++ b/examples/analogDigitalDemo/render.cpp	Fri May 27 18:37:51 2016 +0100
@@ -36,7 +36,7 @@
   /*
   * 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
 		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
@@ -67,14 +67,14 @@
         //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
+        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++){
-    	analogWrite(context, n, 1, (context->audioSampleCount&8191)/8192.0); // writes a single frame. channel 1 is a ramp that follows gCountFrames
+    	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++)
--- a/examples/cape_test/render.cpp	Fri May 27 18:29:20 2016 +0100
+++ b/examples/cape_test/render.cpp	Fri May 27 18:37:51 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/gpioAnalogLoopbackTest/render.cpp	Fri May 27 18:29:20 2016 +0100
+++ b/examples/gpioAnalogLoopbackTest/render.cpp	Fri May 27 18:37:51 2016 +0100
@@ -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:29:20 2016 +0100
+++ b/examples/level_meter/render.cpp	Fri May 27 18:37:51 2016 +0100
@@ -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
--- a/examples/tank_wars/render.cpp	Fri May 27 18:29:20 2016 +0100
+++ b/examples/tank_wars/render.cpp	Fri May 27 18:37:51 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:29:20 2016 +0100
+++ b/include/Bela.h	Fri May 27 18:37:51 2016 +0100
@@ -243,13 +243,13 @@
 	/// Digital sample rate in Hz (currently always 44100.0)
 	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).
-	const uint64_t audioSampleCount;
+	const uint64_t audioFramesElapsed;
 
 	/// \brief Other audio/sensor settings
 	///
--- a/include/PRU.h	Fri May 27 18:29:20 2016 +0100
+++ b/include/PRU.h	Fri May 27 18:37:51 2016 +0100
@@ -87,13 +87,13 @@
 	/// Digital sample rate in Hz (currently always 44100.0)
 	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;
+	uint64_t audioFramesElapsed;
 
 	/// \brief Other audio/sensor settings
 	///
--- a/include/PulseIn.h	Fri May 27 18:29:20 2016 +0100
+++ b/include/PulseIn.h	Fri May 27 18:37:51 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];