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
3465class 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
5385class AudioConnection_F32
@@ -76,7 +108,7 @@ class AudioConnection_F32
76108
77109class 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