-
-
Save kenkit/fcd26e8b8ab72fe24aafddb99e9b6ea7 to your computer and use it in GitHub Desktop.
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
/* | |
ffmpeg -i "$file" -f s32be -acodec pcm_s32be -ar 44100 -af "volume=0.5" tcp://espip:5522 | |
*/ | |
#include "i2s.h" | |
#include <ESP8266WiFi.h> | |
const char* ssid = "***********"; | |
const char* password = "**********"; | |
WiFiServer pcmServer(5522); | |
static WiFiClient pcmClient; | |
void setup() { | |
Serial.begin(115200); | |
Serial.print("\n"); | |
Serial.setDebugOutput(true); | |
if (String(WiFi.SSID()) != String(ssid)) WiFi.begin(ssid, password); | |
while (WiFi.status() != WL_CONNECTED) delay(100); | |
pcmServer.begin(); | |
pcmServer.setNoDelay(true); | |
i2s_begin(); | |
i2s_set_rate(44100); | |
Serial.printf("Connected to: %s\n", ssid); | |
Serial.print("IP address: "); Serial.println(WiFi.localIP()); | |
} | |
void loop() { | |
if (pcmServer.hasClient()){ | |
if (!pcmClient || !pcmClient.connected()){ | |
if(pcmClient) pcmClient.stop(); | |
pcmClient = pcmServer.available(); | |
} else { | |
pcmServer.available().stop(); | |
} | |
} | |
if (pcmClient && pcmClient.connected()){ | |
while(pcmClient.available() >= 8){ | |
uint32_t data = 0; | |
//Right Channel | |
data |= (uint32_t)(pcmClient.read()) << 24; | |
data |= (uint32_t)(pcmClient.read()) << 16; | |
pcmClient.read();pcmClient.read(); | |
//Left Channel | |
data |= (uint32_t)(pcmClient.read()) << 8; | |
data |= pcmClient.read(); | |
pcmClient.read();pcmClient.read(); | |
i2s_write_sample(data); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment