Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

input_tdm: every odd channel had every other sample swapped #429

Open
ccrome opened this issue Dec 22, 2021 · 1 comment
Open

input_tdm: every odd channel had every other sample swapped #429

ccrome opened this issue Dec 22, 2021 · 1 comment

Comments

@ccrome
Copy link
Contributor

ccrome commented Dec 22, 2021

input_tdm: every odd channel had every other sample swapped

The TDM input and TDM2 Input modules have samples swapped on every other frame. So for example, assume the following 6 frames of 16 channels from TDM: The first digits are the channel, the last digit is the frame number:

Here's what's on the TDM bus:

C00 000 001 002 003 004 005
C01 010 011 012 013 014 015
C02 020 021 022 023 024 025
C03 030 031 032 033 034 035
C04 040 041 042 043 044 045
C05 050 051 052 053 054 055
C06 060 061 062 063 064 065
C07 070 071 072 073 074 075
C08 080 081 082 083 084 085
C09 090 091 092 093 094 095
C10 100 101 102 103 104 105
C11 110 111 112 113 114 115
C12 120 121 122 123 124 125
C13 130 131 132 133 134 135
C14 140 141 142 143 144 145
C15 150 151 152 153 154 155

But here's what gets copied into the TDM buffers

C00 000 001 002 003 004 005
C01 011 010 013 012 015 014
C02 020 021 022 023 024 025
C03 031 030 033 032 035 034
C04 040 041 042 043 044 045
C05 051 050 053 052 055 054
C06 060 061 062 063 064 065
C07 071 070 073 072 075 074
C08 080 081 082 083 084 085
C09 091 090 093 092 095 094
C10 100 101 102 103 104 105
C11 111 110 113 112 115 114
C12 120 121 122 123 124 125
C13 131 130 133 132 135 134
C14 140 141 142 143 144 145
C15 151 150 153 152 155 154

Steps To Reproduce Problem

It's pretty easy to reproduce

  • Take a teensy 4.0 or 4.1, and connect pins 7 and 8 together. (i.e. send SAI TX to SAI RX, no audio actual card required)
  • Create a sketch with a TDM object, USB object, and a codec object (the codec object is solely to get the TDM going).
  • connect USB input -> TDM output
  • connect TDM input -> USB output
  • play and record simultaneously on your PC
  • Witness that every other sample of the recorded sample for the right channel is swapped. This is true for all odd TDM channels.

Hardware & Software

  • Teensy 4.0/4.1
  • No shield required
  • Platformio
  • Teensyduino 1.155
  • ubuntu 20.04

Arduino Sketch

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

// GUItool: begin automatically generated code
AudioInputTDM            tdm1;           //xy=125,296.66666412353516
AudioOutputUSB           usb1;           //xy=275.0000228881836,203.6666717529297
AudioInputUSB            usb2;           //xy=401.00001525878906,204.0000057220459
AudioOutputTDM           tdm2;           //xy=568.0000190734863,296.6666717529297
AudioConnection          patchCord1(tdm1, 0, usb1, 0);
AudioConnection          patchCord2(tdm1, 1, usb1, 1);
AudioConnection          patchCord3(usb2, 0, tdm2, 0);
AudioConnection          patchCord4(usb2, 1, tdm2, 1);

// GUItool: end automatically generated code

void setup()
{
    AudioMemory(100);
}

void loop()
{}

Errors or Incorrect Output

You can play and record simulataneously from the host. Samples are swapped on all odd TDM channels as seen in this picture:
image

Top: played out to left and right.
Middle: recorded USB left
Bottom: recorded USB right, with swapped samples.

Bug fixed with pull request

Here's the fix for the problem:

2021426

Here are the results after the fix:
image

h4yn0nnym0u5e added a commit to h4yn0nnym0u5e/Audio that referenced this issue Jun 18, 2022
h4yn0nnym0u5e added a commit to h4yn0nnym0u5e/Audio that referenced this issue Jun 18, 2022
AudioInputTDM[2] input bug fixes issue PaulStoffregen#429
Freeverb bug fixes mono output of AudioEffectFreeverbStereo reported in https://forum.pjrc.com/threads/70334-Possible-bug-in-effect_freeverb-cpp-in-the-current-release-of-Teensyduino-(1-56)

Don't give me the credit, I just followed the instructions and did the PR!
h4yn0nnym0u5e added a commit to h4yn0nnym0u5e/Audio that referenced this issue Feb 19, 2024
Description: PaulStoffregen#429
Fixes: PaulStoffregen#440 (credit to ccrome for the code, of course)
PaulStoffregen pushed a commit that referenced this issue Sep 8, 2024
AudioInputTDM[2] input bug fixes issue #429
Freeverb bug fixes mono output of AudioEffectFreeverbStereo reported in https://forum.pjrc.com/threads/70334-Possible-bug-in-effect_freeverb-cpp-in-the-current-release-of-Teensyduino-(1-56)

Don't give me the credit, I just followed the instructions and did the PR!
@h4yn0nnym0u5e
Copy link
Contributor

Fixed by #440 which has been merged, so this issue can be closed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants