USB interface for multi channel outputs, not just stereo

Hello, I have modify the contents under the teensyduino app according to the instruction in the readme file in the repo. (I am on Mac and I didn't find suitable old teensyduino installer so I am running everything under the standalone teensyduino app.)

I also did this all:
- Select your Teensy board using the Teensyduino menu.
- Ensure USB type is Audio.
- Ensure USB channels is 8.
- Ensure you select your port from the "Teensy port" section.

I am sending 8 tones to the 8 outputs and I can hear all the 8 tones. Just it's only a very short sound, like for half second and it's cut off. I tried to change the AUDIO_SUBSLOT_SIZE in the usb_desc.h from 2 to 3 and then the cut-off sound turned to repeated cut-off (like beap...beap...beap..) Is it the 16/24 bit formatting? The 8 tones was sent from max/msp under 44100 sample rate. I tried to change the I/O vector and signal vector size but didn't help. Any ideas?


Code:
#include <Audio.h>

// GUItool: begin automatically generated code
AudioInputUSBOct         usb_oct1;       //xy=189,160
AudioOutputTDM           tdm1;           //xy=508,157

AudioConnection          patchCord1(usb_oct1, 0, tdm1, 0);
AudioConnection          patchCord2(usb_oct1, 1, tdm1, 2);
AudioConnection          patchCord3(usb_oct1, 2, tdm1, 4);
AudioConnection          patchCord4(usb_oct1, 3, tdm1, 6);
AudioConnection          patchCord5(usb_oct1, 4, tdm1, 8);
AudioConnection          patchCord6(usb_oct1, 5, tdm1, 10);
AudioConnection          patchCord7(usb_oct1, 6, tdm1, 12);
AudioConnection          patchCord8(usb_oct1, 7, tdm1, 14);

AudioControlCS42448      cs42448_1;      //xy=337,337
// GUItool: end automatically generated code

void setup() {
  AudioMemory(200);
  Serial.begin(9600);
}

void loop() {
}
 
Last edited:
Personnally i always initialize the cs42448,were i can set the output level and verify the initialization:

Code:
if (cs42448_1.enable() && cs42448_1.volume(0.8)) {
    Serial.println("configured CS42448_1");
  } else {
    Serial.println("failed to config CS42448_1");
  }

no set level -> no output sound?

But there is something's missing and i only noticed it today because i have not used usb_oct since about2 weeks,
i updated the Audio-feature-multi-TDM,and now i can't see any of usb_oct object in the editor,and
in any of my sketches i created with usb_oct,the same with the example of Weiweiweiwear,
is there someone to confirm my discovering,am i dreaming??

EDIT: i have not the last teensy 1.60X update, i did only update the Audio-feature-multi-TDM,about one week ago,
i remember h4yn0nnym0u5e did a united gui with all the new options,a far time before,including usb_oct,if i'm not wrong...
 
Last edited:
I recover the "index-with-multi-TDM-and-USB" gui of the editor,that i put in the trash with the old "Audio-feature-multi-TDM" folder,
thinking the update will be with all the new options with usb_oct,but it was not.
So now i can play with usb_oct objects,but i wonder
if those new options : multi TDM & usb_oct are really together in the new teensysuino 1.60 #beta x
 
No, so far neither of those are even at the PR stage, let alone being in a TD 1.60 beta.

The multi-channel USB is quite complex, and will require synced PRs for both cores and Audio, plus ideally some buy-in from Paul to add options to the Tools menu to select at least the channel count, and if possible the sample rate and audio block size. The multi-TDM is very new, and even last week was still getting bugs fixed ... I'd like a few more reports of satisfactory functioning before putting in a PR. There are plenty of examples of badly-thought-through or even totally broken PRs, I don't want to add to them!

I'm sure Paul will be fully aware of these developments, so obviously if he posts on the relevant threads that he'd like some PRs to be submitted then we're poised to act. If not ... well, eventually the PRs will happen anyway.
 
I'm such a candid and naive man on this subject,i was ready to erase the PR's to get the new teensyduino,
a chance we have a trace of your updates and gui adaptation on this thread.
What do you want for testings? If i can help with...🤠
 
@h4yn0nnym0u5e: If we really make PRs at some point, I think we even don't need to make synced PRs for the core and for the audio library.
We could split up our changes into three PRs:
1. A first PR can be done for the files in https://github.com/alex6679/teensy-4-usbAudio/tree/main/changedCorefiles for the core. I would also set the default value of USB_AUDIO_NO_CHANNELS_480 in usb_desc.h back to 2. This PR should work on its own and would only change the usb audio standard from 1 to 2 and should solve the problem with the audio glitches.

2. A second PR can be made for your files in https://github.com/alex6679/teensy-4-usbAudio/tree/main/changedConfigfiles. This changes shouldn't brake anything if used with the current Audio library. Right?

3. Finally a PR at the Audio library can be done to update the GUI.

As long as the changes to the core library are merged before the changes of the audio library, everything should be fine. Or did I miss something?
 
You're right, they could be done incrementally, though my feeling is that having only part of the changes will make things a bit unwieldy for anyone who wants to try them out. But that'd be Paul's call - so long as we cross-reference the PRs then he'll know they're associated, and can deal with them as seems to make the most sense, or ask for changes.

I think the best route would probably be to do one PR for cores+config, and another for Audio. The PR for cores would include the config files somewhere "safe", and a note not just to pull them in but use as a template for the actual config files. I know from previous threads that there's no repo for those, they're constructed via some script magic that only Paul has.

The USB channels selection is safe; selection of sample rate is fairly safe, though there will be issues if users try to use 8 channels at 96kHz, because that's not possible at USB Full Speed (12Mb/s); changing audio block size can definitely break some library objects, but the solution to that is simply to stick with 128 samples. Dedicated users will probably then start to fix the fragile objects, because they want e.g. the lower latency that comes with smaller blocks.

The Audio library PR will, as you say, just update the Design Tool and also keywords.txt for syntax highlighting.

As the USB code is pretty much all yours, would you be happy to assemble the updated cores+config, and do a PR for it? Just say if not, and I'll do it but try to ensure you get the credit! And I'll do the Audio library changes.
 
Hey I couldn't post pic in private conversation with @alex6679 (i don't want to bother people with low level debugging), but I am having this in plotter, however, as said, it only lasts for 0.5 second and then it goes back to 0 when the AUDIO_SUBSLOT_SIZE = 2. I recorded a film of it and i put it on my instagram story.

if I change AUDIO_SUBSLOT_SIZE = 3, the cut-off will turn to repeated. It seems like I have missed some really basic settings?

Also i just saw Alex he just updated the github repo, I don't think I should download the latest repo since the old version worked for all you guys. 🤔

Screenshot 2024-10-04 at 2.55.24 PM .jpg
 
Last edited:
Works for me, here, on Windows 10, with a version of your sketch from post #127 modified to initialise the CS42448 properly. I played back an 8-channel WAV file using GoldWave, and got the expected outputs. Your screenshot is very pretty, but the actual code you ran would be more useful.

Also I don't think I should downloaded the latest repo from alex since it worked for all you guys. 🤔
Not sure what you intended to say here, but you definitely should make sure you have the latest version.
 
Last edited:
Works for me, here, on Windows 11, with a version of your sketch from post #127 modified to initialise the CS42448 properly. I played back an 8-channel WAV file using GoldWave, and got the expected outputs. Your screenshot is very pretty, but the actual code you ran would be more useful.


Not sure what you intended to say here, but you definitely should make sure you have the latest version.
sorry I re-edited my question.

Ok so if this works for you then it must be the configuration settings? Did you check my video? can you guess what could be the cause?

I think the code I was using the example test code which Alex mentioned in #129.

Anyway I think this is all goood news if you are able to run it with my code without any issue, it’s must be me making sth wrong with the configuration somewhere. I don’t think it’s a Mac problem.
 
Last edited:
Haven't checked your video: don't think it was part of the original post, and in any case I don't do Instagram so no way of seeing it. To be honest, apart from confirming that you have an issue, it's unlikely that it would help resolve things.

I've never run the plotter test before, but I tried that, too, just in case. That works for me, as well.

If you can, it would be good for you to try on a Windows PC (I said Windows 11 but since edited it to 10; either should be fine). If that works then there's something about your Mac environment that's at issue, but whether it's OS settings or something needs fixing in @alex6679's code, I couldn't say. We do have one Mac user (@toyosm) who I believe has it working OK.
 
Haven't checked your video: don't think it was part of the original post, and in any case I don't do Instagram so no way of seeing it. To be honest, apart from confirming that you have an issue, it's unlikely that it would help resolve things.

I've never run the plotter test before, but I tried that, too, just in case. That works for me, as well.

If you can, it would be good for you to try on a Windows PC (I said Windows 11 but since edited it to 10; either should be fine). If that works then there's something about your Mac environment that's at issue, but whether it's OS settings or something needs fixing in @alex6679's code, I couldn't say. We do have one Mac user (@toyosm) who I believe has it working OK.
Yeah, so far so good, tried on a couple different Macs and it's all working perfectly!
 
Hey Weiweiweiwear,try this sketch,i just tested with goldwave,it's okay

Code:
#include <Audio.h>
#include <Wire.h>
#include <SPI.h>
#include <SD.h>
#include <SerialFlash.h>

// GUItool: begin automatically generated code
AudioSynthWaveformSine   sine2;          //xy=87,87
AudioSynthWaveformSine   sine1;          //xy=89,45
AudioSynthWaveformSine   sine3;          //xy=89,126
AudioSynthWaveformSine   sine4;          //xy=90,166
AudioSynthWaveformSine   sine5;          //xy=93,207
AudioSynthWaveformSine   sine6;          //xy=95,248
AudioSynthWaveformSine   sine8;          //xy=97,333
AudioSynthWaveformSine   sine7;          //xy=99,292
AudioOutputUSBOct        usb_oct2;       //xy=328,165

AudioConnection          patchCord1(sine2, 0, usb_oct2, 1);
AudioConnection          patchCord2(sine1, 0, usb_oct2, 0);
AudioConnection          patchCord3(sine3, 0, usb_oct2, 2);
AudioConnection          patchCord4(sine4, 0, usb_oct2, 3);
AudioConnection          patchCord5(sine5, 0, usb_oct2, 4);
AudioConnection          patchCord6(sine6, 0, usb_oct2, 5);
AudioConnection          patchCord7(sine8, 0, usb_oct2, 7);
AudioConnection          patchCord8(sine7, 0, usb_oct2, 6);

AudioControlCS42448      cs42448_1;      //xy=334,306
// GUItool: end automatically generated code


void setup()
{

  AudioMemory(1000);

  if (cs42448_1.enable() && cs42448_1.volume(0.8)) {
    Serial.println("configured CS42448_1");
  } else {
    Serial.println("failed to config CS42448_1");
  }

   sine1.frequency(1200);
   sine1.amplitude(0.3);

   sine2.frequency(1200);
   sine2.amplitude(0.3);

   sine3.frequency(500);
   sine3.amplitude(0.3);

   sine4.frequency(600);
   sine4.amplitude(0.3);

   sine5.frequency(800);
   sine5.amplitude(0.3);

   sine6.frequency(1100);
   sine6.amplitude(0.3);

   sine7.frequency(1300);
   sine7.amplitude(0.3);

   sine8.frequency(1500);
   sine8.amplitude(0.3);                      
                         
         
}

void loop()
{
}

The result in goldwave:

Goldwave 8 channels.png
 
@Weiweiweiwear: Thank you for the test. At least we know you problem has nothing to do with your audio codec or its configuration. Once I had a similar problem and the reason in my case was a broken usb cable. I connected the Teensy and started playing music. It worked for some time (a few seconds up to a few minutes) without any issues and then the Teensy just stopped streaming the music. In the Windows audio settings it looked like the Teensy was working, but it wasn't. It also didn't crash because when I plugged the usb cable out and in again, the Teensy received the audio signal again. (The Teensy wasn't restarted because it had an own power supply and did not depend on the usb power.) Can you switch the usb cable and test if it makes a difference?
Also, you should definitely use the latest version of the code.
Then, if switching the cable and the latest code version do not fix the problem:
In the example with the serial plotter there are more options that can be used for debugging. Can you run the example again, but this time don't plot the waveform. Instead the usb input status may give us some hints whats going on. You just need to change two line in the example:
C++:
//activate one of the four options
//#define PLOT_SIGNAL               //use Arduino Serial Plotter -> comment out this line
//#define PLOT_BUFFER             //use Arduino Serial Plotter
//#define PLOT_REQUEST_FRREQ      //use Arduino Serial Plotter
#define PRINT_USBINPUT_STATUS   //prints information like number of buffer over and underruns -> activate this line
In the Arduino Serial Monitor you will see the current status (updated every second) of the usb input. It is especially interesting how the status changes when the problem occurs. Maybe there is a buffer over- or underrun and the usb input doesn't recover from it properly.
 
@AntiLoop It seems you want to send 8 sines from CS42448 to the PC, I have uploaded the code successfully and I have received the correct signal in Mac, just with the same repeated cut-off (regular repeating on and off). But what I want now is AudioInputUSBOct not AudioOutputUSBOct.

However just to say again, I did successfully output 8 sines from teensy to speakers, with the example code: Audio -> hardwaretesting -> waveFormsTDM16 under Arduino IDE 2.3.3 AND Teensyduino standalone app 1.8.19. Its with AudioOutputTDM though.

Code:
AudioOutputTDM           tdm1;       //xy=524,345

@alex6679 I have switched to another USB cable and am using the latest code from your repository now but still without a success. (still the repeated cut-offs) Here is what I have after I modified the plotter code:

Code:
buffer overrun: 0
buffer underruns: 142
memory underruns: 0
buffer target number of samples : 79.38
number of transmitted channels : 8
size of ring buffer : 3
size of usb receive and transmit buffers : 576
currently receiving data : 1
bInterval [uS] : 500
buffered samples (smooth): 78.19

buffer overrun: 0
buffer underruns: 143
memory underruns: 0
buffer target number of samples : 79.38
number of transmitted channels : 8
size of ring buffer : 3
size of usb receive and transmit buffers : 576
currently receiving data : 1
bInterval [uS] : 500
buffered samples (smooth): 78.39

buffer overrun: 0
buffer underruns: 143
memory underruns: 0
buffer target number of samples : 79.38
number of transmitted channels : 8
size of ring buffer : 3
size of usb receive and transmit buffers : 576
currently receiving data : 0
bInterval [uS] : 500
buffered samples (smooth): 78.47

buffer overrun: 0
buffer underruns: 144
memory underruns: 0
buffer target number of samples : 79.38
number of transmitted channels : 8
size of ring buffer : 3
size of usb receive and transmit buffers : 576
currently receiving data : 0
bInterval [uS] : 500
buffered samples (smooth): 78.57

buffer overrun: 0
buffer underruns: 146
memory underruns: 0
buffer target number of samples : 79.38
number of transmitted channels : 8
size of ring buffer : 3
size of usb receive and transmit buffers : 576
currently receiving data : 0
bInterval [uS] : 500
buffered samples (smooth): 116.68

buffer overrun: 0
buffer underruns: 147
memory underruns: 0
buffer target number of samples : 79.38
number of transmitted channels : 8
size of ring buffer : 3
size of usb receive and transmit buffers : 576
currently receiving data : 1
bInterval [uS] : 500
buffered samples (smooth): 77.81

buffer overrun: 0
buffer underruns: 149
memory underruns: 0
buffer target number of samples : 79.38
number of transmitted channels : 8
size of ring buffer : 3
size of usb receive and transmit buffers : 576
currently receiving data : 1
bInterval [uS] : 500
buffered samples (smooth): 77.33

buffer overrun: 0
buffer underruns: 150
memory underruns: 0
buffer target number of samples : 79.38
number of transmitted channels : 8
size of ring buffer : 3
size of usb receive and transmit buffers : 576
currently receiving data : 1
bInterval [uS] : 500
buffered samples (smooth): 78.51

buffer overrun: 0
buffer underruns: 152
memory underruns: 0
buffer target number of samples : 79.38
number of transmitted channels : 8
size of ring buffer : 3
size of usb receive and transmit buffers : 576
currently receiving data : 1
bInterval [uS] : 500
buffered samples (smooth): 78.06

buffer overrun: 0
buffer underruns: 153
memory underruns: 0
buffer target number of samples : 79.38
number of transmitted channels : 8
size of ring buffer : 3
size of usb receive and transmit buffers : 576
currently receiving data : 1
bInterval [uS] : 500
buffered samples (smooth): 78.26

buffer overrun: 0
buffer underruns: 155
memory underruns: 0
buffer target number of samples : 79.38
number of transmitted channels : 8
size of ring buffer : 3
size of usb receive and transmit buffers : 576
currently receiving data : 1
bInterval [uS] : 500
buffered samples (smooth): 78.43

buffer overrun: 0
buffer underruns: 157
memory underruns: 0
buffer target number of samples : 79.38
number of transmitted channels : 8
size of ring buffer : 3
size of usb receive and transmit buffers : 576
currently receiving data : 1
bInterval [uS] : 500
buffered samples (smooth): 78.95

buffer overrun: 0
buffer underruns: 159
memory underruns: 0
buffer target number of samples : 79.38
number of transmitted channels : 8
size of ring buffer : 3
size of usb receive and transmit buffers : 576
currently receiving data : 1
bInterval [uS] : 500
buffered samples (smooth): 78.19

buffer overrun: 0
buffer underruns: 161
memory underruns: 0
buffer target number of samples : 79.38
number of transmitted channels : 8
size of ring buffer : 3
size of usb receive and transmit buffers : 576
currently receiving data : 1
bInterval [uS] : 500
buffered samples (smooth): 77.69

buffer overrun: 0
buffer underruns: 162
memory underruns: 0
buffer target number of samples : 79.38
number of transmitted channels : 8
size of ring buffer : 3
size of usb receive and transmit buffers : 576
currently receiving data : 1
bInterval [uS] : 500
buffered samples (smooth): 78.87

buffer overrun: 0
buffer underruns: 164
memory underruns: 0
buffer target number of samples : 79.38
number of transmitted channels : 8
size of ring buffer : 3
size of usb receive and transmit buffers : 576
currently receiving data : 1
bInterval [uS] : 500
buffered samples (smooth): 78.38

buffer overrun: 0
buffer underruns: 166
memory underruns: 0
buffer target number of samples : 79.38
number of transmitted channels : 8
size of ring buffer : 3
size of usb receive and transmit buffers : 576
currently receiving data : 1
bInterval [uS] : 500
buffered samples (smooth): 77.54

buffer overrun: 0
buffer underruns: 167
memory underruns: 0
buffer target number of samples : 79.38
number of transmitted channels : 8
size of ring buffer : 3
size of usb receive and transmit buffers : 576
currently receiving data : 1
bInterval [uS] : 500
buffered samples (smooth): 79.10

buffer overrun: 0
buffer underruns: 168
memory underruns: 0
buffer target number of samples : 79.38
number of transmitted channels : 8
size of ring buffer : 3
size of usb receive and transmit buffers : 576
currently receiving data : 1
bInterval [uS] : 500
buffered samples (smooth): 78.27

buffer overrun: 0
buffer underruns: 169
memory underruns: 0
buffer target number of samples : 79.38
number of transmitted channels : 8
size of ring buffer : 3
size of usb receive and transmit buffers : 576
currently receiving data : 1
bInterval [uS] : 500
buffered samples (smooth): 78.86

For the video so here is the post on my thread, just to prove that I could run the stereo out without problems, very low latency and CPU consuming. cheers.
 
Last edited:
I've done it also with playing from goldwave to TDM,in your sketch you are not initializing the cs42448,i think that if you want
to hear something you have to do it,maybe you can see a wave in the plotter without having done the initialization,but you have no sound.
 
@AntiLoop: You are right, the cs42448 needs to be initialized. However, this can easily be fixed for sure and I am much more concerned about the problem with the usb input at the moment. I asked @Weiweiweiwear to do use the simple example just to remove the tdm ouput and the cs42448 as sources of the problem.

@Weiweiweiwear: Thank you for the test. That helps a lot at understanding what is going on. There are lots of buffer underruns although 'buffered samples (smooth)' is really close to 'buffer target number of samples'. Also, the Mac never stops sending audio to the Teensy because 'currently receiving data' is always '1'. I will have a look look at the code and think about how that can happen.
You mentioned that it works in stereo. Have you used my code for that? Or the original code? If you tested stereo only with the original Teensy code, can you please test stereo also with my code?
Also, there are two additional options in my example: 'PLOT_BUFFER' and 'PLOT_REQUEST_FRREQ' can you please also run this tests and post the output of the Serial Plotter? If the problem only occurs with 8 channels, then please also stick to 8 channels for this test.
I know, it is maybe cumbersome for you to make all this tests, but I would be glad if you don't give up and help me at improving the code. I just don't have the possibility to reproduce your problem without you.
 
Hi @alex6679
Do you mean just to cut the outputs to two? I did and I still get the same repeated cut-off tone when I send a sine wave from Mac to Teensy.

Code:
#include <Audio.h>
#include <Wire.h>
#include <SPI.h>
#include <SD.h>
#include <SerialFlash.h>

// GUItool: begin automatically generated code
AudioInputUSBOct         usb_oct1;       //xy=348,409
AudioOutputTDM           tdm1;           //xy=671,411
AudioConnection          patchCord1(usb_oct1, 0, tdm1, 0);
AudioConnection          patchCord2(usb_oct1, 1, tdm1, 2);
AudioControlCS42448      cs42448_1;      //xy=369,601
// GUItool: end automatically generated code


void setup() {
  AudioMemory(200);
if (cs42448_1.enable() && cs42448_1.volume(0.8)) {
    Serial.println("configured CS42448_1");
  } else {
    Serial.println("failed to config CS42448_1");
  }}

void loop() {
}

And one thing I found is that I am having heavy CPU load in coreaudiod when I select teensy as output device in Max/msp, and the silence gap in the cut-off stream gets longer alone with the CPU load increasing.


PLOT_BUFFER

Code:
74.00 77.43
59.00 77.36
15.00 102.25
59.00 79.08
69.00 78.90
79.00 78.73
67.00 78.61
77.00 78.43
15.00 122.96
75.00 78.16
59.00 78.33
69.00 78.17
79.00 77.98
64.00 78.12
64.00 78.12


PLOT_REQUEST_FRREQ

Code:
44100.0508
44100.0117
44100.0195
44100.0313
44100.0703
44100.0000
44100.0820
44100.0898
44100.0977
44100.1055
44100.0000
44100.0000
44100.0273
44100.0313
44100.0430
44100.0352
44100.0430
44100.0547
44100.0625
44100.0703
44100.0000
44100.0273
44100.0352
44100.0469


Screenshot 2024-10-05 at 1.30.10 PM copy.jpg
 
When I asked you to make a test in stereo, I meant you should select only two number of channels in the Tools menu as described in the 'In use' section of the README.md and connect only channel 0 and 1 with audio connections in the example code (as you already did in the example above). If you use my example with the plotter, you would need to change patchCordPlotter2 since it connects channel 2 to the plotter.
Can you please also run the PLOT_BUFFER and PLOT_REQUEST_FRREQ tests again? They are meant to be visualized with the Arduino Serial Plotter and your first results that you posted as short sequences of numbers are very difficult to interpret.
 
For those who are curious about Weiweiweiwear's problem: We had a long video call this afternoon/evening and tried to find out what the problem is. Unfortunately we were not successful yet. In the end we compared the original usb input with my version (both in stereo). The original code worked and the new code had the problem that Weiweiweiwear described above.
In the end we decided to take a break and continue next weekend.
 
I'm a bit concerned about the 700% CPU load reported for coreaudiod, and also that it's consumed over 122 days of CPU time. That suggests it might at least be time for a reboot...
 
Back
Top