3
3
4
4
using namespace audio_tools ;
5
5
6
+ // WIFI
6
7
const char *ssid = " ssid" ;
7
8
const char *password = " password" ;
8
9
WiFiServer server (80 );
9
10
WiFiClient client;
10
11
12
+ // Sound Generation
11
13
const int sample_rate = 10000 ;
12
14
const int data_length = 100000 ;
13
15
const int channels = 1 ;
@@ -18,14 +20,13 @@ StreamCopy copier; // buffered copy
18
20
WAVEncoder encoder;
19
21
AudioOutputStream wav_stream (encoder); // WAV output stream
20
22
21
- void setup ()
22
- {
23
+
24
+ void setup () {
23
25
Serial.begin (115200 );
24
26
AudioLogger::instance ().begin (Serial,AudioLogger::Debug);
25
27
26
28
WiFi.begin (ssid, password);
27
- while (WiFi.status () != WL_CONNECTED)
28
- {
29
+ while (WiFi.status () != WL_CONNECTED) {
29
30
delay (500 );
30
31
Serial.print (" ." );
31
32
}
@@ -35,13 +36,15 @@ void setup()
35
36
Serial.println (" IP address: " );
36
37
Serial.println (WiFi.localIP ());
37
38
39
+ // start server
38
40
server.begin ();
39
- sineWave.begin (sample_rate, B4);
40
41
42
+ // start generation of sound
43
+ sineWave.begin (sample_rate, B4);
41
44
in.begin ();
42
45
}
43
46
44
-
47
+ // Handle an new client connection and return the data
45
48
void processClient () {
46
49
if (client) { // if you get a client,
47
50
Serial.println (" New Client." ); // print a message out the serial port
@@ -86,6 +89,7 @@ void processClient() {
86
89
}
87
90
}
88
91
92
+ // copy the data
89
93
void loop () {
90
94
if (!client.connected ()) {
91
95
client = server.available (); // listen for incoming clients
@@ -94,6 +98,7 @@ void loop() {
94
98
// We are connected: copy input from source to wav output
95
99
if (encoder){
96
100
copier.copy ();
101
+ // if we limit the size of the WAV the encoder gets automatically closed when all has been sent
97
102
if (!encoder) {
98
103
Serial.println (" stop client..." );
99
104
client.stop ();
0 commit comments