changeset 187:d7148d21aaa5

Utilities are now optimizable. Closes #1526
author Giulio Moro <giuliomoro@yahoo.it>
date Tue, 19 Jan 2016 02:54:13 +0000
parents 524c87ec23a3
children c706be7daad7
files .cproject core/Utilities.cpp include/BeagleRT.h include/Utilities.h projects/basic_midi/render.cpp
diffstat 5 files changed, 140 insertions(+), 143 deletions(-) [+]
line wrap: on
line diff
--- a/.cproject	Tue Jan 19 01:54:34 2016 +0000
+++ b/.cproject	Tue Jan 19 02:54:13 2016 +0000
@@ -121,7 +121,7 @@
 							<targetPlatform id="cdt.managedbuild.target.gnu.platform.exe.release.908983575" name="Debug Platform" superClass="cdt.managedbuild.target.gnu.platform.exe.release"/>
 							<builder arguments="-j6" buildPath="${workspace_loc:/BBB_audio+input/Release}" command="make" id="cdt.managedbuild.target.gnu.builder.exe.release.511190290" keepEnvironmentInBuildfile="false" managedBuildOn="true" name="Gnu Make Builder" superClass="cdt.managedbuild.target.gnu.builder.exe.release"/>
 							<tool command="arm-linux-gnueabihf-g++&#10;" id="cdt.managedbuild.tool.gnu.archiver.base.810674388" name="GCC Archiver" superClass="cdt.managedbuild.tool.gnu.archiver.base"/>
-							<tool command="arm-linux-gnueabihf-g++&#10;" commandLinePattern="${COMMAND} ${FLAGS} ${OUTPUT_FLAG} ${OUTPUT_PREFIX}${OUTPUT} ${INPUTS}" id="cdt.managedbuild.tool.gnu.cpp.compiler.exe.release.163790048" name="GCC C++ Compiler" superClass="cdt.managedbuild.tool.gnu.cpp.compiler.exe.release">
+							<tool command="arm-linux-gnueabihf-gcc" commandLinePattern="${COMMAND} ${FLAGS} ${OUTPUT_FLAG} ${OUTPUT_PREFIX}${OUTPUT} ${INPUTS}" id="cdt.managedbuild.tool.gnu.cpp.compiler.exe.release.163790048" name="GCC C++ Compiler" superClass="cdt.managedbuild.tool.gnu.cpp.compiler.exe.release">
 								<option id="gnu.cpp.compiler.exe.release.option.optimization.level.2031085570" name="Optimization Level" superClass="gnu.cpp.compiler.exe.release.option.optimization.level" value="gnu.cpp.compiler.optimization.level.more" valueType="enumerated"/>
 								<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">
@@ -150,7 +150,7 @@
 								<inputType id="cdt.managedbuild.tool.gnu.c.compiler.input.574072828" superClass="cdt.managedbuild.tool.gnu.c.compiler.input"/>
 							</tool>
 							<tool command="arm-linux-gnueabihf-g++&#10;" id="cdt.managedbuild.tool.gnu.c.linker.exe.release.281634187" name="GCC C Linker" superClass="cdt.managedbuild.tool.gnu.c.linker.exe.release"/>
-							<tool command="arm-linux-gnueabihf-g++&#10;" id="cdt.managedbuild.tool.gnu.cpp.linker.exe.release.929570421" name="GCC C++ Linker" superClass="cdt.managedbuild.tool.gnu.cpp.linker.exe.release">
+							<tool command="arm-linux-gnueabihf-g++" id="cdt.managedbuild.tool.gnu.cpp.linker.exe.release.929570421" name="GCC C++ Linker" superClass="cdt.managedbuild.tool.gnu.cpp.linker.exe.release">
 								<option id="gnu.cpp.link.option.paths.277042583" name="Library search path (-L)" superClass="gnu.cpp.link.option.paths" valueType="libPaths">
 									<listOptionValue builtIn="false" value="/usr/arm-linux-gnueabihf/lib"/>
 									<listOptionValue builtIn="false" value="/usr/arm-linux-gnueabihf/lib/xenomai"/>
@@ -160,6 +160,8 @@
 								</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"/>
+									<listOptionValue builtIn="false" value="porttime"/>
+									<listOptionValue builtIn="false" value="portmidi"/>
 									<listOptionValue builtIn="false" value="native"/>
 									<listOptionValue builtIn="false" value="xenomai"/>
 								</option>
--- a/core/Utilities.cpp	Tue Jan 19 01:54:34 2016 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,123 +0,0 @@
-/*
- * Utilities.cpp
- *
- *  Created on: Oct 27, 2014
- *      Author: parallels
- */
-
-#include "../include/Utilities.h"
-
-// audioReadFrame()
-//
-// Returns the value of the given audio input at the given frame number.
-float audioReadFrame(BeagleRTContext *context, int frame, int channel) {
-	return context->audioIn[frame * context->audioChannels + channel];
-}
-
-// audioWriteFrame()
-//
-// Sets a given audio output channel to a value for the current frame
-void audioWriteFrame(BeagleRTContext *context, int frame, int channel, float value) {
-	context->audioOut[frame * context->audioChannels + channel] = value;
-}
-
-// analogReadFrame()
-//
-// Returns the value of the given analog input at the given frame number.
-float analogReadFrame(BeagleRTContext *context, int frame, int channel) {
-	return context->analogIn[frame * context->analogChannels + channel];
-}
-
-// analogWriteFrame()
-//
-// Sets a given analog output channel to a value for the current frame and, if persistent outputs are
-// enabled, for all subsequent frames
-void analogWriteFrame(BeagleRTContext *context, int frame, int channel, float value) {
-	if(context->flags & BEAGLERT_FLAG_ANALOG_OUTPUTS_PERSIST) {
-		for(unsigned int f = frame; f < context->analogFrames; f++)
-			context->analogOut[frame * context->analogChannels + channel] = value;
-	}
-	else
-		context->analogOut[frame * context->analogChannels + channel] = value;
-}
-
-// analogWriteFrameOnce()
-//
-// Sets a given channel to a value for only the current frame
-void analogWriteFrameOnce(BeagleRTContext *context, int frame, int channel, float value) {
-	context->analogOut[frame * context->analogChannels + channel] = value;
-}
-
-// digitalReadFrame()
-//
-// Returns the value of a given digital input at the given frame number
-int digitalReadFrame(BeagleRTContext *context, int frame, int channel) {
-	return getBit(context->digital[frame], channel + 16);
-}
-
-// digitalWriteFrame()
-//
-// Sets a given digital output channel to a value for the current frame and all subsequent frames
-void digitalWriteFrame(BeagleRTContext *context, int frame, int channel, int value) {
-	for(unsigned int f = frame; f < context->digitalFrames; f++) {
-		if(value)
-			context->digital[f] |= 1 << (channel + 16);
-		else
-			context->digital[f] &= ~(1 << (channel + 16));
-	}
-}
-
-// digitalWriteFrameOnce()
-//
-// Sets a given digital output channel to a value for the current frame only
-void digitalWriteFrameOnce(BeagleRTContext *context, int frame, int channel, int value) {
-	if(value)
-		context->digital[frame] |= 1 << (channel + 16);
-	else
-		context->digital[frame] &= ~(1 << (channel + 16));
-}
-
-// pinModeFrame()
-//
-// Sets the direction of a digital pin for the current frame and all subsequent frames
-void pinModeFrame(BeagleRTContext *context, int frame, int channel, int mode) {
-	for(unsigned int f = frame; f < context->digitalFrames; f++) {
-		if(mode == INPUT)
-			context->digital[f] |= (1 << channel);
-		else
-			context->digital[f] &= ~(1 << channel);
-	}
-}
-
-// pinModeFrameOnce()
-//
-// Sets the direction of a digital pin for the current frame only
-void pinModeFrameOnce(BeagleRTContext *context, int frame, int channel, int mode) {
-	if(mode == INPUT)
-		context->digital[frame] |= (1 << channel);
-	else
-		context->digital[frame] &= ~(1 << channel);
-}
-
-// map()
-//
-// Scale an input value from one range to another. Works like its Wiring language equivalent.
-// x is the value to scale; in_min and in_max are the input range; out_min and out_max
-// are the output range.
-
-float map(float x, float in_min, float in_max, float out_min, float out_max)
-{
-	return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
-}
-
-// constrain()
-//
-// Clips an input value to be between two end points
-// x is the value to constrain; min_val and max_val are the range
-
-float constrain(float x, float min_val, float max_val)
-{
-	if(x < min_val) return min_val;
-	if(x > max_val) return max_val;
-	return x;
-}
--- a/include/BeagleRT.h	Tue Jan 19 01:54:34 2016 +0000
+++ b/include/BeagleRT.h	Tue Jan 19 02:54:13 2016 +0000
@@ -609,5 +609,6 @@
 void BeagleRT_scheduleAuxiliaryTask(AuxiliaryTask task);
 
 /** @} */
+#include <Utilities.h>
 
 #endif /* BEAGLERT_H_ */
--- a/include/Utilities.h	Tue Jan 19 01:54:34 2016 +0000
+++ b/include/Utilities.h	Tue Jan 19 02:54:13 2016 +0000
@@ -31,11 +31,13 @@
  * @{
  */
 
-#define HIGH 0x1
-#define LOW  0x0
+#ifndef INPUT
+	#define INPUT 0x0
+#endif /* INPUT */
 
-#define INPUT 0x0
-#define OUTPUT 0x1
+#ifndef OUTPUT
+	#define OUTPUT 0x1
+#endif /* OUTPUT */
 
 /** @} */
 
@@ -83,7 +85,7 @@
  * (context->audioChannels - 1), typically 0 to 1 by default.
  * \return Value of the analog input, range  to 1.
  */
-float audioReadFrame(BeagleRTContext *context, int frame, int channel);
+static inline float audioReadFrame(BeagleRTContext *context, int frame, int channel);
 
 /**
  * \brief Write an audio output, specifying the frame number (when to write) and the channel.
@@ -98,7 +100,7 @@
  * (context->audioChannels - 1), typically 0 to 1 by default.
  * \param value Value to write to the output, range -1 to 1.
  */
-void audioWriteFrame(BeagleRTContext *context, int frame, int channel, float value);
+static inline void audioWriteFrame(BeagleRTContext *context, int frame, int channel, float value);
 
 /**
  * \brief Read an analog input, specifying the frame number (when to read) and the channel.
@@ -113,7 +115,7 @@
  * (context->analogChannels - 1), typically 0 to 7 by default.
  * \return Value of the analog input, range 0 to 1.
  */
-float analogReadFrame(BeagleRTContext *context, int frame, int channel);
+static inline float analogReadFrame(BeagleRTContext *context, int frame, int channel);
 
 /**
  * \brief Write an analog output, specifying the frame number (when to write) and the channel.
@@ -131,7 +133,7 @@
  * (context->analogChannels - 1), typically 0 to 7 by default.
  * \param value Value to write to the output, range 0 to 1.
  */
-void analogWriteFrame(BeagleRTContext *context, int frame, int channel, float value);
+static inline void analogWriteFrame(BeagleRTContext *context, int frame, int channel, float value);
 
 /**
  * \brief Write an analog output, specifying the frame number (when to write) and the channel.
@@ -152,7 +154,7 @@
  * (context->analogChannels - 1), typically 0 to 7 by default.
  * \param value Value to write to the output, range 0 to 1.
  */
-void analogWriteFrameOnce(BeagleRTContext *context, int frame, int channel, float value);
+static inline void analogWriteFrameOnce(BeagleRTContext *context, int frame, int channel, float value);
 
 /**
  * \brief Read a digital input, specifying the frame number (when to read) and the pin.
@@ -168,7 +170,7 @@
  * digital_gpio_mapping.h.
  * \return Value of the digital input.
  */
-int digitalReadFrame(BeagleRTContext *context, int frame, int channel);
+static inline int digitalReadFrame(BeagleRTContext *context, int frame, int channel);
 
 /**
  * \brief Write a digital output, specifying the frame number (when to write) and the pin.
@@ -186,7 +188,7 @@
  * digital_gpio_mapping.h.
  * \param value Value to write to the output.
  */
-void digitalWriteFrame(BeagleRTContext *context, int frame, int channel, int value);
+static inline void digitalWriteFrame(BeagleRTContext *context, int frame, int channel, int value);
 
 /**
  * \brief Write a digital output, specifying the frame number (when to write) and the pin.
@@ -206,7 +208,7 @@
  * digital_gpio_mapping.h.
  * \param value Value to write to the output.
  */
-void digitalWriteFrameOnce(BeagleRTContext *context, int frame, int channel, int value);
+static inline void digitalWriteFrameOnce(BeagleRTContext *context, int frame, int channel, int value);
 
 /**
  * \brief Set the direction of a digital pin to input or output.
@@ -224,7 +226,7 @@
  * digital_gpio_mapping.h.
  * \param value Direction of the pin (\c INPUT or \c OUTPUT).
  */
-void pinModeFrame(BeagleRTContext *context, int frame, int channel, int mode);
+static inline void pinModeFrame(BeagleRTContext *context, int frame, int channel, int mode);
 
 /**
  * \brief Set the direction of a digital pin to input or output.
@@ -242,7 +244,7 @@
  * digital_gpio_mapping.h.
  * \param value Direction of the pin (\c INPUT or \c OUTPUT).
  */
-void pinModeFrameOnce(BeagleRTContext *context, int frame, int channel, int mode);
+static inline void pinModeFrameOnce(BeagleRTContext *context, int frame, int channel, int mode);
 
 /** @} */
 
@@ -309,7 +311,7 @@
  * \param out_max Upper bound of the output range.
  * \return Rescaled value.
  */
-float map(float x, float in_min, float in_max, float out_min, float out_max);
+static inline float map(float x, float in_min, float in_max, float out_min, float out_max);
 
 /**
  * \brief Constrain a number to stay within a given range.
@@ -327,8 +329,124 @@
  * \param max_val Maximum possible value.
  * \return Constrained value.
  */
-float constrain(float x, float min_val, float max_val);
+static inline float constrain(float x, float min_val, float max_val);
 
 /** @} */
+// audioReadFrame()
+//
+// Returns the value of the given audio input at the given frame number.
+static inline float audioReadFrame(BeagleRTContext *context, int frame, int channel) {
+	return context->audioIn[frame * context->audioChannels + channel];
+}
+
+// audioWriteFrame()
+//
+// Sets a given audio output channel to a value for the current frame
+static inline void audioWriteFrame(BeagleRTContext *context, int frame, int channel, float value) {
+	context->audioOut[frame * context->audioChannels + channel] = value;
+}
+
+// analogReadFrame()
+//
+// Returns the value of the given analog input at the given frame number.
+static inline float analogReadFrame(BeagleRTContext *context, int frame, int channel) {
+	return context->analogIn[frame * context->analogChannels + channel];
+}
+
+// analogWriteFrame()
+//
+// 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(BeagleRTContext *context, int frame, int channel, float value) {
+	if(context->flags & BEAGLERT_FLAG_ANALOG_OUTPUTS_PERSIST) {
+		for(unsigned int f = frame; f < context->analogFrames; f++)
+			context->analogOut[frame * context->analogChannels + channel] = value;
+	}
+	else
+		context->analogOut[frame * context->analogChannels + channel] = value;
+}
+
+// analogWriteFrameOnce()
+//
+// Sets a given channel to a value for only the current frame
+static inline void analogWriteFrameOnce(BeagleRTContext *context, int frame, int channel, float value) {
+	context->analogOut[frame * context->analogChannels + channel] = value;
+}
+
+// digitalReadFrame()
+//
+// Returns the value of a given digital input at the given frame number
+static inline int digitalReadFrame(BeagleRTContext *context, int frame, int channel) {
+	return getBit(context->digital[frame], channel + 16);
+}
+
+// digitalWriteFrame()
+//
+// Sets a given digital output channel to a value for the current frame and all subsequent frames
+static inline void digitalWriteFrame(BeagleRTContext *context, int frame, int channel, int value) {
+	for(unsigned int f = frame; f < context->digitalFrames; f++) {
+		if(value)
+			context->digital[f] |= 1 << (channel + 16);
+		else
+			context->digital[f] &= ~(1 << (channel + 16));
+	}
+}
+
+// digitalWriteFrameOnce()
+//
+// Sets a given digital output channel to a value for the current frame only
+static inline void digitalWriteFrameOnce(BeagleRTContext *context, int frame, int channel, int value) {
+	if(value)
+		context->digital[frame] |= 1 << (channel + 16);
+	else
+		context->digital[frame] &= ~(1 << (channel + 16));
+}
+
+// pinModeFrame()
+//
+// Sets the direction of a digital pin for the current frame and all subsequent frames
+static inline void pinModeFrame(BeagleRTContext *context, int frame, int channel, int mode) {
+	for(unsigned int f = frame; f < context->digitalFrames; f++) {
+		if(mode == INPUT)
+			context->digital[f] |= (1 << channel);
+		else
+			context->digital[f] &= ~(1 << channel);
+	}
+}
+
+// pinModeFrameOnce()
+//
+// Sets the direction of a digital pin for the current frame only
+static inline void pinModeFrameOnce(BeagleRTContext *context, int frame, int channel, int mode) {
+	if(mode == INPUT)
+		context->digital[frame] |= (1 << channel);
+	else
+		context->digital[frame] &= ~(1 << channel);
+}
+
+
+
+// map()
+//
+// Scale an input value from one range to another. Works like its Wiring language equivalent.
+// x is the value to scale; in_min and in_max are the input range; out_min and out_max
+// are the output range.
+
+static inline float map(float x, float in_min, float in_max, float out_min, float out_max)
+{
+	return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
+}
+
+// constrain()
+//
+// Clips an input value to be between two end points
+// x is the value to constrain; min_val and max_val are the range
+
+static inline float constrain(float x, float min_val, float max_val)
+{
+	if(x < min_val) return min_val;
+	if(x > max_val) return max_val;
+	return x;
+}
 
 #endif /* UTILITIES_H_ */
--- a/projects/basic_midi/render.cpp	Tue Jan 19 01:54:34 2016 +0000
+++ b/projects/basic_midi/render.cpp	Tue Jan 19 02:54:13 2016 +0000
@@ -5,11 +5,10 @@
  *      Author: parallels
  */
 
-
 #include <BeagleRT.h>
 #include <Midi.h>
+#include <Utilities.h>
 #include <stdlib.h>
-#include <Utilities.h>
 #include <rtdk.h>
 #include <cmath>