-
-
Notifications
You must be signed in to change notification settings - Fork 248
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b450bcf
commit 263f6b2
Showing
19 changed files
with
351,733 additions
and
115 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
{ | ||
"files.associations": { | ||
"ostream": "cpp", | ||
"cullsettings": "cpp", | ||
"types": "cpp", | ||
"*.tcc": "cpp", | ||
"functional": "cpp", | ||
"string_view": "cpp", | ||
"quat": "cpp", | ||
"vec2d": "cpp", | ||
"vec2f": "cpp", | ||
"vec3d": "cpp", | ||
"vec3f": "cpp", | ||
"vec4d": "cpp", | ||
"vec4f": "cpp", | ||
"tuple": "cpp" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# Webserver | ||
|
||
With the help of the ESP32 WIFI functionality we can implement a simple web server. | ||
In the example we use a Sine Wave generator as sound source and return the result as an WAV file |
103 changes: 103 additions & 0 deletions
103
examples/streams-generator-webserver_wav/streams-generator-server_wav.ino
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
#include <WiFi.h> | ||
#include "AudioTools.h" | ||
|
||
using namespace audio_tools; | ||
|
||
const char *ssid = "ssid"; | ||
const char *password = "password"; | ||
WiFiServer server(80); | ||
WiFiClient client; | ||
|
||
const int sample_rate = 10000; | ||
const int data_length = 100000; | ||
const int channels = 1; | ||
|
||
SineWaveGenerator<int16_t> sineWave; // subclass of SoundGenerator with max amplitude of 32000 | ||
GeneratedSoundStream<int16_t> in(sineWave, channels); // Stream generated from sine wave | ||
StreamCopy copier; // buffered copy | ||
WAVEncoder encoder; | ||
AudioOutputStream wav_stream(encoder); // WAV output stream | ||
|
||
void setup() | ||
{ | ||
Serial.begin(115200); | ||
AudioLogger::instance().begin(Serial,AudioLogger::Debug); | ||
|
||
WiFi.begin(ssid, password); | ||
while (WiFi.status() != WL_CONNECTED) | ||
{ | ||
delay(500); | ||
Serial.print("."); | ||
} | ||
|
||
Serial.println(""); | ||
Serial.println("WiFi connected."); | ||
Serial.println("IP address: "); | ||
Serial.println(WiFi.localIP()); | ||
|
||
server.begin(); | ||
sineWave.begin(sample_rate, B4); | ||
|
||
in.begin(); | ||
} | ||
|
||
|
||
void processClient() { | ||
if (client) { // if you get a client, | ||
Serial.println("New Client."); // print a message out the serial port | ||
String currentLine = ""; // make a String to hold incoming data from the client | ||
while (client.connected()) { // loop while the client's connected | ||
if (client.available()) { // if there's bytes to read from the client, | ||
char c = client.read(); // read a byte, then | ||
Serial.write(c); // print it out the serial monitor | ||
if (c == '\n') { // if the byte is a newline character | ||
|
||
// if the current line is blank, you got two newline characters in a row. | ||
// that's the end of the client HTTP request, so send a response: | ||
if (currentLine.length() == 0){ | ||
// HTTP headers always start with a response code (e.g. HTTP/1.1 200 OK) | ||
// and a content-type so the client knows what's coming, then a blank line: | ||
client.println("HTTP/1.1 200 OK"); | ||
client.println("Content-type:audio/wav"); | ||
client.println(); | ||
|
||
// set up wav encoder | ||
auto config = encoder.defaultConfig(); | ||
config.channels = channels; | ||
config.sample_rate = sample_rate; | ||
//config.data_length = data_length; | ||
config.is_streamed = true; | ||
encoder.begin(client, config); | ||
|
||
Serial.println("Returning WAV stream..."); | ||
copier.begin(wav_stream, in); | ||
// break out of the while loop: | ||
break; | ||
} else { // if you got a newline, then clear currentLine: | ||
currentLine = ""; | ||
} | ||
} | ||
else if (c != '\r') | ||
{ // if you got anything else but a carriage return character, | ||
currentLine += c; // add it to the end of the currentLine | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
void loop() { | ||
if (!client.connected()) { | ||
client = server.available(); // listen for incoming clients | ||
processClient(); | ||
} else { | ||
// We are connected: copy input from source to wav output | ||
if (encoder){ | ||
copier.copy(); | ||
if (!encoder) { | ||
Serial.println("stop client..."); | ||
client.stop(); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
#Decoding a WAV file | ||
|
||
In this example we decode a WAV file into RAW output and send it to the Serial output. The audio chain is: | ||
|
||
MemoryStream -> AudioOutputStream -> WAVDecoder -> CsvStream |
Oops, something went wrong.