Closed renne closed 4 years ago
Those are pretty hard to come by in the US, unfortunately. The chips themselves are only in the $5USD qty 1 range, but I suppose the analogs to go along with it and support 40W output (and I love using the PCB copper as the heatsink in these hats, very cool!) are pricey.
If you're handy with C++, I can point you in the direction you'd need to go to get these working.
It looks like these are I2C DACs that need to be programmed to handle specific formats (as opposed to the lower-cost ones which figure it out from WCLK and apply proper filters/etc. automatically) and to control speaker gain.
If so, then what you need to do is create and AudioOutput class that instantiates the standard I2S class and passes through data writes (ConsumeSample), but which wraps calls like SetFreq() or SetGain() and converts those into I2C commands to fire to the chip (and also pass the required ones like SetFreq() or SetChannels() along to the internal I2S object to ensure they are obeyed). If there's a C sample that plays a WAV using raw I2C on the RPI, it should have everything you need. You can add add'l member functions for things not envisioned in the standard one, like maybe "SetMute()" or "SetAudioTransform()."
That said, I think you may be connecting a gold-plated amp to an FM radio. While it's possible to send 24-bits/sample, we're only doing 16 to save memory (24bpp uses 2x the RAM, gives 1/2 the buffer time before you get underflow). The I2S clock generator is only accurate to within +/- 2-3%. libMAD has been compiled to favor speed over bit accuracy. And so on. Probably not worth the grief...
Yesterday I got a ESP32. ;-) I stumbled upon the STM STA333W. I ordered a 13$ power-amplifier at Aliexpress. It will be delivered in 4-8 weeks. It's basically a CM108 soundcard with a STA333W attached to the I2S output. I'll try to get to the I2S traces. For now I'll get the Adafruit I2S MEMS Mikrofon-Breakout - SPH0645LM4H and the Adafruit I2S 3W Class D Amplifier Breakout - MAX98357A.
Neat. The ESP32 is a completely different beast than the 8266, with way more hardware & IO accelerators, 2x the cores, 4x the RAM, and a bunch more IO pins. From what I've seen, though, the Arduino port for the 32 is not nearly as active or well supported as the 8266 (and that's not just because I'm part of the 8266 team!). Most folks using it seem to be using the raw SDK from Espressif. Given you don't ever need to do a yield()
or delay()
in the 2nd (user) core, you can often just recompile standard libraries to decode files, no need for this lib.
We don't need any I2S traces, actually. That protocol is as simple as can be and has no control options. It's just lrclk toggle, followed one cycle later by the 16 or 32 bits of audio data for the channel. It's I2C that's needed to control your cool TI DAC+AMP unit.
If you have a RPi and use the hat with it, there may be an I2C dumper you can run to watch what the RPIs does on the I2C bus when playing a simple 16-bit stereo WAV. That's really all that's needed, a list of I2C addr + data to send to prep the TI chip to accept the new input format. Even the source code for the sound driver might be enough to get this. The STA333W looks very different from the 5756, so I'm not sure the AliExpress board will be of much use.
I've used the 98357A board and it's nice and simple. For recording I'm now using(abusing) the stereo microphone PCB from a Google AIY box and it works amazingly well. When you get the Adafruit one, I'd love to hear how it works with the new I2S input subsystem!
I received the 13$ power-amplifier at Aliexpress today. It's not as linear as my AVR with room/speaker correction but sounds quite well. Instead of a STA333W it uses a STA333BW which can be configured either as stereo amplifier + stereo line-out or 2.1 amplifier. The I2C registers are documented.
The TI TAS5756M is an I2S power amplifier IC commonly used on Raspberry Pi audio amplifier (p)HATs. It is controlled via I2C and provides quite good sound quality.
As my IQAudIO Pi-DigiAmp+ was quite expensive I have compiled a list of currently available implementations: