Skip to content

Commit ce3a933

Browse files
committed
Comment additions
1 parent 8fbac35 commit ce3a933

3 files changed

Lines changed: 70 additions & 39 deletions

File tree

AudioSettings_F32.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,19 @@
22
#ifndef _AudioSettings_F32_
33
#define _AudioSettings_F32_
44

5-
#include <AudioStream.h> // for AUDIO_SAMPLE_RATE_EXACT, AUDIO_BLOCK_SAMPLES
5+
#include <AudioStream.h> // 16-bit audio for AUDIO_SAMPLE_RATE_EXACT, AUDIO_BLOCK_SAMPLES
66

77
class AudioSettings_F32 {
88
public:
99
AudioSettings_F32(float fs_Hz=AUDIO_SAMPLE_RATE_EXACT, int block_size=AUDIO_BLOCK_SAMPLES) :
1010
sample_rate_Hz(fs_Hz), audio_block_samples(block_size) {}
1111
const float sample_rate_Hz;
1212
const int audio_block_samples;
13-
13+
1414
float cpu_load_percent(const int n);
1515
float processorUsage(void);
1616
float processorUsageMax(void);
1717
void processorUsageMaxReset(void);
1818
};
1919

20-
#endif
20+
#endif

AudioStream_F32.cpp

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -67,19 +67,19 @@ audio_block_f32_t * AudioStream_F32::allocate_f32(void)
6767
audio_block_f32_t *block;
6868
uint8_t used;
6969

70-
// f32_memory_pool_available_mask is array of six 32-bit uints with a 1 in position of
70+
// f32_memory_pool_available_mask is array of six 32-bit uints with a 1 in position of
7171
// each available block (max 192). 0 if unavailable (busy) or not allocated at all.
7272
p = f32_memory_pool_available_mask;
73-
74-
75-
/*
73+
74+
75+
/*
7676
if(millis() > 1200) {
7777
Serial.print("AudioStream_F32 ");
7878
Serial.println((uint32_t)*p, BIN); // Just first of 6
79-
}
80-
*/
81-
82-
79+
}
80+
*/
81+
82+
8383
__disable_irq();
8484
do {
8585
avail = *p; if (avail) break;
@@ -196,4 +196,3 @@ void AudioConnection_F32::connect(void) {
196196
dst.active = true;
197197
__enable_irq();
198198
}
199-

AudioStream_F32.h

Lines changed: 59 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,46 @@
11
/*
22
* AudioStream_F32
3-
*
3+
*
44
* Created: Chip Audette, November 2016
55
* Purpose; Extend the Teensy Audio Library's "AudioStream" to permit floating-point audio data.
6-
*
7-
* I modeled it directly on the Teensy code in "AudioStream.h" and "AudioStream.cpp", which are
6+
*
7+
* I modeled it directly on the Teensy code in "AudioStream.h" and "AudioStream.cpp", which are
88
* available here: https://github.com/PaulStoffregen/cores/tree/master/teensy3
9-
*
9+
*
1010
* Added id to audio_block_f32_t class, per Tympan. Bob Larkin June 2020
11-
*
12-
* MIT License. use at your own risk.
11+
*
12+
*
13+
* Thse classes are derived from their equivalents in Teensyduino. Thus:
14+
* Teensyduino Core Library
15+
* http://www.pjrc.com/teensy/
16+
* Copyright (c) 2017 PJRC.COM, LLC.
17+
*
18+
* Permission is hereby granted, free of charge, to any person obtaining
19+
* a copy of this software and associated documentation files (the
20+
* "Software"), to deal in the Software without restriction, including
21+
* without limitation the rights to use, copy, modify, merge, publish,
22+
* distribute, sublicense, and/or sell copies of the Software, and to
23+
* permit persons to whom the Software is furnished to do so, subject to
24+
* the following conditions:
25+
*
26+
* 1. The above copyright notice and this permission notice shall be
27+
* included in all copies or substantial portions of the Software.
28+
*
29+
* 2. If the Software is incorporated into a build system that allows
30+
* selection among a list of target devices, then similar target
31+
* devices manufactured by PJRC.COM must be included in the list of
32+
* target devices and selectable in the same manner.
33+
*
34+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
35+
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
36+
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
37+
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
38+
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
39+
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
40+
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
41+
* SOFTWARE.
42+
*
43+
* All additions are under MIT License. use at your own risk.
1344
*/
1445

1546
#ifndef _AudioStream_F32_h
@@ -32,22 +63,23 @@ class AudioConnection_F32;
3263
//https://github.com/PaulStoffregen/cores/blob/268848cdb0121f26b7ef6b82b4fb54abbe465427/teensy3/AudioStream.h
3364
// Added id, per Tympan. Should not disturb existing programs. Bob Larkin June 2020
3465
class audio_block_f32_t {
35-
public:
36-
audio_block_f32_t(void) {};
37-
audio_block_f32_t(const AudioSettings_F32 &settings) {
38-
fs_Hz = settings.sample_rate_Hz;
39-
length = settings.audio_block_samples;
40-
};
41-
42-
unsigned char ref_count;
43-
unsigned char memory_pool_index;
44-
unsigned char reserved1;
45-
unsigned char reserved2;
46-
float32_t data[AUDIO_BLOCK_SAMPLES]; // AUDIO_BLOCK_SAMPLES is 128, from AudioStream.h
47-
const int full_length = AUDIO_BLOCK_SAMPLES;
48-
int length = AUDIO_BLOCK_SAMPLES; // AUDIO_BLOCK_SAMPLES is 128, from AudioStream.h
49-
float fs_Hz = AUDIO_SAMPLE_RATE; // AUDIO_SAMPLE_RATE is 44117.64706 from AudioStream.h
50-
unsigned long id;
66+
public:
67+
audio_block_f32_t(void) {};
68+
audio_block_f32_t(const AudioSettings_F32 &settings) {
69+
fs_Hz = settings.sample_rate_Hz;
70+
length = settings.audio_block_samples;
71+
};
72+
73+
unsigned char ref_count;
74+
unsigned char memory_pool_index;
75+
unsigned char reserved1;
76+
unsigned char reserved2;
77+
float32_t data[AUDIO_BLOCK_SAMPLES]; // AUDIO_BLOCK_SAMPLES is 128, from AudioStream.h
78+
const int full_length = AUDIO_BLOCK_SAMPLES;
79+
int length = AUDIO_BLOCK_SAMPLES; // AUDIO_BLOCK_SAMPLES is 128, from AudioStream.h
80+
// For Teensy 4.x, AUDIO_SAMPLE_RATE is 44100
81+
float fs_Hz = AUDIO_SAMPLE_RATE; // T3.x AUDIO_SAMPLE_RATE is 44117.64706
82+
unsigned long id;
5183
};
5284

5385
class AudioConnection_F32
@@ -76,7 +108,7 @@ class AudioConnection_F32
76108

77109
class AudioStream_F32 : public AudioStream {
78110
public:
79-
AudioStream_F32(unsigned char n_input_f32, audio_block_f32_t **iqueue) : AudioStream(1, inputQueueArray_i16),
111+
AudioStream_F32(unsigned char n_input_f32, audio_block_f32_t **iqueue) : AudioStream(1, inputQueueArray_i16),
80112
num_inputs_f32(n_input_f32), inputQueue_f32(iqueue) {
81113
//active_f32 = false;
82114
destination_list_f32 = NULL;
@@ -86,20 +118,20 @@ class AudioStream_F32 : public AudioStream {
86118
};
87119
static void initialize_f32_memory(audio_block_f32_t *data, unsigned int num);
88120
static void initialize_f32_memory(audio_block_f32_t *data, unsigned int num, const AudioSettings_F32 &settings);
89-
//virtual void update(audio_block_f32_t *) = 0;
121+
//virtual void update(audio_block_f32_t *) = 0;
90122
static uint8_t f32_memory_used;
91123
static uint8_t f32_memory_used_max;
92124
static audio_block_f32_t * allocate_f32(void);
93125
static void release(audio_block_f32_t * block);
94-
126+
95127
protected:
96128
//bool active_f32;
97129
unsigned char num_inputs_f32;
98130
void transmit(audio_block_f32_t *block, unsigned char index = 0);
99131
audio_block_f32_t * receiveReadOnly_f32(unsigned int index = 0);
100-
audio_block_f32_t * receiveWritable_f32(unsigned int index = 0);
132+
audio_block_f32_t * receiveWritable_f32(unsigned int index = 0);
101133
friend class AudioConnection_F32;
102-
134+
103135
private:
104136
AudioConnection_F32 *destination_list_f32;
105137
audio_block_f32_t **inputQueue_f32;

0 commit comments

Comments
 (0)