changeset 179:f1012082f142

Added audioReadFrame() and audioWriteFrame(). Closes #1519
author Giulio Moro <giuliomoro@yahoo.it>
date Sat, 02 Jan 2016 13:50:36 +0100
parents a156a694864d
children 07cfd337ad18
files core/Utilities.cpp include/Utilities.h
diffstat 2 files changed, 45 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/core/Utilities.cpp	Sat Jan 02 13:08:39 2016 +0100
+++ b/core/Utilities.cpp	Sat Jan 02 13:50:36 2016 +0100
@@ -7,6 +7,20 @@
 
 #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.
@@ -16,7 +30,7 @@
 
 // analogWriteFrame()
 //
-// Sets a given channel to a value for the current frame and, if persistent outputs are
+// 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) {
--- a/include/Utilities.h	Sat Jan 02 13:08:39 2016 +0100
+++ b/include/Utilities.h	Sat Jan 02 13:50:36 2016 +0100
@@ -71,6 +71,36 @@
 // Also, make volume change functions callable from render() thread -- as an aux task?
 
 /**
+ * \brief Read an audio input, specifying the frame number (when to read) and the channel.
+ *
+ * This function returns the value of an audio input, at the time indicated by \c frame.
+ * The returned value ranges from -1 to 1.
+ *
+ * \param context The I/O data structure which is passed by BeagleRT to render().
+ * \param frame Which frame (i.e. what time) to read the audio input. Valid values range
+ * from 0 to (context->audioFrames - 1).
+ * \param channel Which audio input to read. Valid values are between 0 and
+ * (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);
+
+/**
+ * \brief Write an audio output, specifying the frame number (when to write) and the channel.
+ *
+ * This function sets the value of an audio output, at the time indicated by \c frame. Valid
+ * values are between -1 and 1.
+ *
+ * \param context The I/O data structure which is passed by BeagleRT to render().
+ * \param frame Which frame (i.e. what time) to write the audio output. Valid values range
+ * from 0 to (context->audioFrames - 1).
+ * \param channel Which analog output to write. Valid values are between 0 and
+ * (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);
+
+/**
  * \brief Read an analog input, specifying the frame number (when to read) and the channel.
  *
  * This function returns the value of an analog input, at the time indicated by \c frame.