Teensy 4 multi-pin TDM

h4yn0nnym0u5e

Well-known member
Hi folks

Well, inspired by this thread (which seems to have stalled with a non-functioning library and no appetite to fix it...), I've had a go myself. This is strictly TDM for the Teensy 4.x only, there's a perfectly good option for multi-channel USB on this other thread, and as Teensy 3.x are no longer manufactured there didn't seem a lot of point adding support for those.

I've striven to make this backward-compatible, and to avoid users having to dig in to the library headers to make changes - everything you need should be available using the (updated) Design Tool.

So ... what do you get? Six new objects to play with, named AudioInputTDMB, AudioInputTDMC, and AudioInputTDMD; and AudioOutputTDMB, AudioOutputTDMC, and AudioOutputTDMD. The output objects use OUT1B through OUT1D to stream data, and the input ones do the same but in reverse order, so AudioInputTDMB actually uses OUT1D. You just have to imagine an A at the end of the existing TDM objects ... I didn't want to create any more than I had to, or break existing code :) Actually, I lied - there's also a PCM3168 control object added (and some TDMAB and TDMCD ones in the Design Tool but not yet implemented ... watch this space, but don't get too excited).

You place these just as you always did the previous TDM objects: they have 16 ports, and you wire only the even-numbered ports if your hardware is 24- or 32-bit (which most of it is). The Design Tool advises you of clashes due to two or more objects using the same OUT1n pin. So you can use AudioInputTDM, AudioInputTDMB, AudioOutputTDM and AudioOutputTDMB together; to that, you could add one of AudioOutputTDMC or AudioInputTDMC. You could use AudioOutputTDM, AudioOutputTDMB, AudioOutputTDMC, and AudioOutputTDMD together with just AudioInputTDM. I'm sure you get the idea...

You must use similar objects in sequence with no gaps - AudioOutputTDM and AudioOutputTDMC together with AudioInputTDM and AudioInputTDMD doesn't have any pin clashes, and it's possible the hardware would allow it, but the code doesn't!

Give yourself plenty of AudioMemory() to work with, these objects are quite greedy.

The updated library is at https://github.com/h4yn0nnym0u5e/Audio/tree/feature/multi-TDM. If you need to cherry-pick files because you've already modified your Audio library, I've changed the following:
  • input_tdm.cpp and .h
  • output_tdm.cpp and .h
  • control_pcm3168.cpp and .h (added)
  • Audio.h
  • keywords.txt
  • gui/index.html
  • gui/img/PCM3168.jpg (added)

Please report any issues on this thread, with a short piece of example code that will compile and run from the Arduino 1.8.19 IDE. At this time I only have CS42448 and PCM3168 hardware to test on, but I do have a decent 'scope so may be able to debug using that.
 
You could potentially use 3.5 CS42448 boards. Teensy 4.1 has 5 data pins on I²S, and 2 on I²S2. By using AudioInputTDM+AudioOutputTDM on one board, AudioInputTDMB+AudioOutputTDMB on another, and AudioInputTDM2+AudioOutputTDM2 on the third, you get 18 inputs and 24 outputs. You still have Audio(In|Out)putTDMC left, so you could half-use a fourth CS42448 for another 6 inputs or 8 outputs.
 
Hi,
if i use 18 inputs and 32 outputs,the maximum you said,what about the audio memory?
I found that if i use 2000 it's too much to compil,and between 1500 and < 2000, it would be alright
but how much audio memory do you suggest?
Does TDM objects leave enough room for audio effects or SdwavPlayer stuff?
 
You should budget for at least 16 blocks per TDM object, they’re quite greedy. Then, as @MarkT says, monitor the actual usage. As written the Audio library caps the block count at 896; I’m not sure why asking for 2000 gives a problem.

Even using the maximum of 7 TDM objects, you’re looking at just over 100 blocks or less than 30k of RAM, so plenty of room for other stuff. The audio I/O uses very little CPU time as most of the work is done by DMA.
 
Some bugfixes pushed up, along with implementing AudioInputTDMAB, AudioInputTDMCD, AudioOutputTDMAB, and AudioOutputTDMCD. The latter objects provide 8 ports, and use two pins at a time with a bit clock of 128fs to in/output 4 audio channels per pin This is needed for the PCM3168's Dual Rate format to achieve 8-channels at 96kHz - see Table 11 and Figure 52 in the data sheet. As yet untested on real hardware, it's getting late!
 
Thank you MarkT, it's a good way to learn on the fly what you really needs time by time,i'll have a look at what you pointed,
is there a pdf file that summerize the usage for teensy,in case of internet blackout? :unsure:

Hey,h4yn...5e, why not give an estimation of how much blocks and RAM memory you use in the teensy audio editor.
The changes you made with TDM ,will they be on the next teensy versions?
i've always made some changes with your first TDM 2xmodules attempt,but do i keep them changes with your new one?
 
That's not a bad idea, to document the block usage. It's not 100% reliable because it will depend to some extent how you use them, but certainly a typical/peak usage estimate would be possible. Ideally it'd be extended to other audio objects, and figuring it out might not be that easy ... some of the code is quite convoluted!

I'd love to see these additions make it to an official Teensyduino release. Paul's made some noises about starting the 1.60 beta, and as soon as I get a bit more testing done, and ideally get some favourable reports from folk like you that it all seems to be working, I'll put in a pull request. After that the ball is definitely in Paul's court, and he's still (as far as I know) down the Ornament and Crime rabbit hole, and then has to decide what he'd like in the next release. I have some PRs that are over two years old, so it really is anyone's guess!

i've always made some changes with your first TDM 2xmodules attempt,but do i keep them changes with your new one?
Not quite sure what you mean here. It's probably best to download the newest version and copy over the same changed files as mentioned in post #1, even if I haven't necessarily changed all of them. You shouldn't need to make any changes to your sketch.

If you've made changes to those files (I suspect you haven't...), then you're on your own :)
 
Some images of my test system in action. A pair of CS42448 PCBAs stacked up and wired to a Teensy 4.1:
IMG_1498.jpg


Modifications made to each board. The one underneath; note
  • zero-ohm link fitted to R20 to route 3.3V to IC1
  • I²C pull-ups fitted at IC1 pins 3 and 7, pulled up to pin 2
  • AD0/1 wired on IC1 pins 8 and 1, to GND at pin 4
  • poor view of clock wiring - see next image!
IMG_1496-annotated.jpg


The one on top. Similar mods but:
  • You can see the wiring to route LRCLK and BCLK to the ADC and DAC together
  • No pull-ups, those are on the other board
  • AD1 is wired to 3.3V, so the address is 0x4A
IMG_1497-annotated.jpg


Test topology:
1723382990725.png


Scope output. Yellow trace is from wav10 (TDMB_O port 14), magenta is wav6 (TDMA_O port 10) wired externally to TDMA_I port 10, and measured at TDMB_O port 10.

SDS00001.png
 
I have replaced the Audio library with your fork library: Audio-feature-multi-TDM
It works ok with TDM and TDM2 :)

Then i Followed what you said:

You could potentially use 3.5 CS42448 boards. Teensy 4.1 has 5 data pins on I²S, and 2 on I²S2. By using AudioInputTDM+AudioOutputTDM on one board, AudioInputTDMB+AudioOutputTDMB on another, and AudioInputTDM2+AudioOutputTDM2 on the third, you get 18 inputs and 24 outputs. You still have Audio(In|Out)putTDMC left, so you could half-use a fourth CS42448 for another 6 inputs or 8 outputs.

And I've made a test with cs42448 X4,here's the snapshot of the editor:

Multi TDM x4.png


But i have errors with compil,i suspect it comes from the TDM objects that are not in red but in black in arduino IDE:

Code:
TEST_16X_GENERATORS_SINEWAVE_TO_16X_STEREO_OUTPUTS_4XCS42448:8: error: 'AudioInputTDMB' does not name a type; did you mean 'AudioInputTDM2'?
    8 | AudioInputTDMB           tdmB2;          //xy=65,446
      | ^~~~~~~~~~~~~~
      | AudioInputTDM2
TEST_16X_GENERATORS_SINEWAVE_TO_16X_STEREO_OUTPUTS_4XCS42448:28: error: 'AudioOutputTDMB' does not name a type; did you mean 'AudioOutputTDM2'?
   28 | AudioOutputTDMB          tdmB1;          //xy=642,454
      | ^~~~~~~~~~~~~~~
      | AudioOutputTDM2
TEST_16X_GENERATORS_SINEWAVE_TO_16X_STEREO_OUTPUTS_4XCS42448:30: error: 'AudioOutputTDMC' does not name a type; did you mean 'AudioOutputTDM2'?
   30 | AudioOutputTDMC          tdmC1;          //xy=653,1086
      | ^~~~~~~~~~~~~~~
      | AudioOutputTDM2
TEST_16X_GENERATORS_SINEWAVE_TO_16X_STEREO_OUTPUTS_4XCS42448:46: error: 'tdmB1' was not declared in this scope; did you mean 'tdm1'?
   46 | AudioConnection          patchCord15(sine5, 0, tdmB1, 0);
      |                                                ^~~~~
      |                                                tdm1
TEST_16X_GENERATORS_SINEWAVE_TO_16X_STEREO_OUTPUTS_4XCS42448:47: error: 'tdmB1' was not declared in this scope; did you mean 'tdm1'?
   47 | AudioConnection          patchCord16(sine5, 0, tdmB1, 2);
      |                                                ^~~~~
      |                                                tdm1
TEST_16X_GENERATORS_SINEWAVE_TO_16X_STEREO_OUTPUTS_4XCS42448:48: error: 'tdmB1' was not declared in this scope; did you mean 'tdm1'?
   48 | AudioConnection          patchCord17(sine6, 0, tdmB1, 4);
      |                                                ^~~~~
      |                                                tdm1
TEST_16X_GENERATORS_SINEWAVE_TO_16X_STEREO_OUTPUTS_4XCS42448:49: error: 'tdmB1' was not declared in this scope; did you mean 'tdm1'?
   49 | AudioConnection          patchCord18(sine6, 0, tdmB1, 6);
      |                                                ^~~~~
      |                                                tdm1
TEST_16X_GENERATORS_SINEWAVE_TO_16X_STEREO_OUTPUTS_4XCS42448:50: error: 'tdmB1' was not declared in this scope; did you mean 'tdm1'?
   50 | AudioConnection          patchCord19(sine7, 0, tdmB1, 8);
      |                                                ^~~~~
      |                                                tdm1
TEST_16X_GENERATORS_SINEWAVE_TO_16X_STEREO_OUTPUTS_4XCS42448:51: error: 'tdmB1' was not declared in this scope; did you mean 'tdm1'?
   51 | AudioConnection          patchCord20(sine7, 0, tdmB1, 10);
      |                                                ^~~~~
      |                                                tdm1
TEST_16X_GENERATORS_SINEWAVE_TO_16X_STEREO_OUTPUTS_4XCS42448:52: error: 'tdmC1' was not declared in this scope; did you mean 'tdm1'?
   52 | AudioConnection          patchCord21(sine13, 0, tdmC1, 0);
      |                                                 ^~~~~
      |                                                 tdm1
TEST_16X_GENERATORS_SINEWAVE_TO_16X_STEREO_OUTPUTS_4XCS42448:53: error: 'tdmC1' was not declared in this scope; did you mean 'tdm1'?
   53 | AudioConnection          patchCord22(sine13, 0, tdmC1, 2);
      |                                                 ^~~~~
      |                                                 tdm1
TEST_16X_GENERATORS_SINEWAVE_TO_16X_STEREO_OUTPUTS_4XCS42448:54: error: 'tdmB1' was not declared in this scope; did you mean 'tdm1'?
   54 | AudioConnection          patchCord23(sine8, 0, tdmB1, 12);
      |                                                ^~~~~
      |                                                tdm1
TEST_16X_GENERATORS_SINEWAVE_TO_16X_STEREO_OUTPUTS_4XCS42448:55: error: 'tdmB1' was not declared in this scope; did you mean 'tdm1'?
   55 | AudioConnection          patchCord24(sine8, 0, tdmB1, 14);
      |                                                ^~~~~
      |                                                tdm1
TEST_16X_GENERATORS_SINEWAVE_TO_16X_STEREO_OUTPUTS_4XCS42448:58: error: 'tdmC1' was not declared in this scope; did you mean 'tdm1'?
   58 | AudioConnection          patchCord27(sine14, 0, tdmC1, 4);
      |                                                 ^~~~~
      |                                                 tdm1
TEST_16X_GENERATORS_SINEWAVE_TO_16X_STEREO_OUTPUTS_4XCS42448:59: error: 'tdmC1' was not declared in this scope; did you mean 'tdm1'?
   59 | AudioConnection          patchCord28(sine14, 0, tdmC1, 6);
      |                                                 ^~~~~
      |                                                 tdm1
TEST_16X_GENERATORS_SINEWAVE_TO_16X_STEREO_OUTPUTS_4XCS42448:60: error: 'tdmC1' was not declared in this scope; did you mean 'tdm1'?
   60 | AudioConnection          patchCord29(sine15, 0, tdmC1, 8);
      |                                                 ^~~~~
      |                                                 tdm1
TEST_16X_GENERATORS_SINEWAVE_TO_16X_STEREO_OUTPUTS_4XCS42448:61: error: 'tdmC1' was not declared in this scope; did you mean 'tdm1'?
   61 | AudioConnection          patchCord30(sine15, 0, tdmC1, 10);
      |                                                 ^~~~~
      |                                                 tdm1
TEST_16X_GENERATORS_SINEWAVE_TO_16X_STEREO_OUTPUTS_4XCS42448:62: error: 'tdmC1' was not declared in this scope; did you mean 'tdm1'?
   62 | AudioConnection          patchCord31(sine16, 0, tdmC1, 12);
      |                                                 ^~~~~
      |                                                 tdm1
TEST_16X_GENERATORS_SINEWAVE_TO_16X_STEREO_OUTPUTS_4XCS42448:63: error: 'tdmC1' was not declared in this scope; did you mean 'tdm1'?
   63 | AudioConnection          patchCord32(sine16, 0, tdmC1, 14);
      |                                                 ^~~~~
      |                                                 tdm1
 
That looks very much as if you haven't managed to replace the Audio library with my modified one. Turn on verbose compilation output, and look at which library is in use - for example:
1723389894002.png

You can see I have multiple Audio libraries, but the stock one in hardware\teensy\avr\libraries\Audio has not been used, and the one in D:\swd\git!dynamic\libraries\Audio has (note that's in my personalised libraries in the default sketchbook location).

The key errors shown in your post are the first three, where the new TDM objects "do not name a type" - all the other errors are just consequences of that, and I'd expect them to go away once the library location is sorted out.
 
Guess you found it:

Code:
Using library Audio at version 1.3 in folder: C:\Program Files (x86)\Arduino\hardware\teensy\avr\libraries\Audio

I pulled off this Audio lib and now it compiles right.
You made a good job with your stacked up cs42448,but how do you sandwich them together?
 
Great news.

The stacked CS42448 are a bit flimsy at the moment! I soldered some pins underneath the CN1 single-inline connector, to mate with the I²S and power, and then a couple of pieces of wire between the two CN3 Master Control connectors, for SCL and SDA. I'll put some pillars in at some point, and maybe see if I can put in a 2-pin header/socket for the I²C, so it's easier to take apart.

You'll note I have two yellow and two green wires coming off the Teensy - those are the TDM out and in signals. OUT1B and OUT1D go to unused pins on the bottom CS42448 PCBA, and the top stacked board gets its data to/from those, because I offset those pins one step on the back of the board.
 
I encouter problems with the input of tdmB, wired it to pin 6,
If i rely the input to the output of tdmB in the editor, i hear a bad sound,like a bad sinewave,if it's not relied in the editor the sound is quiet
and if i only rely a generator to the output in the editor ,the sound is ok.
 
Not sure I understand this - can you post a your code, and an indication of which patchcord you leave out to stop the "bad sinewave", please?
 
TDM multi forum.jpg

This is my all designing,all works exept the input of tdmB1,in this example if i select any of the imput,i have
the bad noise.
 
Are you sure you have the data I/O pins wired correctly? MCLK_OUT, LRCLK_DO and BCLK_DO are common to both boards, but one should have SD_OUT0 and SD_IN0 wired to Teensy pins 7 and 8, and the other to pins 32 and 6.

(Not sure you need those amplifier objects, the mixers can have a gain >1.0)
 
I use a different wiring for TDM1 & TDM2,i've made a summary here,coming from the editor infos,something wrong?:
Edit; yes they have the same wiring,exept for inputs and outputs

TDM - MULTI - INFOS.jpg
 
That's correct, except of course that the Design Tool makes it hard to distinguish TDM, TDMB, TDMC and TDMD (on SAI1) from TDM2 (on SAI2). You can tell in your summary, from the pins used for the TDM clocks.

Your post #18 looks correct, but the code I asked for would be unambiguous.
 
Ok,let's put hands in the engine...

Code:
                                                                                                                                                                                                                     //0x38  (RA8875,FT6206,MAX98390)
#include <Audio.h>
#include <Wire.h>
#include <SPI.h>
#include <SD.h>
#include <SerialFlash.h>
#include <RA8875.h>
#include <Adafruit_FT6206.h>




Adafruit_FT6206 ts = Adafruit_FT6206();


#define RA8875_CS         36
#define RA8875_RESET      40                
#define RA8875_INT        41



RA8875 tft = RA8875(RA8875_CS, RA8875_RESET);



// GUItool: begin automatically generated code
AudioInputTDMB           tdmB1;          //xy=120,2290
AudioInputTDM            tdm1;           //xy=158,1989
AudioPlaySdWav           playSdWav1;     //xy=171,1750
AudioAmplifier           amp3;           //xy=301,1910
AudioAmplifier           amp2;           //xy=303,1847
AudioAmplifier           amp4;           //xy=303,1951
AudioAmplifier           amp11;          //xy=303,2230
AudioAmplifier           amp1;           //xy=305,1807
AudioAmplifier           amp5;           //xy=306,2003
AudioAmplifier           amp10;          //xy=306,2195
AudioAmplifier           amp12;          //xy=307,2273
AudioAmplifier           amp13;          //xy=308,2312
AudioAmplifier           amp15;          //xy=308,2391
AudioAmplifier           amp14;          //xy=311,2353
AudioAmplifier           amp6;           //xy=313,2052
AudioAmplifier           amp8;           //xy=347,1737
AudioAmplifier           amp9;           //xy=348,1770
AudioSynthWaveformSine   sine1;          //xy=458,2043
AudioSynthWaveformSine   sine2;          //xy=487,2403
AudioMixer4              mixer5;         //xy=523,2193
AudioMixer4              mixer6;         //xy=525,2265
AudioMixer4              mixer1;         //xy=530,1785
AudioMixer4              mixer2;         //xy=531,1866
AudioAmplifier           amp7;           //xy=531,1951
AudioAmplifier           amp16;          //xy=561,2348
AudioMixer4              mixer7;         //xy=675,2199
AudioMixer4              mixer8;         //xy=680,2262
AudioMixer4              mixer3;         //xy=688,1856
AudioMixer4              mixer4;         //xy=692,1925
AudioOutputTDM           tdm2;           //xy=825,1991
AudioOutputTDMB          tdmB2;          //xy=862,2285

AudioConnection          patchCord1(tdmB1, 0, amp10, 0);
AudioConnection          patchCord2(tdmB1, 2, amp11, 0);
AudioConnection          patchCord3(tdmB1, 4, amp12, 0);
AudioConnection          patchCord4(tdmB1, 6, amp13, 0);
AudioConnection          patchCord5(tdmB1, 8, amp14, 0);
AudioConnection          patchCord6(tdmB1, 10, amp15, 0);
AudioConnection          patchCord7(tdm1, 0, amp1, 0);
AudioConnection          patchCord8(tdm1, 2, amp2, 0);
AudioConnection          patchCord9(tdm1, 4, amp3, 0);
AudioConnection          patchCord10(tdm1, 6, amp4, 0);
AudioConnection          patchCord11(tdm1, 8, amp5, 0);
AudioConnection          patchCord12(tdm1, 10, amp6, 0);
AudioConnection          patchCord13(playSdWav1, 0, amp8, 0);
AudioConnection          patchCord14(playSdWav1, 1, amp9, 0);
AudioConnection          patchCord15(amp3, 0, mixer1, 1);
AudioConnection          patchCord16(amp2, 0, mixer2, 0);
AudioConnection          patchCord17(amp4, 0, mixer2, 1);
AudioConnection          patchCord18(amp11, 0, mixer6, 0);
AudioConnection          patchCord19(amp1, 0, mixer1, 0);
AudioConnection          patchCord20(amp5, 0, mixer1, 2);
AudioConnection          patchCord21(amp10, 0, mixer5, 0);
AudioConnection          patchCord22(amp12, 0, mixer5, 1);
AudioConnection          patchCord23(amp13, 0, mixer6, 1);
AudioConnection          patchCord24(amp15, 0, mixer6, 2);
AudioConnection          patchCord25(amp14, 0, mixer5, 2);
AudioConnection          patchCord26(amp6, 0, mixer2, 2);
AudioConnection          patchCord27(amp8, 0, mixer1, 3);
AudioConnection          patchCord28(amp9, 0, mixer2, 3);
AudioConnection          patchCord29(sine1, amp7);
AudioConnection          patchCord30(sine2, amp16);
AudioConnection          patchCord31(mixer5, 0, mixer7, 0);
AudioConnection          patchCord32(mixer6, 0, mixer8, 0);
AudioConnection          patchCord33(mixer1, 0, mixer3, 0);
AudioConnection          patchCord34(mixer2, 0, mixer4, 0);
AudioConnection          patchCord35(amp7, 0, mixer3, 1);
AudioConnection          patchCord36(amp7, 0, mixer4, 1);
AudioConnection          patchCord37(amp16, 0, mixer7, 1);
AudioConnection          patchCord38(amp16, 0, mixer8, 1);
AudioConnection          patchCord39(mixer7, 0, tdmB2, 0);
AudioConnection          patchCord40(mixer8, 0, tdmB2, 2);
AudioConnection          patchCord41(mixer3, 0, tdm2, 0);
AudioConnection          patchCord42(mixer4, 0, tdm2, 2);

AudioControlCS42448      cs42448_2;      //xy=512,2481
AudioControlCS42448      cs42448_1;      //xy=533,2091
// GUItool: end automatically generated code





bool sinetouch = 0;
float vol_sine = 3.0;
float vol_sd = 1.0;
float vol_line1 = 1.0;


void setup() {
 
  Serial.begin(38400);

  

  Wire.begin();
 

cs42448_1.setAddress(0x48);
cs42448_1.enable();
 
cs42448_2.setAddress(0x4A);
cs42448_2.enable();


  //  begin display: Choose from: RA8875_480x272, RA8875_800x480, RA8875_800x480ALT, Adafruit_480x272, Adafruit_800x480
  tft.begin(RA8875_800x480);

 

 

   if (!ts.begin(40)) {
    Serial.println("Unable to start touchscreen.");
  }
  else {
    Serial.println("Touchscreen started.");
  }
 
   tft.setRotation(0);
  tft.fillWindow(RA8875_BLUE);//fill window black
  
  tft.setFontScale(1);
    
 
  AudioMemory(1000);

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

cs42448_1.inputLevel(1.0);//very sensible !!
cs42448_2.inputLevel(1.0);
 
   sine1.frequency(1200);
   sine1.amplitude(0.3);

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

  
//--------AMPS TDM1-----------
amp1.gain(0);
amp2.gain(0);

amp3.gain(0);
amp4.gain(0);

amp5.gain(0);
amp6.gain(0);

amp7.gain(0);

amp8.gain(0);
amp9.gain(0);
//--------AMPS TDM2-----------
amp10.gain(0);
amp11.gain(0);

amp12.gain(0);
amp13.gain(0);

amp14.gain(0);
amp15.gain(0);

amp16.gain(0);

//---------MIXERS TDM1-----------
  mixer1.gain(0,3.0);
  mixer1.gain(1,3.0);
  mixer1.gain(2,3.0);
  mixer1.gain(3,vol_sd);

  mixer2.gain(0,3.0);
  mixer2.gain(1,3.0);
  mixer2.gain(2,3.0);
  mixer2.gain(3,vol_sd);

  mixer3.gain(0,3.0);
  mixer3.gain(1,vol_sine);
  mixer3.gain(2,0.0);
  mixer3.gain(3,0.0);

  mixer4.gain(0,3.0);
  mixer4.gain(1,vol_sine);
  mixer4.gain(2,0.0);
  mixer4.gain(3,0.0);
//----------MIXERS TDM2-----------
  mixer5.gain(0,3.0);
  mixer5.gain(1,3.0);
  mixer5.gain(2,3.0);
  mixer5.gain(3,0.0);

  mixer6.gain(0,3.0);
  mixer6.gain(0,3.0);
  mixer6.gain(2,3.0);
  mixer6.gain(3,0.0);

  mixer7.gain(0,3.0);
  mixer7.gain(1,vol_sine);
  mixer7.gain(2,0.0);
  mixer7.gain(3,0.0);

  mixer8.gain(0,3.0);
  mixer8.gain(1,vol_sine);
  mixer8.gain(2,0.0);
  mixer8.gain(3,0.0);


        
 

  Serial.print("Initializing SD card...");
  bool ok;
  const int chipSelect = 38;
 
  SPI1.setMISO(39);  
  SPI1.begin();

  /
  ok = SD.sdfs.begin(SdSpiConfig(chipSelect, SHARED_SPI, SD_SCK_MHZ(16), &SPI1));

 if (!ok) {
    Serial.println("initialization failed!");
    return;
  }
  Serial.println("initialization done.");
 
}

boolean wastouched = true;
elapsedMillis msecs;

void loop() {

 
 
  boolean istouched = ts.touched();
 
  if (istouched) {
    TS_Point p = ts.getPoint();

    // rotate coordinate system
    // flip it around to match the screen.
    p.x = map(p.x, 0, 800,0,800);
    p.y = map(p.y, 0, 480, 480,0);
    

    int y = tft.height() - p.y;   
    int x = p.x;
    
    if (!wastouched) {
      tft.fillWindow(RA8875_BLACK);//fill window black
      tft.setTextColor(RA8875_YELLOW);
      
      tft.setCursor(700, 360);
      tft.print("Touch");
    }
    tft.fillRect(680, 390, 140, 60, RA8875_BLACK);
    tft.setTextColor(RA8875_GREEN);
    //tft.setFont(Arial_24);
    tft.setCursor(680, 390);
    tft.print("X = ");
    tft.print(p.x);
    tft.setCursor(680, 420);
    tft.print("Y = ");
    tft.print(p.y);
    Serial.print(", x = ");
    
    Serial.print(", y = ");
    

//-------------INPUT: LINE 1--------------
 
    if(p.x>=0 && p.x<=110 && p.y>=370 && p.y<=480)
    {Serial.print("LINE1");
    playSdWav1.stop();
    amp1.gain(1);amp2.gain(1);
    amp10.gain(1);amp11.gain(1);   
    
    amp3.gain(0);amp4.gain(0);
    amp5.gain(0);amp6.gain(0);   
    amp7.gain(0);
    amp8.gain(0);amp9.gain(0);

    amp12.gain(0);amp13.gain(0);
    amp14.gain(0);amp15.gain(0);
    amp16.gain(0);
 
    }
    
//-----------VOL LINE 1----------------
    if(p.x>=0 && p.x<=110 && p.y>=270 && p.y<=380)
    {
      Serial.print("LINE1 VOL+");
      
      vol_line1 += 0.2;
      amp1.gain(vol_line1);amp2.gain(vol_line1);
      amp10.gain(vol_line1);amp11.gain(vol_line1);
     
    }
    
    if(p.x>=0 && p.x<=110 && p.y>=170 && p.y<=280 && vol_line1 >= 0.1)
    {
      Serial.print("LINE1 VOL-");
      
      
      vol_line1 -= 0.2;
      amp1.gain(vol_line1);amp2.gain(vol_line1);
      amp10.gain(vol_line1);amp11.gain(vol_line1);   
     //mixer1.gain(3,vol_line1);mixer2.gain(3,vol_line1);
    }

//--------------INPUT: LINE 2---------------       
    if(p.x>=110 && p.x<=210 && p.y>=370 && p.y<=480)
    {Serial.print("LINE2");
    playSdWav1.stop();
    amp3.gain(1);amp4.gain(1);
    amp12.gain(1);amp13.gain(1);   
    
    amp1.gain(0);amp2.gain(0);
    amp5.gain(0);amp6.gain(0);   
    amp7.gain(0);
    amp8.gain(0);amp9.gain(0);

    amp10.gain(0);amp11.gain(0);
    amp14.gain(0);amp15.gain(0);
    amp16.gain(0);
 
     }
      
//--------------INPUT: LINE 3---------------   
    if(p.x>=210 && p.x<=310 && p.y>=370 && p.y<=480)
    {Serial.print("LINE3");
    playSdWav1.stop();
    amp5.gain(1);amp6.gain(1);
    amp14.gain(1);amp15.gain(1);   
    
    amp1.gain(0);amp2.gain(0);
    amp3.gain(0);amp4.gain(0);   
    amp7.gain(0);
    amp8.gain(0);amp9.gain(0);

    amp10.gain(0);amp11.gain(0);
    amp12.gain(0);amp13.gain(0);
    amp16.gain(0);
    
    }

//------------TEST SINE-----------
    if(p.x>=310 && p.x<=410 && p.y>=370 && p.y<=480 && sinetouch == 0 )
    {Serial.print("SINE");
    amp8.gain(1);amp9.gain(1);   
        
    amp1.gain(0);amp2.gain(0);
    amp3.gain(0);amp4.gain(0);
    amp5.gain(0);amp6.gain(0); 
        
    amp10.gain(0);amp11.gain(0);
    amp12.gain(0);amp13.gain(0);
    amp14.gain(0);amp15.gain(0);
    
    sinetouch = 1;
    amp7.gain(1);
    amp16.gain(1);
    
        
        
    }
     else{
      sinetouch = 0;
      amp7.gain(0);
      amp16.gain(0);
      
      }
      
//------------VOL TEST SINE-------------
if(p.x>=310 && p.x<=410 && p.y>=270 && p.y<=380)
    {
      Serial.print("SINE VOL+");
      amp7.gain(1);amp16.gain(1);
      vol_sine += 0.2;
     mixer3.gain(1,vol_sine);mixer4.gain(1,vol_sine);
     mixer7.gain(1,vol_sine);mixer8.gain(1,vol_sine);
    }
    
if(p.x>=310 && p.x<=410 && p.y>=170 && p.y<=280 && vol_sine >= 0.5)
    {
      Serial.print("SINE VOL-");
      
      amp7.gain(1);amp10.gain(1);
      vol_sine -= 0.2;   
     mixer3.gain(1,vol_sine);mixer4.gain(1,vol_sine);
     mixer7.gain(1,vol_sine);mixer8.gain(1,vol_sine);
    }

//-------------PLAYER SD CARD------------       
    if(p.x>=410 && p.x<=510 && p.y>=370 && p.y<=480)
    {Serial.print("SD1");
    amp8.gain(1);amp9.gain(1);   
        
    amp1.gain(0);amp2.gain(0);
    amp3.gain(0);amp4.gain(0);
    amp5.gain(0);amp6.gain(0);   
    amp7.gain(0);
    
    amp10.gain(0);amp11.gain(0);
    amp12.gain(0);amp13.gain(0);
    amp14.gain(0);amp15.gain(0);
    amp16.gain(0);
    
    playSdWav1.play("sdtest1.wav");
    }
    
    if(p.x>=510 && p.x<=610 && p.y>=370 && p.y<=480)
    {Serial.print("SD2");
    amp8.gain(1);amp9.gain(1);   
        
    amp1.gain(0);amp2.gain(0);
    amp3.gain(0);amp4.gain(0);
    amp5.gain(0);amp6.gain(0);   
    amp7.gain(0);
    
    amp10.gain(0);amp11.gain(0);
    amp12.gain(0);amp13.gain(0);
    amp14.gain(0);amp15.gain(0);
    amp16.gain(0);
    
    playSdWav1.play("sdtest2.wav");   
    }
    
    if(p.x>=610 && p.x<=710 && p.y>=370 && p.y<=480)
    {Serial.print("STOP");
    playSdWav1.stop();
    }
    
//-------------VOL PLAYER SD CARD------------
if(p.x>=610 && p.x<=710 && p.y>=270 && p.y<=380)
    {
      Serial.print("SD VOL+");
      
      vol_sd += 0.2;
     mixer1.gain(3,vol_sd);mixer2.gain(3,vol_sd);
    }
    
if(p.x>=610 && p.x<=710 && p.y>=170 && p.y<=280 && vol_sd >= 0.1)
    {
      Serial.print("SD VOL-");
      
      //amp8.gain(1);amp9.gain(1);
      vol_sd -= 0.2;   
     mixer1.gain(3,vol_sd);mixer2.gain(3,vol_sd);
    }


    
    }

    
  else {
    if (wastouched) {
      tft.fillWindow(RA8875_BLACK);//fill window black   
//-------------"INPUTS" BUTTONS--------------   
      tft.fillRect(0,0,100,100,RA8875_BLUE);//
      tft.fillRect(100,0,100,100,RA8875_BLUE);//
      tft.fillRect(200,0,100,100,RA8875_BLUE);//
      tft.fillRect(300,0,100,100,RA8875_GREEN);//
      tft.fillRect(400,0,100,100,RA8875_LIGHT_ORANGE );//
      tft.fillRect(500,0,100,100,RA8875_LIGHT_ORANGE);//
      tft.fillRect(600,0,100,100,RA8875_RED);//

      
//------------------"VOLUME +" BUTTONS----------------
      tft.fillRect(0,100,100,100,RA8875_BLUE);//
      tft.fillRect(100,100,100,100,RA8875_BLUE);//
      tft.fillRect(200,100,100,100,RA8875_BLUE);//
      tft.fillRect(300,100,100,100,RA8875_GREEN);//
      tft.fillRect(400,100,100,100,RA8875_LIGHT_ORANGE );//
      tft.fillRect(500,100,100,100,RA8875_LIGHT_ORANGE);//
      tft.fillRect(600,100,100,100,RA8875_RED);//

//---------------"VOLUME -" BUTTONS     
      tft.fillRect(0,200,100,100,RA8875_BLUE);//
      tft.fillRect(100,200,100,100,RA8875_BLUE);//
      tft.fillRect(200,200,100,100,RA8875_BLUE);//
      tft.fillRect(300,200,100,100,RA8875_GREEN);//
      tft.fillRect(400,200,100,100,RA8875_LIGHT_ORANGE );//
      tft.fillRect(500,200,100,100,RA8875_LIGHT_ORANGE);//
      tft.fillRect(600,200,100,100,RA8875_RED);//     
    
      
      tft.setTextColor(RA8875_WHITE);
      //tft.setFont(Arial_18);
      
      tft.setCursor(10, 35);tft.print("LINE1");     
      tft.setCursor(10, 135);tft.print("VOL+");     
      tft.setCursor(10, 235);tft.print("VOL-");     


      tft.setCursor(110, 35);tft.print("LINE2");
      tft.setCursor(110, 135);tft.print("VOL+");     
      tft.setCursor(110, 235);tft.print("VOL-"); 

      tft.setCursor(210, 35);tft.print("LINE3");
      tft.setCursor(210, 135);tft.print("VOL+");     
      tft.setCursor(210, 235);tft.print("VOL-");

      tft.setCursor(310, 35);tft.print("SINE");
      tft.setCursor(310, 135);tft.print("VOL+");     
      tft.setCursor(310, 235);tft.print("VOL-");

      tft.setCursor(425, 35);tft.print("SD1");
      

      tft.setCursor(525, 35);tft.print("SD2");
      

      tft.setCursor(615, 35);tft.print("STOP");
      tft.setCursor(610, 135);tft.print("VOL+");     
      tft.setCursor(610, 235);tft.print("VOL-");
      

      

      
    }
    Serial.println("no touch");
  }
  wastouched = istouched;
  delay(100);
}
 
Great thanks. Could you try something for me - swap the order of the TDM input objects, like this:
C++:
// GUItool: begin automatically generated code
AudioInputTDM            tdm1;           //xy=158,1989
AudioInputTDMB           tdmB1;          //xy=120,2290
AudioPlaySdWav           playSdWav1;     //xy=171,1750
AudioAmplifier           amp3;           //xy=301,1910
It shouldn't matter, but I did have a few problems getting the TDM hardware (re-)initialisation code to work, and it may be that it's still not right.

If that's successful, then you have a workaround for the time being, and I have a bug to fix :eek:
 
Well,the bad sinewave is gone but a big blowing is present :)
Line1: big blowing,line2: a less bigger blowing,line3: a bad sinewavel,but i can't hear the music from my ipod i put in the input
 
OK, I've just tested on my hardware and as far as I can tell everything works as expected.
  • I had to comment out all your display-related code, because I haven't got one
  • SD card initialisation fails, because I haven't got one
  • I set amp7.gain(0.5) to enable a sine wave output on tdm2 outputs 1 and 2, and ...
  • ...set amp10. and amp11.gain(0.1) to pass through tdmB1 inputs 1 and 2 to tdmB2 outputs 1 and 2, ...and
  • ...physically wired tdm2 out 1+2 to tdmB1 in 1+2
The code as tested is thus:
C++:
/*
 * See https://forum.pjrc.com/index.php?threads/teensy-4-multi-pin-tdm.75577/post-348599
 * Needs multi-TDM update
 */
#include <Audio.h>
#include <Wire.h>
#include <SPI.h>
#include <SD.h>
#include <SerialFlash.h>
//#include <RA8875.h>
//#include <Adafruit_FT6206.h>




//Adafruit_FT6206 ts = Adafruit_FT6206();


#define RA8875_CS         36
#define RA8875_RESET      40               
#define RA8875_INT        41



//RA8875 tft = RA8875(RA8875_CS, RA8875_RESET);



// GUItool: begin automatically generated code
AudioInputTDMB           tdmB1;          //xy=120,2290
AudioInputTDM            tdm1;           //xy=158,1989
AudioPlaySdWav           playSdWav1;     //xy=171,1750
AudioAmplifier           amp3;           //xy=301,1910
AudioAmplifier           amp2;           //xy=303,1847
AudioAmplifier           amp4;           //xy=303,1951
AudioAmplifier           amp11;          //xy=303,2230
AudioAmplifier           amp1;           //xy=305,1807
AudioAmplifier           amp5;           //xy=306,2003
AudioAmplifier           amp10;          //xy=306,2195
AudioAmplifier           amp12;          //xy=307,2273
AudioAmplifier           amp13;          //xy=308,2312
AudioAmplifier           amp15;          //xy=308,2391
AudioAmplifier           amp14;          //xy=311,2353
AudioAmplifier           amp6;           //xy=313,2052
AudioAmplifier           amp8;           //xy=347,1737
AudioAmplifier           amp9;           //xy=348,1770
AudioSynthWaveformSine   sine1;          //xy=458,2043
AudioSynthWaveformSine   sine2;          //xy=487,2403
AudioMixer4              mixer5;         //xy=523,2193
AudioMixer4              mixer6;         //xy=525,2265
AudioMixer4              mixer1;         //xy=530,1785
AudioMixer4              mixer2;         //xy=531,1866
AudioAmplifier           amp7;           //xy=531,1951
AudioAmplifier           amp16;          //xy=561,2348
AudioMixer4              mixer7;         //xy=675,2199
AudioMixer4              mixer8;         //xy=680,2262
AudioMixer4              mixer3;         //xy=688,1856
AudioMixer4              mixer4;         //xy=692,1925
AudioOutputTDM           tdm2;           //xy=825,1991
AudioOutputTDMB          tdmB2;          //xy=862,2285

AudioConnection          patchCord1(tdmB1, 0, amp10, 0);
AudioConnection          patchCord2(tdmB1, 2, amp11, 0);
AudioConnection          patchCord3(tdmB1, 4, amp12, 0);
AudioConnection          patchCord4(tdmB1, 6, amp13, 0);
AudioConnection          patchCord5(tdmB1, 8, amp14, 0);
AudioConnection          patchCord6(tdmB1, 10, amp15, 0);
AudioConnection          patchCord7(tdm1, 0, amp1, 0);
AudioConnection          patchCord8(tdm1, 2, amp2, 0);
AudioConnection          patchCord9(tdm1, 4, amp3, 0);
AudioConnection          patchCord10(tdm1, 6, amp4, 0);
AudioConnection          patchCord11(tdm1, 8, amp5, 0);
AudioConnection          patchCord12(tdm1, 10, amp6, 0);
AudioConnection          patchCord13(playSdWav1, 0, amp8, 0);
AudioConnection          patchCord14(playSdWav1, 1, amp9, 0);
AudioConnection          patchCord15(amp3, 0, mixer1, 1);
AudioConnection          patchCord16(amp2, 0, mixer2, 0);
AudioConnection          patchCord17(amp4, 0, mixer2, 1);
AudioConnection          patchCord18(amp11, 0, mixer6, 0);
AudioConnection          patchCord19(amp1, 0, mixer1, 0);
AudioConnection          patchCord20(amp5, 0, mixer1, 2);
AudioConnection          patchCord21(amp10, 0, mixer5, 0);
AudioConnection          patchCord22(amp12, 0, mixer5, 1);
AudioConnection          patchCord23(amp13, 0, mixer6, 1);
AudioConnection          patchCord24(amp15, 0, mixer6, 2);
AudioConnection          patchCord25(amp14, 0, mixer5, 2);
AudioConnection          patchCord26(amp6, 0, mixer2, 2);
AudioConnection          patchCord27(amp8, 0, mixer1, 3);
AudioConnection          patchCord28(amp9, 0, mixer2, 3);
AudioConnection          patchCord29(sine1, amp7);
AudioConnection          patchCord30(sine2, amp16);
AudioConnection          patchCord31(mixer5, 0, mixer7, 0);
AudioConnection          patchCord32(mixer6, 0, mixer8, 0);
AudioConnection          patchCord33(mixer1, 0, mixer3, 0);
AudioConnection          patchCord34(mixer2, 0, mixer4, 0);
AudioConnection          patchCord35(amp7, 0, mixer3, 1);
AudioConnection          patchCord36(amp7, 0, mixer4, 1);
AudioConnection          patchCord37(amp16, 0, mixer7, 1);
AudioConnection          patchCord38(amp16, 0, mixer8, 1);
AudioConnection          patchCord39(mixer7, 0, tdmB2, 0);
AudioConnection          patchCord40(mixer8, 0, tdmB2, 2);
AudioConnection          patchCord41(mixer3, 0, tdm2, 0);
AudioConnection          patchCord42(mixer4, 0, tdm2, 2);

AudioControlCS42448      cs42448_2;      //xy=512,2481
AudioControlCS42448      cs42448_1;      //xy=533,2091
// GUItool: end automatically generated code





bool sinetouch = 0;
float vol_sine = 3.0;
float vol_sd = 1.0;
float vol_line1 = 1.0;


void setup() {
  //while (!Serial) ; // JRO
 
  Serial.begin(38400);

 

  Wire.begin();
 

cs42448_1.setAddress(0x48);
cs42448_1.enable();
 
cs42448_2.setAddress(0x4A);
cs42448_2.enable();


  //  begin display: Choose from: RA8875_480x272, RA8875_800x480, RA8875_800x480ALT, Adafruit_480x272, Adafruit_800x480
  //tft.begin(RA8875_800x480);

 

 
/*
   if (!ts.begin(40)) {
    Serial.println("Unable to start touchscreen.");
  }
  else {
    Serial.println("Touchscreen started.");
  }
 
   tft.setRotation(0);
  tft.fillWindow(RA8875_BLUE);//fill window black
 
  tft.setFontScale(1);
*/   
 
  AudioMemory(1000);

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

cs42448_1.inputLevel(1.0);//very sensible !!
cs42448_2.inputLevel(1.0);
 
   sine1.frequency(1200);
   sine1.amplitude(0.3);

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

 
//--------AMPS TDM1-----------
amp1.gain(0);
amp2.gain(0);

amp3.gain(0);
amp4.gain(0);

amp5.gain(0);
amp6.gain(0);

amp7.gain(0.5f); // JRO

amp8.gain(0);
amp9.gain(0);
//--------AMPS TDM2-----------
amp10.gain(0.1f); // JRO
amp11.gain(0.1f); // JRO

amp12.gain(0);
amp13.gain(0);

amp14.gain(0);
amp15.gain(0);

amp16.gain(0);

//---------MIXERS TDM1-----------
  mixer1.gain(0,3.0);
  mixer1.gain(1,3.0);
  mixer1.gain(2,3.0);
  mixer1.gain(3,vol_sd);

  mixer2.gain(0,3.0);
  mixer2.gain(1,3.0);
  mixer2.gain(2,3.0);
  mixer2.gain(3,vol_sd);

  mixer3.gain(0,3.0);
  mixer3.gain(1,vol_sine);
  mixer3.gain(2,0.0);
  mixer3.gain(3,0.0);

  mixer4.gain(0,3.0);
  mixer4.gain(1,vol_sine);
  mixer4.gain(2,0.0);
  mixer4.gain(3,0.0);
//----------MIXERS TDM2-----------
  mixer5.gain(0,3.0);
  mixer5.gain(1,3.0);
  mixer5.gain(2,3.0);
  mixer5.gain(3,0.0);

  mixer6.gain(0,3.0);
  mixer6.gain(0,3.0);
  mixer6.gain(2,3.0);
  mixer6.gain(3,0.0);

  mixer7.gain(0,3.0);
  mixer7.gain(1,vol_sine);
  mixer7.gain(2,0.0);
  mixer7.gain(3,0.0);

  mixer8.gain(0,3.0);
  mixer8.gain(1,vol_sine);
  mixer8.gain(2,0.0);
  mixer8.gain(3,0.0);


        
 

  Serial.print("Initializing SD card...");
  bool ok;
  const int chipSelect = 38;
 
  SPI1.setMISO(39); 
  SPI1.begin();

 
  ok = SD.sdfs.begin(SdSpiConfig(chipSelect, SHARED_SPI, SD_SCK_MHZ(16), &SPI1));

 if (!ok) {
    Serial.println("initialization failed!");
    return;
  }
  Serial.println("initialization done.");
 
}

boolean wastouched = true;
elapsedMillis msecs;

void loop() {

 
 
  boolean istouched = 0; // ts.touched();
 
  if (istouched) {
  /*
    TS_Point p = ts.getPoint();

    // rotate coordinate system
    // flip it around to match the screen.
    p.x = map(p.x, 0, 800,0,800);
    p.y = map(p.y, 0, 480, 480,0);
    

    int y = tft.height() - p.y;   
    int x = p.x;
    
    if (!wastouched) {
      tft.fillWindow(RA8875_BLACK);//fill window black
      tft.setTextColor(RA8875_YELLOW);
      
      tft.setCursor(700, 360);
      tft.print("Touch");
    }
    tft.fillRect(680, 390, 140, 60, RA8875_BLACK);
    tft.setTextColor(RA8875_GREEN);
    //tft.setFont(Arial_24);
    tft.setCursor(680, 390);
    tft.print("X = ");
    tft.print(p.x);
    tft.setCursor(680, 420);
    tft.print("Y = ");
    tft.print(p.y);
    Serial.print(", x = ");
    
    Serial.print(", y = ");
    

//-------------INPUT: LINE 1--------------
 
    if(p.x>=0 && p.x<=110 && p.y>=370 && p.y<=480)
    {Serial.print("LINE1");
    playSdWav1.stop();
    amp1.gain(1);amp2.gain(1);
    amp10.gain(1);amp11.gain(1);   
    
    amp3.gain(0);amp4.gain(0);
    amp5.gain(0);amp6.gain(0);   
    amp7.gain(0);
    amp8.gain(0);amp9.gain(0);

    amp12.gain(0);amp13.gain(0);
    amp14.gain(0);amp15.gain(0);
    amp16.gain(0);
 
    }
    
//-----------VOL LINE 1----------------
    if(p.x>=0 && p.x<=110 && p.y>=270 && p.y<=380)
    {
      Serial.print("LINE1 VOL+");
      
      vol_line1 += 0.2;
      amp1.gain(vol_line1);amp2.gain(vol_line1);
      amp10.gain(vol_line1);amp11.gain(vol_line1);
    
    }
    
    if(p.x>=0 && p.x<=110 && p.y>=170 && p.y<=280 && vol_line1 >= 0.1)
    {
      Serial.print("LINE1 VOL-");
      
      
      vol_line1 -= 0.2;
      amp1.gain(vol_line1);amp2.gain(vol_line1);
      amp10.gain(vol_line1);amp11.gain(vol_line1);   
     //mixer1.gain(3,vol_line1);mixer2.gain(3,vol_line1);
    }

//--------------INPUT: LINE 2---------------       
    if(p.x>=110 && p.x<=210 && p.y>=370 && p.y<=480)
    {Serial.print("LINE2");
    playSdWav1.stop();
    amp3.gain(1);amp4.gain(1);
    amp12.gain(1);amp13.gain(1);   
    
    amp1.gain(0);amp2.gain(0);
    amp5.gain(0);amp6.gain(0);   
    amp7.gain(0);
    amp8.gain(0);amp9.gain(0);

    amp10.gain(0);amp11.gain(0);
    amp14.gain(0);amp15.gain(0);
    amp16.gain(0);
 
     }
      
//--------------INPUT: LINE 3---------------   
    if(p.x>=210 && p.x<=310 && p.y>=370 && p.y<=480)
    {Serial.print("LINE3");
    playSdWav1.stop();
    amp5.gain(1);amp6.gain(1);
    amp14.gain(1);amp15.gain(1);   
    
    amp1.gain(0);amp2.gain(0);
    amp3.gain(0);amp4.gain(0);   
    amp7.gain(0);
    amp8.gain(0);amp9.gain(0);

    amp10.gain(0);amp11.gain(0);
    amp12.gain(0);amp13.gain(0);
    amp16.gain(0);
    
    }

//------------TEST SINE-----------
    if(p.x>=310 && p.x<=410 && p.y>=370 && p.y<=480 && sinetouch == 0 )
    {Serial.print("SINE");
    amp8.gain(1);amp9.gain(1);   
        
    amp1.gain(0);amp2.gain(0);
    amp3.gain(0);amp4.gain(0);
    amp5.gain(0);amp6.gain(0);
        
    amp10.gain(0);amp11.gain(0);
    amp12.gain(0);amp13.gain(0);
    amp14.gain(0);amp15.gain(0);
    
    sinetouch = 1;
    amp7.gain(1);
    amp16.gain(1);
    
        
        
    }
     else{
      sinetouch = 0;
      amp7.gain(0);
      amp16.gain(0);
      
      }
      
//------------VOL TEST SINE-------------
if(p.x>=310 && p.x<=410 && p.y>=270 && p.y<=380)
    {
      Serial.print("SINE VOL+");
      amp7.gain(1);amp16.gain(1);
      vol_sine += 0.2;
     mixer3.gain(1,vol_sine);mixer4.gain(1,vol_sine);
     mixer7.gain(1,vol_sine);mixer8.gain(1,vol_sine);
    }
    
if(p.x>=310 && p.x<=410 && p.y>=170 && p.y<=280 && vol_sine >= 0.5)
    {
      Serial.print("SINE VOL-");
      
      amp7.gain(1);amp10.gain(1);
      vol_sine -= 0.2;   
     mixer3.gain(1,vol_sine);mixer4.gain(1,vol_sine);
     mixer7.gain(1,vol_sine);mixer8.gain(1,vol_sine);
    }

//-------------PLAYER SD CARD------------       
    if(p.x>=410 && p.x<=510 && p.y>=370 && p.y<=480)
    {Serial.print("SD1");
    amp8.gain(1);amp9.gain(1);   
        
    amp1.gain(0);amp2.gain(0);
    amp3.gain(0);amp4.gain(0);
    amp5.gain(0);amp6.gain(0);   
    amp7.gain(0);
    
    amp10.gain(0);amp11.gain(0);
    amp12.gain(0);amp13.gain(0);
    amp14.gain(0);amp15.gain(0);
    amp16.gain(0);
    
    playSdWav1.play("sdtest1.wav");
    }
    
    if(p.x>=510 && p.x<=610 && p.y>=370 && p.y<=480)
    {Serial.print("SD2");
    amp8.gain(1);amp9.gain(1);   
        
    amp1.gain(0);amp2.gain(0);
    amp3.gain(0);amp4.gain(0);
    amp5.gain(0);amp6.gain(0);   
    amp7.gain(0);
    
    amp10.gain(0);amp11.gain(0);
    amp12.gain(0);amp13.gain(0);
    amp14.gain(0);amp15.gain(0);
    amp16.gain(0);
    
    playSdWav1.play("sdtest2.wav");   
    }
    
    if(p.x>=610 && p.x<=710 && p.y>=370 && p.y<=480)
    {Serial.print("STOP");
    playSdWav1.stop();
    }
    
//-------------VOL PLAYER SD CARD------------
if(p.x>=610 && p.x<=710 && p.y>=270 && p.y<=380)
    {
      Serial.print("SD VOL+");
      
      vol_sd += 0.2;
     mixer1.gain(3,vol_sd);mixer2.gain(3,vol_sd);
    }
    
if(p.x>=610 && p.x<=710 && p.y>=170 && p.y<=280 && vol_sd >= 0.1)
    {
      Serial.print("SD VOL-");
      
      //amp8.gain(1);amp9.gain(1);
      vol_sd -= 0.2;   
     mixer1.gain(3,vol_sd);mixer2.gain(3,vol_sd);
    }


*/   
    }

    
  else {
    if (wastouched) {
/*     
      tft.fillWindow(RA8875_BLACK);//fill window black   
//-------------"INPUTS" BUTTONS--------------   
      tft.fillRect(0,0,100,100,RA8875_BLUE);//
      tft.fillRect(100,0,100,100,RA8875_BLUE);//
      tft.fillRect(200,0,100,100,RA8875_BLUE);//
      tft.fillRect(300,0,100,100,RA8875_GREEN);//
      tft.fillRect(400,0,100,100,RA8875_LIGHT_ORANGE );//
      tft.fillRect(500,0,100,100,RA8875_LIGHT_ORANGE);//
      tft.fillRect(600,0,100,100,RA8875_RED);//

      
//------------------"VOLUME +" BUTTONS----------------
      tft.fillRect(0,100,100,100,RA8875_BLUE);//
      tft.fillRect(100,100,100,100,RA8875_BLUE);//
      tft.fillRect(200,100,100,100,RA8875_BLUE);//
      tft.fillRect(300,100,100,100,RA8875_GREEN);//
      tft.fillRect(400,100,100,100,RA8875_LIGHT_ORANGE );//
      tft.fillRect(500,100,100,100,RA8875_LIGHT_ORANGE);//
      tft.fillRect(600,100,100,100,RA8875_RED);//

//---------------"VOLUME -" BUTTONS     
      tft.fillRect(0,200,100,100,RA8875_BLUE);//
      tft.fillRect(100,200,100,100,RA8875_BLUE);//
      tft.fillRect(200,200,100,100,RA8875_BLUE);//
      tft.fillRect(300,200,100,100,RA8875_GREEN);//
      tft.fillRect(400,200,100,100,RA8875_LIGHT_ORANGE );//
      tft.fillRect(500,200,100,100,RA8875_LIGHT_ORANGE);//
      tft.fillRect(600,200,100,100,RA8875_RED);//     
    
      
      tft.setTextColor(RA8875_WHITE);
      //tft.setFont(Arial_18);
      
      tft.setCursor(10, 35);tft.print("LINE1");     
      tft.setCursor(10, 135);tft.print("VOL+");     
      tft.setCursor(10, 235);tft.print("VOL-");     


      tft.setCursor(110, 35);tft.print("LINE2");
      tft.setCursor(110, 135);tft.print("VOL+");     
      tft.setCursor(110, 235);tft.print("VOL-");

      tft.setCursor(210, 35);tft.print("LINE3");
      tft.setCursor(210, 135);tft.print("VOL+");     
      tft.setCursor(210, 235);tft.print("VOL-");

      tft.setCursor(310, 35);tft.print("SINE");
      tft.setCursor(310, 135);tft.print("VOL+");     
      tft.setCursor(310, 235);tft.print("VOL-");

      tft.setCursor(425, 35);tft.print("SD1");
      

      tft.setCursor(525, 35);tft.print("SD2");
      

      tft.setCursor(615, 35);tft.print("STOP");
      tft.setCursor(610, 135);tft.print("VOL+");     
      tft.setCursor(610, 235);tft.print("VOL-");
      

      

*/     
    }
  
    Serial.println("no touch");
  }
  wastouched = istouched;
  delay(100);
}
This gives me a reasonable-looking 1.2kHz test tone output.

I notice you have a lot of mixers with their gains set to 3.0 - obviously this will give horrible distortion if the sum is greater than 1.0. In fact, because the mixing is very poorly done (see this issue on github, which pretty much as expected has been ignored for over two years; I'd do a PR, but that would be ignored, too), the distortion can be much nastier than you'd imagine.

Please give this code and wiring a try and see if it works for you. If so, maybe the display is doing something weird (seems unlikely...), or as noted the mixer gains are too high - easy to test. If not, I'd suspect the CS42448 boards' wiring.
 
Back
Top