/*
SD Wave file stream over UDP. Transmitter. (Client)
This sketch read Microsoft Wave files from microsd and stream over network
using UDP connectionless protocol. It is even possible to send broadcast to
all local network devices. Combine both mode it is possible to stream to another
device over internet, then the receiver (Server) will stream data to broadcast
devices on other local network.
Needs an UDP listener, another ESP or Netcat, VLC etc... that listen on port 8266 or 3232
Listener can be another ESP programmed to listen UDP packet stream and send it to audio out
or Android or Desktop app, or just a network media streamer like Netcat or VLC, if this is
a case on Linux start the UDP listener with the follow terminal commands:
Netcat: nc -u -p 8266 -l | play -t raw -r 44100 -b 16 -c 2 -e signed-integer -
VLC: vlc --demux=rawaud --rawaud-channels=2 --rawaud-samplerate=44100 udp://@:8266
NOTES:
- Using Netcat your audio pass through the linux ALSA driver, it can be routed to any audio
application and even processed with multiple effects at same time or can be sampled from
audio programs like Audacity, Ardour5 etc...
To do audio routing on linux we use Jack Audio Connection Kit, precisely we use QjackCtl or Pathage
(that offers a frontend GUI for Jack and ALSA audio drivers) to route ALSA audio to Jack audio and
optionally process it with realtime effects or just analyze with audio analyzers.
- If you use another ESP as listener you can adjust the volume by connecting a potentiometer on any ADC
- If you use VLC as listener, to adjust volume, use VLC volume control on the right bottom interface,
or just use a linux master volume control
- If you use Netcat, use a linux master volume control, you can even use alsamixer
Tested successfully on Wemos D1 Mini @ 44100Hz, 48000Hz, 96000Hz, 192000Hz 16Bit Stereo samples
This code is released to the Public Domain by Massimo Meli
Please read Licence.txt provided with ESPAudioClass library
*/
/*
Stream received UDP audio data to external I2S DAC.
Demonstrates the use of the ESPAudioClass library for ESP8266 and ESP32
Hardware required :
- Any ESP8266 with I2S pins exposed, eg. NodeMCU, Wemos D1, Wemos D1 Mini, Wemos D1 Mini Pro, or any clone,
on ESP-01 you can only use Sigma-Delta output on RX pin because it do not have others I2S pin exposed.
Any similar board with ESP32 Extensa Chip.
- One or more 44100 Hz, 16 bits, Stereo wave files in the root directory of the SD card, use short names 8.3 dos format.
- An audio amplifier or just headphones to connect to the DAC output (we tested on PCM5102A, any DAC can work)
- One or two speakers to connect to the audio amplifier if you do not use headphones.
- One potentiometer if you would to manually set the volume.
IMPORTANT NOTES:
- Set the SD SPI around the max speed possible
- Compile @ (160Mhz on ESP8266) or (240Mhz on ESP32) because can be CPU intensive so need to work as fast possible
- if you do not have DAC you can get output from RX pin, the library use even Sigma-Delta output, or if you use ESP32
can output from internal DAC0 & DAC1 (GPIO25, GPIO26), but this way you reduce the audio quality because dacs are not
16 bits. If use Sigma-Delta output you just need to add a passive filter to the output pin. Note that this
way you have MONO sound output only, for best quality we suggest to use a small DAC board.
- Start with low volume, if you use an amplifier, lower the volume before ESP start executing the sketch,
if you use headphones you may do not have a possibility to set the volume, set it with the library in the
Audio.prepare() method, you can set the volume from 0 to 1024, may put it on the midle 512 for first tests
then you can increase it. Values > 1024 do not overflows, just the library limit the output so you can't have
distort sound. The best and faster way to control the volume is to connect a potentiometer to analog input (A0)
and pass the ADC value when use Audio.prepare method, you can even use Audio.getVolumeL(), Audio.getVolumeR()
to get it.
- This sketch was tested with 44100 Hz, 16 bits, Stereo wave files on Wemos D1 Mini Pro 2.0 and Raspberry Zero
PHAT DAC that has a PCM5102A mounted on it. Low cost for superb audio quality, as many other DACs it output
up 192Khz 32 bits per sample, but ESP8266 I2S output can't output 24 or 32 bits? I do not tried infos on
Arduino Core Documentation.
Copyright (c) 2020 Massimo Meli. All right reserved.
This example code is in the public domain, see attached Licence file
*/