Experimental SP/DIF output on expansion pins of RP2040 boards #201
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Enables audio playback on RP2040 boards via one of the expansion header pins. Core1 is used to translate 16-bit signed PCM samples to emulated biphase mark code, which is then sent over SPI1 (clocked at about 5.6448MHz) to generate a SP/DIF datastream. Functions are provided with an eye toward eventual CD-ROM integration, with audio_play() and audio_stop() calls allowing playback to proceed in the background, supported by the new platform_poll() call (thanks again for that!)
Hardware to get this going is pretty simple: for testing I've been using an Everlight PLT133 powered from the 3V at the expansion header, connected to various Toslink DACs. Audio playback is generally stable during light computer use, but dropouts do occur during extended disk I/O, particularly writes. As mentioned in the discussion this could probably be helped by additional sample buffering capacity (currently 2x8K).
There are some 'hacky' things to note:
Right now all code is behind an ENABLE_AUDIO_OUTPUT include guard, currently disabled. I've tested this on a pretty small set of computers and things are definitely on the 'unstable' side of experimental. I'm very open to suggestions for changes!
For testing, you'll need a 16-bit signed stereo PCM file in 'raw' format written to the memory card. I used Audacity to generate them. See lines removed in this commit for an example of setting up audio playback.