Skip to content

Commit 4f14430

Browse files
committed
AudioKit 2957
1 parent 5520715 commit 4f14430

File tree

7 files changed

+387
-10
lines changed

7 files changed

+387
-10
lines changed
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/**
2+
* @file example-serial-receive.ino
3+
* @author Phil Schatzmann
4+
* @brief Receiving audio via serial bluetooth
5+
* @version 0.1
6+
* @date 2022-03-09
7+
*
8+
* @copyright Copyright (c) 2022
9+
*
10+
*/
11+
12+
uint16_t sample_rate = 44100;
13+
uint8_t channels = 2; // The stream will have 2 channels
14+
BluetoothSerial SerialBT;
15+
StreamCopy copier(out, SerialBT);
16+
17+
void setup() {
18+
Serial.begin(115200);
19+
AudioLogger::instance().begin(Serial, AudioLogger::Info);
20+
21+
SerialBT.begin("ESP32Receiver"); //Bluetooth device name
22+
while(!SerialBT.connected()){
23+
//SerialBT.connect("ESP32Receiver");
24+
Serial.print(".");
25+
delay(1000);
26+
}
27+
Serial.println();
28+
29+
// start I2S
30+
Serial.println("starting I2S...");
31+
auto config = out.defaultConfig(TX_MODE);
32+
config.sample_rate = sample_rate;
33+
config.channels = channels;
34+
config.bits_per_sample = 16;
35+
out.begin(config);
36+
37+
Serial.println("started...");
38+
}
39+
40+
void loop() {
41+
copier.copy();
42+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/**
2+
* @file example-serial-send.ino
3+
* @author Phil Schatzmann
4+
* @brief Sending audio over serial bluetooth
5+
* @version 0.1
6+
* @date 2022-03-09
7+
*
8+
* @copyright Copyright (c) 2022
9+
*
10+
*/
11+
12+
#include "BluetoothSerial.h"
13+
14+
uint16_t sample_rate = 44100;
15+
uint8_t channels = 2; // The stream will have 2 channels
16+
SineWaveGenerator<sound_t> sineWave( 32000); // subclass of SoundGenerator with max amplitude of 32000
17+
GeneratedSoundStream<sound_t> sound( sineWave); // Stream generated from sine wave
18+
BluetoothSerial SerialBT;
19+
StreamCopy copier(SerialBT, sound); // copies sound into i2s
20+
21+
void setup() {
22+
Serial.begin(115200);
23+
AudioLogger::instance().begin(Serial, AudioLogger::Info);
24+
25+
SerialBT.begin("ESP32Sender"); //Bluetooth device name
26+
while(!SerialBT.connected()){
27+
SerialBT.connect("ESP32Receiver");
28+
Serial.print(".");
29+
delay(1000);
30+
}
31+
Serial.println();
32+
33+
// Setup sine wave
34+
sineWave.begin(channels, sample_rate, N_B4);
35+
Serial.println("started...");
36+
}
37+
38+
void loop() {
39+
copier.copy();
40+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/**
2+
* @file example-serial-send.ino
3+
* @author Phil Schatzmann
4+
* @brief Sending audio over ESPNow
5+
* @version 0.1
6+
* @date 2022-03-09
7+
*
8+
* @copyright Copyright (c) 2022
9+
*
10+
*/
11+
12+
uint16_t sample_rate = 44100;
13+
uint8_t channels = 2; // The stream will have 2 channels
14+
SineWaveGenerator<sound_t> sineWave( 32000); // subclass of SoundGenerator with max amplitude of 32000
15+
GeneratedSoundStream<sound_t> sound( sineWave); // Stream generated from sine wave
16+
ESPNowStream now;
17+
StreamCopy copier(now, sound); // copies sound into i2s
18+
const char *ssd = "ssid";
19+
const char *password = "password";
20+
21+
void setup() {
22+
Serial.begin(115200);
23+
AudioLogger::instance().begin(Serial, AudioLogger::Info);
24+
25+
now.add
26+
now.begin(ssid, pasword);
27+
28+
// Setup sine wave
29+
sineWave.begin(channels, sample_rate, N_B4);
30+
Serial.println("started...");
31+
}
32+
33+
void loop() {
34+
copier.copy();
35+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/**
2+
* @file example-serial-receive.ino
3+
* @author Phil Schatzmann
4+
* @brief Receiving audio via serial
5+
* @version 0.1
6+
* @date 2022-03-09
7+
*
8+
* @copyright Copyright (c) 2022
9+
*
10+
*/
11+
12+
#define RXD2 16
13+
#define TXD2 17
14+
15+
uint16_t sample_rate = 44100;
16+
uint8_t channels = 2; // The stream will have 2 channels
17+
I2SStream out;
18+
StreamCopy copier(out, Serial2);
19+
20+
void setup() {
21+
Serial.begin(115200);
22+
AudioLogger::instance().begin(Serial, AudioLogger::Info);
23+
24+
// Note the format for setting a serial port is as follows:
25+
// Serial2.begin(baud-rate, protocol, RX pin, TX pin);
26+
Serial2.begin(115200, SERIAL_8N1, RXD2, TXD2);
27+
28+
// start I2S
29+
Serial.println("starting I2S...");
30+
auto config = out.defaultConfig(TX_MODE);
31+
config.sample_rate = sample_rate;
32+
config.channels = channels;
33+
config.bits_per_sample = 16;
34+
out.begin(config);
35+
36+
Serial.println("started...");
37+
}
38+
39+
void loop() {
40+
copier.copy();
41+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/**
2+
* @file example-serial-send.ino
3+
* @author Phil Schatzmann
4+
* @brief Sending audio over serial
5+
* @version 0.1
6+
* @date 2022-03-09
7+
*
8+
* @copyright Copyright (c) 2022
9+
*
10+
*/
11+
12+
#define RXD2 16
13+
#define TXD2 17
14+
15+
uint16_t sample_rate = 44100;
16+
uint8_t channels = 2; // The stream will have 2 channels
17+
SineWaveGenerator<sound_t> sineWave( 32000); // subclass of SoundGenerator with max amplitude of 32000
18+
GeneratedSoundStream<sound_t> sound( sineWave); // Stream generated from sine wave
19+
StreamCopy copier(Serial2, sound); // copies sound into i2s
20+
21+
void setup() {
22+
Serial.begin(115200);
23+
AudioLogger::instance().begin(Serial, AudioLogger::Info);
24+
25+
// Note the format for setting a serial port is as follows:
26+
// Serial2.begin(baud-rate, protocol, RX pin, TX pin);
27+
Serial2.begin(115200, SERIAL_8N1, RXD2, TXD2);
28+
29+
// Setup sine wave
30+
sineWave.begin(channels, sample_rate, N_B4);
31+
Serial.println("started...");
32+
}
33+
34+
void loop() {
35+
copier.copy();
36+
}

src/AudioLibs/AudioKit.h

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -543,14 +543,6 @@ class AudioKitStream : public AudioStreamX {
543543
SPI.end();
544544
}
545545

546-
// pin conflicts with AIThinker A101 and headphone detection
547-
if (! (cfg.sd_active && AUDIOKIT_BOARD==6)) {
548-
LOGD("actionHeadphoneDetection pin:%d",kit.pinHeadphoneDetect())
549-
actions.add(kit.pinHeadphoneDetect(), actionHeadphoneDetection, AudioActions::ActiveChange);
550-
} else {
551-
LOGW("Headphone detection ignored because of conflict: %d ",kit.pinHeadphoneDetect());
552-
}
553-
554546
// pin conflicts with the SD CS pin for AIThinker and buttons
555547
if (! (cfg.sd_active && (AUDIOKIT_BOARD==5 || AUDIOKIT_BOARD==6))){
556548
LOGD("actionStartStop")
@@ -559,8 +551,16 @@ class AudioKitStream : public AudioStreamX {
559551
LOGW("Mode Button ignored because of conflict: %d ",kit.pinInputMode());
560552
}
561553

562-
// pin conflicts with SD Lyrat SD CS Pin and buttons
563-
if (! (cfg.sd_active && AUDIOKIT_BOARD==1)){
554+
// pin conflicts with AIThinker A101 and headphone detection
555+
if (! (cfg.sd_active && AUDIOKIT_BOARD==6)) {
556+
LOGD("actionHeadphoneDetection pin:%d",kit.pinHeadphoneDetect())
557+
actions.add(kit.pinHeadphoneDetect(), actionHeadphoneDetection, AudioActions::ActiveChange);
558+
} else {
559+
LOGW("Headphone detection ignored because of conflict: %d ",kit.pinHeadphoneDetect());
560+
}
561+
562+
// pin conflicts with SD Lyrat SD CS Pin and buttons / Conflict on Audiokit V. 2957
563+
if (! (cfg.sd_active && AUDIOKIT_BOARD==1 || AUDIOKIT_BOARD==7)){
564564
LOGD("actionVolumeDown")
565565
addAction(kit.pinVolumeDown(), actionVolumeDown);
566566
LOGD("actionVolumeUp")

0 commit comments

Comments
 (0)