Audio
Audio copied to clipboard
input_tdm: every odd channel had every other sample swapped
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:
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:
https://github.com/PaulStoffregen/Audio/pull/428/commits/2021426cbb8233aa946a2d0f9bd0609e2c0e65e6
Here are the results after the fix:
Fixed by #440 which has been merged, so this issue can be closed.