changeset 307:ff5f346a293e prerelease

Changed BelaContext fields to be const where appropriate; there's now an InternalBelaContext used for setting the values within the core code. These need to stay aligned.
author andrewm
date Fri, 27 May 2016 18:12:15 +0100
parents 132fc61893af
children 1feb9c23ac57
files core/PRU.cpp core/RTAudio.cpp include/Bela.h include/PRU.h scripts/setup_board.sh
diffstat 5 files changed, 123 insertions(+), 27 deletions(-) [+]
line wrap: on
line diff
--- a/core/PRU.cpp	Fri May 27 18:00:57 2016 +0100
+++ b/core/PRU.cpp	Fri May 27 18:12:15 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) {
--- a/core/RTAudio.cpp	Fri May 27 18:00:57 2016 +0100
+++ b/core/RTAudio.cpp	Fri May 27 18:12:15 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/include/Bela.h	Fri May 27 18:00:57 2016 +0100
+++ b/include/Bela.h	Fri May 27 18:12:15 2016 +0100
@@ -181,50 +181,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,16 +232,16 @@
 	/// 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.
 	///
@@ -249,7 +249,7 @@
 	/// 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
 	/// rate is 22050).
-	uint64_t audioSampleCount;
+	const uint64_t audioSampleCount;
 
 	/// \brief Other audio/sensor settings
 	///
@@ -259,7 +259,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:00:57 2016 +0100
+++ b/include/PRU.h	Fri May 27 18:12:15 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 samples 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
+	/// rate is 22050).
+	uint64_t audioSampleCount;
+
+	/// \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/scripts/setup_board.sh	Fri May 27 18:00:57 2016 +0100
+++ b/scripts/setup_board.sh	Fri May 27 18:12:15 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