mpd: output to SPI ?

Discuss client development (or even MPD development if you feel so inclined), ask questions about the client libs, MPD feature requests from client developers, etc...
Post Reply
pbisiac
Posts: 3
Joined: July 21st, 2019, 7:49 am

mpd: output to SPI ?

Post by pbisiac » July 21st, 2019, 8:03 am

Hi all, I would like to send mpd audio output to an external microcontroller (for further processing and I2S output).
I'm planning to use SPI (around 10Mbps) for stream output on MOSI line and would like to use the read line (MISO) to receive feedback from my microcontroller in order to trim mpd output speed in realtime.
So, mpd should be able to read this feedback and slow down playback on request.
My SBC is a Raspberry3 (at the moment).
Probably the best thing would be to study/modify an existing output module, but I'm quite new at this.

if anyone has any ideas or suggestions to give me to start it would be great.

max
Forum team
Posts: 938
Joined: January 15th, 2013, 3:43 pm

Re: mpd: output to SPI ?

Post by max » July 21st, 2019, 4:48 pm

There are many output plugins, and some of them are pretty complex (e.g. ALSA), and some are simpler but less featureful.
If you need any help, just ask.

pbisiac
Posts: 3
Joined: July 21st, 2019, 7:49 am

Re: mpd: output to SPI ?

Post by pbisiac » July 22nd, 2019, 6:58 am

My plugin should provide following features:

- supply an output channel to mpd (mpd will write blocks of data, which will be stored in a circular queue of RAM buffers)
- block transfer to host microcontroller via SPI;
- handshaking with host microcontroller, that will report back it's buffer filling status;
- reporting back to mpd (how ? with a callback function ? returning an error code upon writing ?) to slow down data transfer if necessary.

This way I should ensure that my microcontroller will always have samples to send out to my DAC (via I2S this time)

I suppose best approach would be to modify/recompile an output plugin.....a tutorial on this would be useful

BTW: I am using Volumio as a mpd client at the moment.

max
Forum team
Posts: 938
Joined: January 15th, 2013, 3:43 pm

Re: mpd: output to SPI ?

Post by max » July 22nd, 2019, 11:58 am

You should write a new output plugin, implementing the C++ interface "AudioOutput". That interface is documented. If you need more help than the existing documentation, ask.

pbisiac
Posts: 3
Joined: July 21st, 2019, 7:49 am

Re: mpd: output to SPI ?

Post by pbisiac » July 22nd, 2019, 1:00 pm

I see....

So, I should implement:
- Enable() or Open(), to initialise my SPI HW interface;
- Disable, or Close(), to clean it;
- Play(), to get and enqueue a chunk of data for SPI output (keeping track, inside my driver, of microcontroller fill status)
- Delay(), returning non-zero until I need/can get mode chunks

Am I right ?
Is there some documentation/guidelines for compiling/inserting a custom plugin into mpd ?

Thank you for your help.

max
Forum team
Posts: 938
Joined: January 15th, 2013, 3:43 pm

Re: mpd: output to SPI ?

Post by max » July 23rd, 2019, 9:06 am

Implementing Enable/Disable is optional. If you don't know a reason to implement them, don't.

For now, Open/Play/Close are important. Play shall block until at least one frame has been consumed (or until an error occurs).

Delay is optional as well; it can be implemented if you know that the next Play call will block for a known amount of time, and giving that duration back to MPD can help MPD by making the wait time cancellable.

Post Reply