File tree Expand file tree Collapse file tree 9 files changed +176
-1
lines changed
examples/examples-communication Expand file tree Collapse file tree 9 files changed +176
-1
lines changed Original file line number Diff line number Diff line change 7
7
*
8
8
* @copyright Copyright (c) 2022
9
9
*
10
+ * ATTENTION: DRAFT - not tested yet
10
11
*/
11
12
13
+ #include " AudioTools.h"
14
+ #include " BluetoothSerial.h"
15
+
12
16
uint16_t sample_rate = 44100 ;
13
17
uint8_t channels = 2 ; // The stream will have 2 channels
14
18
BluetoothSerial SerialBT;
Original file line number Diff line number Diff line change 7
7
*
8
8
* @copyright Copyright (c) 2022
9
9
*
10
+ * ATTENTION: DRAFT - not tested yet
10
11
*/
11
12
13
+ #include " AudioTools.h"
12
14
#include " BluetoothSerial.h"
13
15
14
16
uint16_t sample_rate = 44100 ;
Original file line number Diff line number Diff line change
1
+ /* *
2
+ * @file example-serial-receive.ino
3
+ * @author Phil Schatzmann
4
+ * @brief Receiving audio via ESPNow
5
+ * @version 0.1
6
+ * @date 2022-03-09
7
+ *
8
+ * @copyright Copyright (c) 2022
9
+ *
10
+ * ATTENTION: DRAFT - not tested yet
11
+ */
12
+
13
+ #include " AudioTools.h"
14
+ #include " AudioLibs/Communication.h"
15
+
16
+ uint16_t sample_rate = 44100 ;
17
+ uint8_t channels = 2 ; // The stream will have 2 channels
18
+ ESPNowStream now;
19
+ I2SStream out;
20
+ StreamCopy copier (out, now);
21
+ const char *ssd = " ssid" ;
22
+ const char *password = " password" ;
23
+ const char *peers[] = {" A8:48:FA:0B:93:40" }
24
+
25
+ void setup () {
26
+ Serial.begin (115200 );
27
+ AudioLogger::instance ().begin (Serial, AudioLogger::Info);
28
+
29
+ now.addPeers (peers);
30
+ now.begin (ssid, pasword);
31
+
32
+ // start I2S
33
+ Serial.println (" starting I2S..." );
34
+ auto config = out.defaultConfig (TX_MODE);
35
+ config.sample_rate = sample_rate;
36
+ config.channels = channels;
37
+ config.bits_per_sample = 16 ;
38
+ out.begin (config);
39
+
40
+ Serial.println (" started..." );
41
+ }
42
+
43
+ void loop () {
44
+ copier.copy ();
45
+ }
Original file line number Diff line number Diff line change 7
7
*
8
8
* @copyright Copyright (c) 2022
9
9
*
10
+ * ATTENTION: DRAFT - not tested yet
10
11
*/
11
12
13
+ #include " AudioTools.h"
14
+ #include " AudioLibs/Communication.h"
15
+
12
16
uint16_t sample_rate = 44100 ;
13
17
uint8_t channels = 2 ; // The stream will have 2 channels
14
18
SineWaveGenerator<sound_t > sineWave ( 32000 ); // subclass of SoundGenerator with max amplitude of 32000
@@ -17,12 +21,13 @@ ESPNowStream now;
17
21
StreamCopy copier (now, sound); // copies sound into i2s
18
22
const char *ssd = " ssid" ;
19
23
const char *password = " password" ;
24
+ const char *peers[] = {" A8:48:FA:0B:93:40" }
20
25
21
26
void setup () {
22
27
Serial.begin (115200 );
23
28
AudioLogger::instance ().begin (Serial, AudioLogger::Info);
24
29
25
- now.add
30
+ now.addPeers (peers);
26
31
now.begin (ssid, pasword);
27
32
28
33
// Setup sine wave
Original file line number Diff line number Diff line change
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
+ * ATTENTION: DRAFT - not tested yet
11
+ */
12
+
13
+ #include " AudioTools.h"
14
+ #include < WiFi.h>
15
+
16
+ uint16_t sample_rate = 44100 ;
17
+ uint8_t channels = 2 ; // The stream will have 2 channels
18
+ WiFiServer server (80 );
19
+ WiFiClient client;
20
+ I2SStream out;
21
+ StreamCopy copier (out, client);
22
+ const char * ssid = " yourssid" ;
23
+ const char * password = " yourpasswd" ;
24
+
25
+ void setup () {
26
+ Serial.begin (115200 );
27
+ AudioLogger::instance ().begin (Serial, AudioLogger::Info);
28
+
29
+ // start server
30
+ server.begin ();
31
+
32
+ // start I2S
33
+ Serial.println (" starting I2S..." );
34
+ auto config = out.defaultConfig (TX_MODE);
35
+ config.sample_rate = sample_rate;
36
+ config.channels = channels;
37
+ config.bits_per_sample = 16 ;
38
+ out.begin (config);
39
+
40
+ Serial.println (" started..." );
41
+ }
42
+
43
+ void loop () {
44
+ // get a new connection
45
+ if (!client){
46
+ client = server.available ();
47
+ }
48
+ // copy data if we are connected
49
+ if (client.connected ()){
50
+ copier.copy ();
51
+ }
52
+ }
Original file line number Diff line number Diff line change
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
+ * ATTENTION: DRAFT - not tested yet
11
+ */
12
+
13
+ #include " AudioTools.h"
14
+ #include < WiFi.h>
15
+
16
+ uint16_t sample_rate = 44100 ;
17
+ uint8_t channels = 2 ; // The stream will have 2 channels
18
+ SineWaveGenerator<sound_t > sineWave ( 32000 ); // subclass of SoundGenerator with max amplitude of 32000
19
+ GeneratedSoundStream<sound_t > sound ( sineWave); // Stream generated from sine wave
20
+ WiFiClient client;
21
+ StreamCopy copier (client, sound); // copies sound into i2s
22
+ const char *ssid = " ssid" ;
23
+
24
+ void setup () {
25
+ Serial.begin (115200 );
26
+ AudioLogger::instance ().begin (Serial, AudioLogger::Info);
27
+
28
+ // connect to WIFI
29
+ WiFi.begin (ssid, password);
30
+ while (WiFi.status () != WL_CONNECTED) {
31
+ delay (500 );
32
+ Serial.print (" ." );
33
+ }
34
+ Serial.println ();
35
+
36
+ // Try to connect to ip / port
37
+ while (!client.connect (" 134.209.234.6" , 80 )) {
38
+ Serial.println (" trying to connect..." );
39
+ delay (5000 );
40
+ }
41
+
42
+ // Setup sine wave
43
+ sineWave.begin (channels, sample_rate, N_B4);
44
+ Serial.println (" started..." );
45
+ }
46
+
47
+ void loop () {
48
+ copier.copy ();
49
+ }
Original file line number Diff line number Diff line change 7
7
*
8
8
* @copyright Copyright (c) 2022
9
9
*
10
+ * ATTENTION: DRAFT - not tested yet
10
11
*/
11
12
13
+ #include " AudioTools.h"
14
+
12
15
#define RXD2 16
13
16
#define TXD2 17
14
17
Original file line number Diff line number Diff line change 7
7
*
8
8
* @copyright Copyright (c) 2022
9
9
*
10
+ * ATTENTION: DRAFT - not tested yet
10
11
*/
11
12
13
+ #include " AudioTools.h"
14
+
12
15
#define RXD2 16
13
16
#define TXD2 17
14
17
Original file line number Diff line number Diff line change @@ -31,6 +31,18 @@ class ESPNowStream : public AudioStreamX {
31
31
return result == ESP_OK;
32
32
}
33
33
34
+ // / Adds an array of
35
+ template <size_t size>
36
+ bool addPeers (const char *(&array)[size]) {
37
+ bool result = true ;
38
+ for (int j=0 ;j<size;j++){
39
+ if (!addPeer (array[j])){
40
+ result = false ;
41
+ }
42
+ }
43
+ return result;
44
+ }
45
+
34
46
// / Adds a peer to which we can send info or from which we can receive info
35
47
bool addPeer (const char *address) {
36
48
esp_now_peer_info_t peer;
You can’t perform that action at this time.
0 commit comments