snapshot
This commit is contained in:
@@ -0,0 +1,50 @@
|
||||
/**
|
||||
* @brief A simple WebSocket client sketch that sends out some PCM audio
|
||||
* data using the https://github.com/Links2004/arduinoWebSockets library.AdapterAudioStreamToAudioOutput.AdapterAudioStreamToAudioOutput
|
||||
* The WebSocket API is asynchronous, so we need to slow down the sending
|
||||
* to the playback speed, to prevent any buffer overflows at the receiver.
|
||||
* @author Phil Schatzmann
|
||||
*/
|
||||
|
||||
#include <WebSocketsClient.h> // https://github.com/Links2004/arduinoWebSockets
|
||||
#include <WiFiMulti.h>
|
||||
#include "AudioTools.h"
|
||||
#include "AudioTools/Communication/WebSocketOutput.h"
|
||||
|
||||
// websocket
|
||||
WiFiMulti WiFiMulti;
|
||||
WebSocketsClient webSocket;
|
||||
WebSocketOutput out(webSocket);
|
||||
// audio
|
||||
AudioInfo info(44100, 2, 16);
|
||||
SineWaveGenerator<int16_t> sineWave(32000);
|
||||
GeneratedSoundStream<int16_t> sound(sineWave);
|
||||
Throttle throttle(out)
|
||||
StreamCopy copier(throttle, sound);
|
||||
|
||||
void setup() {
|
||||
Serial.begin(115200);
|
||||
|
||||
// connect to wifi
|
||||
WiFiMulti.addAP("SSID", "passpasspass");
|
||||
while (WiFiMulti.run() != WL_CONNECTED) {
|
||||
delay(100);
|
||||
}
|
||||
WiFi.setSleep(false);
|
||||
|
||||
// start client connecting to server address, port and URL
|
||||
webSocket.begin("192.168.1.34", 81, "/");
|
||||
|
||||
// try ever 5000 again if connection has failed
|
||||
webSocket.setReconnectInterval(5000);
|
||||
|
||||
sineWave.begin(info, N_B4);
|
||||
// WebSockets are async, so we need to slow down the sending
|
||||
throttle.begin(info);
|
||||
}
|
||||
|
||||
void loop() {
|
||||
webSocket.loop();
|
||||
// generate audio only when we are connected
|
||||
if (webSocket.isConnected()) copier.copy();
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
/**
|
||||
* @brief A simple WebSocket server sketch that receives PCM audio data using the
|
||||
* https://github.com/Links2004/arduinoWebSockets library and outputs it via i2s
|
||||
* to an AudioKit for easy testing. Replace the output with whatever other class
|
||||
* you like.
|
||||
* @author Phil Schatzmann
|
||||
*/
|
||||
#include <WebSocketsServer.h> //https://github.com/Links2004/arduinoWebSockets
|
||||
#include <WiFi.h>
|
||||
#include <WiFiClientSecure.h>
|
||||
#include <WiFiMulti.h>
|
||||
#include "AudioTools.h"
|
||||
#include "AudioTools/AudioLibs/AudioBoardStream.h"
|
||||
|
||||
WiFiMulti WiFiMulti;
|
||||
WebSocketsServer webSocket(81);
|
||||
AudioInfo info(44100, 2, 16);
|
||||
AudioBoardStream i2s(AudioKitEs8388V1); // Access I2S as stream
|
||||
|
||||
/// Just output the audio data
|
||||
void webSocketEvent(uint8_t num, WStype_t type, uint8_t* payload,
|
||||
size_t length) {
|
||||
if (type == WStype_BIN) {
|
||||
i2s.write(payload, length);
|
||||
}
|
||||
}
|
||||
|
||||
void setup() {
|
||||
Serial.begin(115200);
|
||||
AudioToolsLogger.begin(Serial, AudioToolsLogLevel::Info);
|
||||
|
||||
WiFiMulti.addAP("SSID", "passpasspass");
|
||||
while (WiFiMulti.run() != WL_CONNECTED) {
|
||||
delay(100);
|
||||
}
|
||||
WiFi.setSleep(false);
|
||||
Serial.println(WiFi.localIP());
|
||||
|
||||
// start server
|
||||
webSocket.begin();
|
||||
webSocket.onEvent(webSocketEvent);
|
||||
|
||||
// start i2s
|
||||
auto cfg = i2s.defaultConfig(TX_MODE);
|
||||
cfg.copyFrom(info);
|
||||
i2s.begin(cfg);
|
||||
}
|
||||
|
||||
void loop() { webSocket.loop(); }
|
||||
@@ -0,0 +1,55 @@
|
||||
/**
|
||||
* @brief A simple WebSocket client sketch that receives PCM audio data using the
|
||||
* https://github.com/Links2004/arduinoWebSockets library and outputs it via i2s
|
||||
* to an AudioKit for easy testing. Replace the output with whatever other class
|
||||
* you like.
|
||||
* @author Phil Schatzmann
|
||||
*/
|
||||
#include <WebSocketsClient.h> // https://github.com/Links2004/arduinoWebSockets
|
||||
#include <WiFiMulti.h>
|
||||
#include "AudioTools.h"
|
||||
#include "AudioTools/AudioLibs/AudioBoardStream.h"
|
||||
|
||||
// websocket
|
||||
WiFiMulti WiFiMulti;
|
||||
WebSocketsClient webSocket;
|
||||
// audio
|
||||
AudioInfo info(44100, 2, 16);
|
||||
AudioBoardStream i2s(AudioKitEs8388V1); // Access I2S as stream
|
||||
|
||||
// write audio to i2s
|
||||
void webSocketEvent(WStype_t type, uint8_t* payload, size_t length) {
|
||||
if (type == WStype_BIN) {
|
||||
i2s.write(payload, length);
|
||||
}
|
||||
}
|
||||
|
||||
void setup() {
|
||||
Serial.begin(115200);
|
||||
AudioToolsLogger.begin(Serial, AudioToolsLogLevel::Info);
|
||||
|
||||
// connect to wifk
|
||||
WiFiMulti.addAP("SSID", "passpasspass");
|
||||
while (WiFiMulti.run() != WL_CONNECTED) {
|
||||
delay(100);
|
||||
}
|
||||
WiFi.setSleep(false);
|
||||
|
||||
// start client connecting to server address, port and URL
|
||||
webSocket.begin("192.168.1.34", 81, "/");
|
||||
|
||||
// event handler
|
||||
webSocket.onEvent(webSocketEvent);
|
||||
|
||||
// try ever 5000 again if connection has failed
|
||||
webSocket.setReconnectInterval(5000);
|
||||
|
||||
// start i2s
|
||||
auto cfg = i2s.defaultConfig(TX_MODE);
|
||||
cfg.copyFrom(info);
|
||||
i2s.begin(cfg);
|
||||
}
|
||||
|
||||
void loop() {
|
||||
webSocket.loop();
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
/**
|
||||
* @brief A simple WebSocket server sketch using the
|
||||
* https://github.com/Links2004/arduinoWebSockets library to send out some
|
||||
* PCM audio data when some clients are connnected.
|
||||
* The WebSocket API is asynchronous, so we need to slow down the sending
|
||||
* to the playback speed, to prevent any buffer overflows at the receiver.
|
||||
* @author Phil Schatzmann
|
||||
*/
|
||||
|
||||
#include <WebSocketsServer.h> // https://github.com/Links2004/arduinoWebSockets
|
||||
#include <WiFi.h>
|
||||
#include <WiFiMulti.h>
|
||||
#include "AudioTools.h"
|
||||
#include "AudioTools/Communication/WebSocketOutput.h"
|
||||
|
||||
WiFiMulti WiFiMulti;
|
||||
WebSocketsServer webSocket(81);
|
||||
WebSocketOutput out(webSocket);
|
||||
|
||||
// audio
|
||||
AudioInfo info(44100, 2, 16);
|
||||
SineWaveGenerator<int16_t> sineWave(32000);
|
||||
GeneratedSoundStream<int16_t> sound(sineWave);
|
||||
Throttle throttle(out);
|
||||
StreamCopy copier(throttle, sound); // copies sound into i2s
|
||||
|
||||
void setup() {
|
||||
// Serial.begin(921600);
|
||||
Serial.begin(115200);
|
||||
AudioToolsLogger.begin(Serial, AudioToolsLogLevel::Info);
|
||||
|
||||
// connect to wifi
|
||||
WiFiMulti.addAP("SSID", "passpasspass");
|
||||
while (WiFiMulti.run() != WL_CONNECTED) {
|
||||
delay(100);
|
||||
}
|
||||
WiFi.setSleep(false);
|
||||
Serial.println(WiFi.localIP());
|
||||
|
||||
// start server
|
||||
webSocket.begin();
|
||||
|
||||
// start sine generation
|
||||
sineWave.begin(info, N_B4);
|
||||
throttle.begin(info);
|
||||
|
||||
}
|
||||
|
||||
void loop() {
|
||||
webSocket.loop();
|
||||
// generate audio only when we have any clients
|
||||
if (webSocket.connectedClients() > 0) copier.copy();
|
||||
}
|
||||
Reference in New Issue
Block a user