Electronics > Projects, Designs, and Technical Stuff

Custom Audio DSP with USB and I2S or TDM

(1/8) > >>

Looking at this or similar, but not married to anything in particular:

I think my biggest problem will be to graduate up from PIC16's and ATmega's with all custom code and no libraries*, to something that can handle the throughput that something like this requires!  (I looked briefly at a PIC16F1454, but when the maximum instruction rate is the same as an external bit clock...ehh, no.)

(*It took some effort to convince the PIC port of SDCC to not add the C-standard init code, but go directly to my main() function instead.  Turns out you just name it something else so that there is no main(), and then map an inline assembly function at the reset vector to long-jump to wherever the linker decides to put your renamed_main().  Then YOU are responsible to initialize everything...or not as the case may be.)

Is the above a good chip to pick?  Is there a better one?  Why for both of those questions?  What (free!) toolchain and possible libraries do I need, considering the possibility of some commercial projects later on?  (GCC and Code::Blocks would be nice, as I already know them from some AVR projects, but others would be okay too)  How to manage a DMA?  Etc.

I want to start with this block diagram, just to get my feet wet, and I have a project that can use it anyway:

| USB Composite Device         |        +----------+        +------------------+
| - 2-ch Audio                 |------->|    DSP   |------->| 2.1 Speaker Out  |
| - HID for custom control app |        +----------+        +------------------+
+------------------------------+              |                                 
                                    | Physical Controls |                       
                                    | - Potentiometers  |                       
                                    | - Encoders        |                       
                                    | - Buttons         |                       
                                    | - LED's           |                       

It's pretty much what you'd think: a stereo-input USB sound card with EQ and crossover to stereo tops and a mono sub, plus some direct physical controls.  If it weren't for the physical controls, I could just buy that instead of making one, but the bigger purpose is to learn the building blocks to then do this:

            +------------------+        +----------+        +----------------------+
            | Stereo Mic In    |------->|          |------->| Stereo Line Out      |
            +------------------+        |          |        +----------------------+
                                        |          |                               
            +------------------+        |          |        +----------------------+
            | Stereo Mic In    |------->|          |------->| Stereo Speaker Out   |
            +------------------+        |          |        +----------------------+
                                        |    DSP   |                               
            +------------------+        |          |        +----------------------+
            | Stereo Line In   |------->|          |------->| Mono Line Out        |
            +------------------+        |          |        +----------------------+
                                        |          |                               
+------------------------------+        |          |        +----------------------+
| USB Composite Device         |<------>|          |------->| Mono Speaker Out     |
| - 8-ch in / 8-ch out Audio   |        +----------+        +----------------------+
| - HID for custom control app |                                                   

That's a total of 6 channels in and 6 channels out of analog audio (counting amplified speakers as analog to allow for digital-input class-D amp chips), for either 3x I2S streams between the ADC's and DAC's/amps, or 1x TDM-8 for all of it.

I2S looks similar enough to SPI that I might be able to use a SPI peripheral to fake it?  And TDM is based on I2S with the same similarities, so maybe I can still use a SPI peripheral for that?  The bit clock of TDM-8, 32-bit, 48kHz, is just a hair above 12MHz, so it'd have to be a pretty fast chip compared to what I'm used to, just for that.

The analog-to-analog signal path of this one has a very tight constraint on the overall latency - there are two mic-to-speaker paths in there, with just a handful of samples' worth of distance at 48kHz through some foam, and the DSP's purpose is mostly to undo the foam's acoustic lowpass (plus some transducer correction and limiting) - so I think I need to write my own transport and DSP code to operate on single samples instead of a block of 64 or so like I see being common, just to have the acoustic and electronic wavefronts line up.  I think I'm okay with writing the DSP code; from what I've seen on Wikipedia and some dedicated DSP coding sites, that part should be easy once I get a new chip up and running in the first place.

USB has so such requirement: it's pretty much a monitor for recording/debugging at several different points simultaneously along the processing chain, so it can fill up a buffer and send it off whenever it gets around to it.  Likewise in the other direction, it can get a buffer from USB and then play it out.  That's fine; the critical latency doesn't apply to this connection.

And like the diagram says, drop the physical controls for this one.  But I might add some other functionality, unrelated to audio, depending on the amount of CPU time and other resources that I have left over.

For both projects, I think I want the DSP chip to have the master clock (and give it a good one!), and everything else slaves to that, including USB, which would then need to run its audio interface in "asynchronous" mode.  Don't need any options for USB Audio: just 2 or 8 channels (depending on the project) of 32-bit integer at 48kHz, and that's it.  Not even any controls, as the DSP code (with its custom HID connection and corresponding app) covers that and more.

The NXP iMXRT1010, iMXRT1020 ... all the way up to the iMXRT1060(there are last digit variations within each group) have a 500/600MHz ARM M7 core with lots of peripherals. The 1010 and 1020 are LQFP the rest are BGA. Value for the range is exceptional and the 1020 EVK board comes with an on board audio CODEC with audio software examples via USB. The grandest chip is the iMXRT1172 which is dual core, one at 1000MHz and the other at 400Mhz and heaps of audio interfaces. You could use the 400MHz core to control the peripherals and the 1000MHz core as your DSP. Hope that helps. :)

If you a just starting and planning on using vendor libraries, I would not use SAM4S. It is an older device, which is not supported by modern libraries. You would have to deal with old libraries that are mostly out of support now. They are still functional, of course, but may not be the best starting point.

I would also try to avoid using SPI for I2S emulation. It would be hard to get the timings consistent.

Start with more recent devices.

Does it have to work with windows <10?

SPI as I2s: Nope, you have more signals, so DMA wouldn't work, and your micro would spend most of it's time in interrupt for that many channels. And I2S carries playback speed, so you need precise control over it's speed, so extra hardware in the micro.
USB: Just note that most microcontroller have USB 1.1 speed, 12MBPS. If you playback 16x channel at 16 bits @ 48 KHz, you are above that, AFAIK you can fit maybe 6 channel on a Audio class 1 device. Going to Audio class 2 limits the available micros a lot, simply because they just don't have example firmware.


[0] Message Index

[#] Next page

There was an error while thanking
Go to full version