Skip to content

Instantly share code, notes, and snippets.

@me-no-dev
Last active February 26, 2024 15:39
Show Gist options
  • Save me-no-dev/e8b5131f840822cdd14b to your computer and use it in GitHub Desktop.
Save me-no-dev/e8b5131f840822cdd14b to your computer and use it in GitHub Desktop.
/*
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);
}
}
}
@bbx10
Copy link

bbx10 commented Sep 16, 2016

This works fine using avconv instead of ffmpeg. The volume parameter is slightly different.

avconv -i "$file" -f s32be -acodec pcm_s32be -ar 44100 -af "volume=volume=0.5" tcp://espip:5522

Very cool!

@SwiCago
Copy link

SwiCago commented Apr 7, 2017

@me-no-dev does this do PCM over i2s in stereo? Thanks

@MarioP73
Copy link

MarioP73 commented Mar 25, 2018

Hello.
Have the script on the ESP8266 on it and connected the VS1053.
Data stream is running, sound comes from the VS1053.
What must be the pinout between the ESP and the VS1053?
I connected so:
1518951946198128982

Thanks

@zeitounian
Copy link

preciso de ajuda, como enviar a musica que está tocando no meu smartphone para o esp? Por favor me ajudem.

@miloit
Copy link

miloit commented Aug 6, 2021

Hello also possible the other way around send audio from Esp32 to PC??

@romakrau
Copy link

romakrau commented Jan 6, 2023

Hi, I try this code but unfortunatky it did'nt work. Can you give me a hi t. Thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment