Comment additions

master
boblark 1 month ago
parent 8fbac3562b
commit ce3a933e05
  1. 6
      AudioSettings_F32.h
  2. 17
      AudioStream_F32.cpp
  3. 86
      AudioStream_F32.h

@ -2,7 +2,7 @@
#ifndef _AudioSettings_F32_ #ifndef _AudioSettings_F32_
#define _AudioSettings_F32_ #define _AudioSettings_F32_
#include <AudioStream.h> // for AUDIO_SAMPLE_RATE_EXACT, AUDIO_BLOCK_SAMPLES #include <AudioStream.h> // 16-bit audio for AUDIO_SAMPLE_RATE_EXACT, AUDIO_BLOCK_SAMPLES
class AudioSettings_F32 { class AudioSettings_F32 {
public: public:
@ -10,11 +10,11 @@ class AudioSettings_F32 {
sample_rate_Hz(fs_Hz), audio_block_samples(block_size) {} sample_rate_Hz(fs_Hz), audio_block_samples(block_size) {}
const float sample_rate_Hz; const float sample_rate_Hz;
const int audio_block_samples; const int audio_block_samples;
float cpu_load_percent(const int n); float cpu_load_percent(const int n);
float processorUsage(void); float processorUsage(void);
float processorUsageMax(void); float processorUsageMax(void);
void processorUsageMaxReset(void); void processorUsageMaxReset(void);
}; };
#endif #endif

@ -67,19 +67,19 @@ audio_block_f32_t * AudioStream_F32::allocate_f32(void)
audio_block_f32_t *block; audio_block_f32_t *block;
uint8_t used; uint8_t used;
// f32_memory_pool_available_mask is array of six 32-bit uints with a 1 in position of // f32_memory_pool_available_mask is array of six 32-bit uints with a 1 in position of
// each available block (max 192). 0 if unavailable (busy) or not allocated at all. // each available block (max 192). 0 if unavailable (busy) or not allocated at all.
p = f32_memory_pool_available_mask; p = f32_memory_pool_available_mask;
/* /*
if(millis() > 1200) { if(millis() > 1200) {
Serial.print("AudioStream_F32 "); Serial.print("AudioStream_F32 ");
Serial.println((uint32_t)*p, BIN); // Just first of 6 Serial.println((uint32_t)*p, BIN); // Just first of 6
} }
*/ */
__disable_irq(); __disable_irq();
do { do {
avail = *p; if (avail) break; avail = *p; if (avail) break;
@ -196,4 +196,3 @@ void AudioConnection_F32::connect(void) {
dst.active = true; dst.active = true;
__enable_irq(); __enable_irq();
} }

@ -1,15 +1,46 @@
/* /*
* AudioStream_F32 * AudioStream_F32
* *
* Created: Chip Audette, November 2016 * Created: Chip Audette, November 2016
* Purpose; Extend the Teensy Audio Library's "AudioStream" to permit floating-point audio data. * Purpose; Extend the Teensy Audio Library's "AudioStream" to permit floating-point audio data.
* *
* I modeled it directly on the Teensy code in "AudioStream.h" and "AudioStream.cpp", which are * I modeled it directly on the Teensy code in "AudioStream.h" and "AudioStream.cpp", which are
* available here: https://github.com/PaulStoffregen/cores/tree/master/teensy3 * available here: https://github.com/PaulStoffregen/cores/tree/master/teensy3
* *
* Added id to audio_block_f32_t class, per Tympan. Bob Larkin June 2020 * Added id to audio_block_f32_t class, per Tympan. Bob Larkin June 2020
* *
* MIT License. use at your own risk. *
* Thse classes are derived from their equivalents in Teensyduino. Thus:
* Teensyduino Core Library
* http://www.pjrc.com/teensy/
* Copyright (c) 2017 PJRC.COM, LLC.
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* 1. The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* 2. If the Software is incorporated into a build system that allows
* selection among a list of target devices, then similar target
* devices manufactured by PJRC.COM must be included in the list of
* target devices and selectable in the same manner.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
* All additions are under MIT License. use at your own risk.
*/ */
#ifndef _AudioStream_F32_h #ifndef _AudioStream_F32_h
@ -32,22 +63,23 @@ class AudioConnection_F32;
//https://github.com/PaulStoffregen/cores/blob/268848cdb0121f26b7ef6b82b4fb54abbe465427/teensy3/AudioStream.h //https://github.com/PaulStoffregen/cores/blob/268848cdb0121f26b7ef6b82b4fb54abbe465427/teensy3/AudioStream.h
// Added id, per Tympan. Should not disturb existing programs. Bob Larkin June 2020 // Added id, per Tympan. Should not disturb existing programs. Bob Larkin June 2020
class audio_block_f32_t { class audio_block_f32_t {
public: public:
audio_block_f32_t(void) {}; audio_block_f32_t(void) {};
audio_block_f32_t(const AudioSettings_F32 &settings) { audio_block_f32_t(const AudioSettings_F32 &settings) {
fs_Hz = settings.sample_rate_Hz; fs_Hz = settings.sample_rate_Hz;
length = settings.audio_block_samples; length = settings.audio_block_samples;
}; };
unsigned char ref_count; unsigned char ref_count;
unsigned char memory_pool_index; unsigned char memory_pool_index;
unsigned char reserved1; unsigned char reserved1;
unsigned char reserved2; unsigned char reserved2;
float32_t data[AUDIO_BLOCK_SAMPLES]; // AUDIO_BLOCK_SAMPLES is 128, from AudioStream.h float32_t data[AUDIO_BLOCK_SAMPLES]; // AUDIO_BLOCK_SAMPLES is 128, from AudioStream.h
const int full_length = AUDIO_BLOCK_SAMPLES; const int full_length = AUDIO_BLOCK_SAMPLES;
int length = AUDIO_BLOCK_SAMPLES; // AUDIO_BLOCK_SAMPLES is 128, from AudioStream.h int length = AUDIO_BLOCK_SAMPLES; // AUDIO_BLOCK_SAMPLES is 128, from AudioStream.h
float fs_Hz = AUDIO_SAMPLE_RATE; // AUDIO_SAMPLE_RATE is 44117.64706 from AudioStream.h // For Teensy 4.x, AUDIO_SAMPLE_RATE is 44100
unsigned long id; float fs_Hz = AUDIO_SAMPLE_RATE; // T3.x AUDIO_SAMPLE_RATE is 44117.64706
unsigned long id;
}; };
class AudioConnection_F32 class AudioConnection_F32
@ -76,7 +108,7 @@ class AudioConnection_F32
class AudioStream_F32 : public AudioStream { class AudioStream_F32 : public AudioStream {
public: public:
AudioStream_F32(unsigned char n_input_f32, audio_block_f32_t **iqueue) : AudioStream(1, inputQueueArray_i16), AudioStream_F32(unsigned char n_input_f32, audio_block_f32_t **iqueue) : AudioStream(1, inputQueueArray_i16),
num_inputs_f32(n_input_f32), inputQueue_f32(iqueue) { num_inputs_f32(n_input_f32), inputQueue_f32(iqueue) {
//active_f32 = false; //active_f32 = false;
destination_list_f32 = NULL; destination_list_f32 = NULL;
@ -86,20 +118,20 @@ class AudioStream_F32 : public AudioStream {
}; };
static void initialize_f32_memory(audio_block_f32_t *data, unsigned int num); static void initialize_f32_memory(audio_block_f32_t *data, unsigned int num);
static void initialize_f32_memory(audio_block_f32_t *data, unsigned int num, const AudioSettings_F32 &settings); static void initialize_f32_memory(audio_block_f32_t *data, unsigned int num, const AudioSettings_F32 &settings);
//virtual void update(audio_block_f32_t *) = 0; //virtual void update(audio_block_f32_t *) = 0;
static uint8_t f32_memory_used; static uint8_t f32_memory_used;
static uint8_t f32_memory_used_max; static uint8_t f32_memory_used_max;
static audio_block_f32_t * allocate_f32(void); static audio_block_f32_t * allocate_f32(void);
static void release(audio_block_f32_t * block); static void release(audio_block_f32_t * block);
protected: protected:
//bool active_f32; //bool active_f32;
unsigned char num_inputs_f32; unsigned char num_inputs_f32;
void transmit(audio_block_f32_t *block, unsigned char index = 0); void transmit(audio_block_f32_t *block, unsigned char index = 0);
audio_block_f32_t * receiveReadOnly_f32(unsigned int index = 0); audio_block_f32_t * receiveReadOnly_f32(unsigned int index = 0);
audio_block_f32_t * receiveWritable_f32(unsigned int index = 0); audio_block_f32_t * receiveWritable_f32(unsigned int index = 0);
friend class AudioConnection_F32; friend class AudioConnection_F32;
private: private:
AudioConnection_F32 *destination_list_f32; AudioConnection_F32 *destination_list_f32;
audio_block_f32_t **inputQueue_f32; audio_block_f32_t **inputQueue_f32;

Loading…
Cancel
Save