Driver for interacting and playing media files with the VS1053 audio codec over a SPI connection.
NOTE: This is not currently working for audio playback of files. Only sine wave test currently works. The problem is that pure Python code is currently too slow to keep up with feeding data to the VS1053 fast enough. There’s no interrupt support so Python code has to monitor the DREQ line and provide a small buffer of data when ready, but the overhead of the interpretor means we can’t keep up. Optimizing SPI to use DMA transfers could help but ultimately an interrupt-based approach is likely what can make this work better (or C functions built in to custom builds that monitor the DREQ line and feed a buffer of data).
Author(s): Tony DiCola
Software and Dependencies:
Adafruit CircuitPython firmware for the supported boards: https://github.com/adafruit/circuitpython/releases
Adafruit’s Bus Device library: https://github.com/adafruit/Adafruit_CircuitPython_BusDevice
- class adafruit_vs1053.VS1053(spi, cs, xdcs, dreq)¶
Class-level buffer for read and write commands.
- property byte_rate¶
Return the bit rate in bytes per second (computed each second). Useful to know if a song is being played and how fast it’s happening.
- property decode_time¶
Return the decode time register value. This is the amount of time the current file has been played back in seconds.
- play_data(data_buffer, start=0, end=None)¶
Send a buffer of file data to the VS1053 for playback. Make sure the ready_for_data property is True before calling!
- property ready_for_data¶
Return True if the VS1053 is ready to accept data, false otherwise.
Perform a longer full reset with clock and volume reset too.
- set_volume(left, right)¶
Set the volume of the left and right channels to the provided byte value (0-255), the lower the louder.
- sine_test(n, seconds)¶
Play a sine wave for the specified number of seconds. Useful to test the VS1053 is working.
Perform a quick soft reset of the VS1053.
Prepare for playback of a file. After calling this check the ready_for_data property continually until true and then send in buffers of music data to the play_data function.
Stop any playback of audio.
- property version¶
Return the status register version value.