Skip to content

Commit 17ac52b

Browse files
committed
Fixed i2s problems. Thanks Greg.
1 parent 2248fad commit 17ac52b

File tree

2 files changed

+19
-31
lines changed

2 files changed

+19
-31
lines changed

output_i2s_quad_f32.cpp

Lines changed: 12 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -36,29 +36,20 @@
3636
// This version is 4 channel I2S output. Greg Raven KF5N October, 2025
3737

3838
#include "output_i2s_quad_f32.h"
39-
#include "output_i2s_f32.h" // Required for 2 channel to be a "friend" so its I2S configuration method can be used.
40-
#include <arm_math.h>
41-
#include <utility/imxrt_hw.h> // From Teensy Audio library. For set_audioClock().
4239

4340
DMAChannel AudioOutputI2SQuad_F32::dma(false);
4441
DMAMEM __attribute__((aligned(32))) static float32_t i2s_tx_buffer[AUDIO_BLOCK_SAMPLES * 4]; // 4 channels 128 samples each, total = 512.
4542

46-
void AudioOutputI2SQuad_F32::begin(void)
47-
{
48-
bool transferUsing32bit = false;
49-
begin(transferUsing32bit);
50-
}
51-
52-
void AudioOutputI2SQuad_F32::begin(bool transferUsing32bit)
43+
void AudioOutputI2SQuad_F32::begin()
5344
{
5445
// Configure most of the I2S.
55-
AudioOutputI2S_F32::config_i2s(transferUsing32bit);
56-
// Configure the rest of the I2S unique to quad output.
57-
I2S1_RCSR |= I2S_RCSR_RE | I2S_RCSR_BCE;
58-
I2S1_TCSR = I2S_TCSR_TE | I2S_TCSR_BCE | I2S_TCSR_FRDE;
59-
I2S1_TCR3 = I2S_TCR3_TCE_2CH;
46+
AudioOutputI2SQuad_F32::config_i2s(sample_rate_Hz);
47+
48+
// Configure the I2S output pins.
6049
CORE_PIN7_CONFIG = 3; // Teensy pin 7 is 1st and 2nd channels of I2S (Audio Adapter on Teensy 4.1).
6150
CORE_PIN32_CONFIG = 3; // Teensy pin 32 is 3rd and 4th channels of I2S.
51+
52+
// Zero the transmit buffer.
6253
memset(i2s_tx_buffer, 0, sizeof(i2s_tx_buffer));
6354

6455
// Configure the DMA channel.
@@ -81,6 +72,11 @@ void AudioOutputI2SQuad_F32::begin(bool transferUsing32bit)
8172
update_responsibility = update_setup();
8273
dma.enable();
8374
enabled = 1; // What is this?
75+
76+
// Configure the rest of the I2S unique to quad output.
77+
I2S1_RCSR |= I2S_RCSR_RE | I2S_RCSR_BCE;
78+
I2S1_TCSR = I2S_TCSR_TE | I2S_TCSR_BCE | I2S_TCSR_FRDE;
79+
I2S1_TCR3 = I2S_TCR3_TCE_2CH;
8480
}
8581

8682
// Interrupt service routine called twice per update by the DMA.
@@ -280,12 +276,7 @@ void AudioOutputI2SQuad_F32::update(void)
280276
}
281277

282278
// Configure the I2S peripheral. This is most, but not all, of the configuration. The rest is done by begin().
283-
// Note that the version of this method can be called from the dual channel object via "friend".
284-
void AudioOutputI2SQuad_F32::config_i2s(void) { config_i2s(false, AudioOutputI2SQuad_F32::sample_rate_Hz); }
285-
void AudioOutputI2SQuad_F32::config_i2s(bool transferUsing32bit) { config_i2s(transferUsing32bit, AudioOutputI2SQuad_F32::sample_rate_Hz); }
286-
void AudioOutputI2SQuad_F32::config_i2s(float fs_Hz) { config_i2s(false, fs_Hz); }
287-
288-
void AudioOutputI2SQuad_F32::config_i2s(bool transferUsing32bit, float fs_Hz)
279+
void AudioOutputI2SQuad_F32::config_i2s(int fs_Hz)
289280
{
290281
CCM_CCGR5 |= CCM_CCGR5_SAI1(CCM_CCGR_ON);
291282

output_i2s_quad_f32.h

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,9 @@
3939
#define output_i2s_quad_f32_h_
4040

4141
#include <Arduino.h>
42-
#include <arm_math.h>
4342
#include "AudioStream_F32.h"
4443
#include "DMAChannel.h"
44+
#include <utility/imxrt_hw.h> // From Teensy Audio library. For set_audioClock().
4545

4646
class AudioOutputI2SQuad_F32 : public AudioStream_F32
4747
{
@@ -65,29 +65,25 @@ class AudioOutputI2SQuad_F32 : public AudioStream_F32
6565
{
6666
outputScale = _oscale;
6767
}
68-
virtual void update(void);
69-
void begin(void);
70-
void begin(bool);
71-
void scale_f32_to_i32(float32_t *p_f32, int len);
7268

7369
protected:
7470
AudioOutputI2SQuad_F32(int dummy) : AudioStream_F32(4, inputQueueArray) {} // to be used only inside AudioOutputI2Sslave !!
7571

72+
void begin();
7673
inline static audio_block_f32_t *block_left_1st = nullptr;
7774
inline static audio_block_f32_t *block_right_1st = nullptr;
7875
inline static audio_block_f32_t *block_left_2nd = nullptr;
7976
inline static audio_block_f32_t *block_right_2nd = nullptr;
8077
inline static bool update_responsibility = false;
8178
static DMAChannel dma;
8279
static void isr(void);
80+
virtual void update(void);
8381

8482
private:
85-
static void config_i2s(void);
86-
static void config_i2s(bool);
87-
static void config_i2s(float);
88-
static void config_i2s(bool, float);
83+
static void config_i2s(int fs_Hz);
84+
void scale_f32_to_i32(float32_t *p_f32, int len);
8985
audio_block_f32_t *inputQueueArray[4];
90-
inline static float sample_rate_Hz = AUDIO_SAMPLE_RATE;
86+
inline static int sample_rate_Hz = AUDIO_SAMPLE_RATE;
9187
inline static int audio_block_samples = AUDIO_BLOCK_SAMPLES;
9288
inline static int half_block_length = AUDIO_BLOCK_SAMPLES / 2;
9389
inline static int half_buffer_length = AUDIO_BLOCK_SAMPLES * 2;
@@ -96,6 +92,7 @@ class AudioOutputI2SQuad_F32 : public AudioStream_F32
9692
float outputScale = 1.0f; // Quick volume control
9793
};
9894

95+
// Quad slave not implemented. Greg Raven KF5N November 2025
9996
class AudioOutputI2SQuadslave_F32 : public AudioOutputI2SQuad_F32
10097
{
10198
public:

0 commit comments

Comments
 (0)