|Since||Origin / Contributor||Maintainer||Source|
|2016-06-05||Arnim Läuger||Arnim Läuger||pcm.c|
Play sounds through various back-ends.
The ESP contains a sigma-delta generator that can be used to synthesize audio with the help of an external low-pass filter. All regular GPIOs (except GPIO0) are able to output the digital waveform, though there is only one single generator.
The external filter circuit is shown in the following schematic. Note that the voltage divider resistors limit the output voltage to 1 VPP. This should match most amplifier boards, but cross-checking against your specific configuration is required.
This driver shares hardware resources with other modules. Thus you can't operate it in parallel to the
pwm modules. They require the sigma-delta generator and the hw_timer, respectively.
Audio is expected as a mono raw unsigned 8 bit stream at sample rates between 1 k and 16 k samples per second. Regular WAV files can be converted with OSS tools like Audacity or SoX. Adjust the volume before the conversion.
sox jump.wav -r 8000 -b 8 -c 1 jump_8k.u8
Also see play_file.lua in the examples folder.
Initializes the audio driver.
pcm.SD use sigma-delta hardware
pin 1~10, IO index
Audio driver object.
Audio driver sub-module¶
Each audio driver exhibits the same control methods for playing sounds.
Stops playback and releases the audio hardware.
Register callback functions for events.
drv:on(event[, cb_fn[, freq]])
eventidentifier, one of:
datacallback function is supposed to return a string containing the next chunk of data.
drainedplayback was stopped due to lack of data. The last 2 invocations of the
datacallback didn't provide new chunks in time (intentionally or unintentionally) and the internal buffers were fully consumed.
pausedplayback was paused by
stoppedplayback was stopped by
vunew peak data,
freqtimes per second (1 to 200 Hz).
cb_fncallback function for the specified event. Unregisters previous function if omitted. First parameter is
drv, followed by peak data for
rate sample rate. Supported are
pcm.RATE_16K and defaults to
RATE_8K if omitted.
Pauses playback. A call to
drv:play() will resume from the last position.
Stops playback and releases buffered chunks.