Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 9 of 9

Thread: Can Teensy 4.0 use TDM and also have a separate stereo input?

  1. #1

    Can Teensy 4.0 use TDM and also have a separate stereo input?

    If the Teensy 4.0 is connected to a CS42448 chip, using the TDM signals to get 48kHz 24-bit audio, how can I get an additional stereo input (also 48kHz) into the system? Are there any additional TDM data input lines available? Is there an I2S bus available? Can I use the S/PDIF input at the same time?

    Thanks in advance!

  2. #2
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    25,022
    Each I2S port can do only 1 protocol, but there are 2 of them. So you could do TDM on I2S1 and stereo I2S on I2S2.

  3. #3
    So, I tried using Teensy 4.0 OUT1/IN1 for I2S audio and OUT2/IN2 for TDM audio and I am having a problem. The TDM port seems to work fine and the I2S output works fine. However, when I try to enable I2S input, it causes the TDM input waveform to be completely wrong. What is going on? I cut down my code to having a simple loopback wire from OUT2 to IN2. Here's my code:

    #include <Arduino.h>
    #include <Audio.h>

    AudioInputI2S i2s_in; // if this is commented out, everything is ok
    AudioOutputI2S i2s_out;
    AudioSynthWaveform waveform1;
    AudioInputTDM2 tdm2_in;
    AudioOutputTDM2 tdm2_out;
    AudioControlSGTL5000 sgtl5000_1;

    // TDM2 OUT2 (pin 2) is wired to TDM2 IN2 (pin 5)
    AudioConnection patchCord1(waveform1, 0, tdm2_out, 0);
    AudioConnection patchCord2(tdm2_in, 0, i2s_out, 0); // left output
    AudioConnection patchCord3(tdm2_in, 0, i2s_out, 1); // right output

    void setup()
    {
    AudioMemory(40);
    pinMode(LED_BUILTIN, OUTPUT);

    sgtl5000_1.enable();
    sgtl5000_1.lineOutLevel(13); //

    waveform1.begin(WAVEFORM_SINE);
    waveform1.frequency(200); // frequency of the sinewave
    waveform1.amplitude(0.05); // turn on the waveform
    }

    void loop()
    {
    digitalWrite(LED_BUILTIN, HIGH); // turn the LED on
    delay(1000);
    digitalWrite(LED_BUILTIN, LOW); // turn the LED off
    delay(1000);
    }

    For this bit of code, I'm using the Teensy Audio Shield (for Teensy 4.0), I'm adding a short jumper wire from pin 2 to pin 5, and then listening to the audio on line out signals. The output sine wave is completely messed up with some big discontinuities. But, if I comment out "AudioInputI2S ", then the sine wave is fine. Any ideas on what could cause this?

  4. #4
    After looking at the discontinuities in the sine wave when AudioInputI2S is uncommented, I notice that they happen every 2.9ms, which is the amount of time in a 128-sample block (i.e. AUDIO_BLOCK_SAMPLES) of 44.1kHz.
    Click image for larger version. 

Name:	tek00000.png 
Views:	38 
Size:	23.9 KB 
ID:	20884

  5. #5
    Ok. I found a way of making it work ok, but I don't understand why it works. I just need to swap the order of AudioInputI2S and AudioOutputI2S in the code above. If I have AudioInputI2S first, the Audio Input on TDM2 will have discontinuities.

    AudioInputI2S i2s_in; // this order is bad
    AudioOutputI2S i2s_out;

    But, if I put AudioOutputI2S first, then TDM2 input works ok.

    AudioOutputI2S i2s_out;
    AudioInputI2S i2s_in; // this order works ok

    Any idea what is going on here?

  6. #6
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    25,022
    Looks like there might be a bug. Can you confirm which version of Teensyduino you're using? In Arduino, click Help > About to check. Or on Macintosh, click Teensyduino > About.

  7. #7
    It says Teensyduino 1.51 and Arduino 1.8.12

  8. #8
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    25,022
    Please install 1.53.

    https://www.pjrc.com/teensy/td_download.html

    Bugs involving cache management were fixed in 1.53, so there's a chance 1.53 may solve all these issues you're seeing. It definitely was doing something similar when PT8211 was used, especially in combination with other features. Might also impact TMD2 with I2S. 1.53 definitely fixed those similar issues people saw with PT8211.

    If not, I'll put this on my list of issues to investigate. Just need you to confirm the problem really does happen with 1.53.

  9. #9
    I tried Teensyduino 1.53 and it didn't make a difference. I still had to put AudioOutputI2S first to avoid making AudioInputTDM2 get weird. Well, as long as I have a workaround, I'm good to go, but it would be good to fix it so that it doesn't bite someone else.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •