Page 1 of 1

mpd: output to SPI ?

Posted: July 21st, 2019, 8:03 am
by pbisiac
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.

Re: mpd: output to SPI ?

Posted: July 21st, 2019, 4:48 pm
by max
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.

Re: mpd: output to SPI ?

Posted: July 22nd, 2019, 6:58 am
by pbisiac
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.

Re: mpd: output to SPI ?

Posted: July 22nd, 2019, 11:58 am
by max
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.

Re: mpd: output to SPI ?

Posted: July 22nd, 2019, 1:00 pm
by pbisiac
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.

Re: mpd: output to SPI ?

Posted: July 23rd, 2019, 9:06 am
by max
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.