Skip to content

Commit 2248fad

Browse files
committed
Thanks Greg, added example
1 parent 79c456d commit 2248fad

1 file changed

Lines changed: 65 additions & 0 deletions

File tree

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
// Demonstration of AudioOutputI2S_F32 two channel I2S output object.
2+
// Greg Raven KF5N November 2025.
3+
// The left and right channels are output on pin 7, which drives the
4+
// Teensy Audio Adapter.
5+
// A headphone can be plugged into the Audio Adapter to hear the tones.
6+
// Be cautious plugging non-floating devices into the Audio Adapter
7+
// headphone output. Grounded devices may cause damage to the Audio Adapter.
8+
9+
#include <Arduino.h>
10+
#include <Audio.h>
11+
#include <OpenAudio_ArduinoLibrary.h>
12+
#include <AudioStream_F32.h>
13+
14+
const float sample_rate_Hz = 48000.0;
15+
const int audio_block_samples = 128;
16+
17+
AudioControlSGTL5000 sgtl5000_1;
18+
AudioSettings_F32 audio_settings(sample_rate_Hz, audio_block_samples);
19+
AudioSynthWaveformSine_F32 tone0(audio_settings), tone1(audio_settings);
20+
AudioOutputI2S_F32 i2s_out(audio_settings);
21+
22+
AudioConnection_F32 connect0(tone0, 0, i2s_out, 0);
23+
AudioConnection_F32 connect1(tone1, 0, i2s_out, 1);
24+
25+
void setup() {
26+
27+
Serial.begin(115200);
28+
29+
/* check for CrashReport stored from previous run */
30+
if (CrashReport) {
31+
Serial.print(CrashReport);
32+
}
33+
34+
uint32_t* dmaErrors;
35+
dmaErrors = (uint32_t*)(0x400E8000 + 0x4);
36+
Serial.printf("DMA errors = %u\n", *dmaErrors);
37+
38+
sgtl5000_1.enable();
39+
sgtl5000_1.setAddress(LOW);
40+
AudioMemory_F32(10);
41+
sgtl5000_1.volume(0.8); // Set headphone volume.
42+
sgtl5000_1.unmuteHeadphone();
43+
Serial.printf("Please listen for tones!\n");
44+
tone0.amplitude(0.1);
45+
tone0.frequency(261.63);
46+
tone0.end();
47+
tone1.amplitude(0.1);
48+
tone1.frequency(329.63);
49+
tone1.end();
50+
51+
tone0.begin();
52+
Serial.println("tone0 is on");
53+
delay(5000);
54+
tone0.end();
55+
Serial.println("tone0 is off");
56+
delay(5000);
57+
tone1.begin();
58+
Serial.println("tone1 is on");
59+
delay(5000);
60+
tone1.end();
61+
Serial.println("Both tones off");
62+
}
63+
64+
void loop() {
65+
}

0 commit comments

Comments
 (0)