Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
/*
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

This comment has been minimized.

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

This comment has been minimized.

Copy link

SwiCago commented Apr 7, 2017

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

@MarioP73

This comment has been minimized.

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

This comment has been minimized.

Copy link

zeitounian commented Sep 26, 2018

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.