[Proposal] I2S interface for audio

No, I wasn’t thinking about abusing the usb interface but using the usb bus. But it’s still completely backward and makes no sense :slight_smile:

Sure, that is how it generally works, also in embedded contexts (stm/arduino/raspi picos). Usually that’s what the libraries/drivers do (for instance wire on arduino). The only additional issue I see is the necessity for setting an additional ID on the bus which may be worked around if one finds an I2C/I2S codec that supports setting the same. Providing the clock is not an issue. The clock timing issue is actually usually a non-issue since the dacs usually just consume to the top of their buffer and you only need to beware not to exhaust your buffers faster than the dac can consume them. Generally, you don’t want to try to deal with the real audio rate but leave it to the dac.

EDIT: recently I’ve mostly been using the raspberry pi pico (and pico 2) for reasons and I2S (Digital Audio) Audio Library — Arduino-Pico 6.1.0 documentation arduino-pico/libraries/I2S/src/I2S.cpp at master · earlephilhower/arduino-pico · GitHub the way that I2S is implemented is such that you can swap out PWM for I2S without changing much code. That’s a case where there is no dedicated I2S device on the soc at all and it’s all done with PIO state machines. Although you have control over the clocks, I never touch them. The driver defaults to 48kHz and that has worked flawlessly with several dacs. But one could go higher if one had an application that needed to.

I’m probably offtopic here[1], and maybe I’m also just being thick :slight_smile:, but how do you connect to the USB bus without using the only USB connector there is?

I have the impression that the I3C clock doesn’t have to be fixed, so maybe a stronger guarantee is needed when deriving a clock for the DAC

I discussed this with someone in the context of building a TOH with a 3.5 mm jack for headphones/headsets. The conclusion was that buffer under-/overruns are inevitable, unless the DAC clock in the TOH and the audio clock in the phone are the same.

For file playback, where you can be flexible about buffering and request more data “at any time”, this is less of an issue. But for “realtime” audio, like from a headset mic, I think it will lead to clicks and other artifacts.


  1. Since this thread is about (TOHs) having I2S instead of/in addition to I3C ↩︎

On topic: Since there is out-of-band TOH detection and identification, we could have a class of TOHs that request I2S instead of I3C.

If the SoC has configurable I/O pins, like many microcontrollers have, then this might even be possible without changes to circuit design or PCB - except for the missing left/right signal.

Looking at the phone with removed TOH, there is room for one more pogo pin, but of course it also has to be wired to something on the inside.) So, as far as I understand it, this will not be possible without a hardware revision of the phone, in addition to revised TOH specs.

Well, this is why I rejected my idea as being stupid :slight_smile: Though i have been know to do evil things with solder :slight_smile:

I have no idea about I3C, per se.

Realtime audio is slow. a headset mic being captured by a codec in stereo at 48kHz is not difficult to time on an interrupt or as in the case of the pico specific code I linked, statemachines running at a particular frequency. I have tons of driver code that will do clean acquisition on much less capable cpus (ie. stm 32 bit at 178mHz, picos 64bit, 2 cores, 276mHz). It’s just a question of responding to the codec. Much of my code is derived from mutable instruments code.
EDIT: I don’t mean to downplay the ‘considerations’, I guess I’m just used to dealing with codecs. eurorack/rings/drivers/codec.cc at master · pichenettes/eurorack · GitHub this is an example of an application where the peripheral bus (stm) is bitchy and you have to work around the soc to deal with the codec. I generally avoid that kind of proplem buy chosing another soc or another codec :slight_smile:

Speaking of stupid (but very effective) and since it’s a Phase Locked Loop application, I do PLL cmos hacks often the rack This very primitive abuse of the classic CD4046 PLL will actually track quite well. But the glitches are what makes it nice :slight_smile:

Me neither, what I know I picked up in discussions here…

The total bandwidth of I3C is high enough, but the issue seems to be a lack of guarantees that samples arrive on the beat, every time.

I.e. a hypothetical DAC can’t just shift incoming samples into its buffer and shift out the oldest one for conversion to analog, because then the sample clock will vary.

It also can’t just use an TXCO to get a stable clock, because it will not be in sync with the phone’s audio clock(s). And that will lead to buffer over-/underruns.

Another hypothetical I3C DAC could have a shortish buffer (8 samples?) and request more when half full. That would shift the work of dealing with differing clocks to someplace in the audio subsystem of the phone.

I did a casual search for I3C DACs that yielded nothing; whether because they don’t/can’t exist or because of lacking search skills is another matter.

A buffer would damp that. As long as the samples come with known “average” frequency.

To control buffer and DAC uC is needed anyway. I really doubt that it would be possible to avoid it. So which communication DAC use is not very relevant.

Use of Raspberry RP2040 or RP2350 is not expensive and they can be programmed either in C or micropython. Besides they also have PIO which can be very handy in this use case.

They probably do (with an unknown jitter), but when do you trigger the D→A conversion of a sample from the buffer? Do you simply set a timer for the average interval as computed up to now?

DAC clock can be sourced from eiher I2C/I3C CLK multiplied with PLL and then divided to minimise the jitter. Or can be done with uC. In that case some buffer under/overrun handling might be needed.

That’s sort of my original suggestion to use the I3C clock at a multiple of the sampling frequency on both sides (phone and TOH).

If you have a local clock, not synced with the phone, it _will_run at a different frequency than used in the phone. Thus you will run into buffering problems, either the TOH will keep starving or it will keep getting too many samples.

What would the consequences be for sound quality if TOH regularly just repeats the last received sample (underrun) or throws a sample away (overrun)?

On small buffer it migt not be noticable much. But hard to say without proper test.

The RP2350 doesn’t doe I3C natively though, so it might be easier to use a differemt MCU, that speaks I3C and I2S natively.

In such a case, you need some management protocol, where the TOH can signal to the phone “increase/decrease the transfer speed (frame rate, not necessarily I3C clock speed)“. The MCU in the TOH would try to always keep its buffer half-full (or half-empty, depending if you are an optimist or pessimist :wink:), and when the current filling level goes out of a specific band around this center point (but still safely away from zero and maximum buffer size), it will tell the phone to increase/decrease the transfer speed - not the sampling rate of the audio stream itself.

This removes the need to keep the I3C clock in sync with the I2S clock (or vice versa). They only need to be approximately close to each other, which will result in a permissible oscillation of the audio buffer filling level in the TOH. By cleverly setting the thresholds upon which the TOH will tell the phone to change the transfer speed, the management overhead on the I3C bus can be kept low.

Implementing such a management protocol on both sides (TOH and phone) however is a big can of worms on its own, I guess.

EDIT: The interrupt pin in the TOH spec could be used to signal such a transfer speed change request to the phone. So no need for the phone to constantly poll the TOH if everything is still alright.

Just a quick note about I2S DACs and buffering on the Pico 2040/2350.

Running at 276mHz, with the PIO drivers from raspi or using Philowers arduino port using DMA buffers of 32- 128 DAC.setBuffers(4, 128); // DMA buffers in 32-bit word lengths and only writing when the buffers have space is sufficient on dedicated devices. I have done manual timing, but it is not necessary. I never miss a beat.

The main issue is how to present the device to the OS and pulse. I haven’t looked at that yet, but, it’s not so complicated.

EDIT: And the I2C bus is limited to 400kHz but that is more than enough unless you interleave a number of devices.

Sounds great, Mark. Pun intended.

Heh. I have to admit that the more I’ve thought about it, the less reason I have to build a TOH for audio.

For ‘listening’ a usb dac is fine (thanks @Mister_Magister ) and although I do sometimes do a fast and dirty recording on the phone, it makes no sense to add hardware there. I have recording gear for that purpose. I am not going to arrive at that quality with a TOH. So, what do I want out of a TOH for audio?

I think it makes more sense for me to finally build a native synth/sampler for SFOS to scratch that itch. Then I might consider a MIDI TOH with TRS input/output!

What about a simple 3.5 out?

Yeah, I had thought about that. But, since testing out a number of usb dongles I just got used to having one around. Doesn’t mean we shouldn’t improve the audio output to analog jacks. One other reason I’ve been defaulting to usb dongles is literally that the 3.5 mm jacks won’t contact because of the bumper on my volla. I know, cut out the silicone. I know.

Not to spoil the fun, but couldn’t you use USB-C for all the MIDI needs as well? On another note I just recorded line-in via USB-C and I was happy to see it was just a plug-n-play.

And yes a native synth would be awesome! Wonder if Vital could be ported, the source is in Github.