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

Thread: I2S audio clipping

  1. #1
    Junior Member
    Join Date
    Mar 2019
    Posts
    5

    I2S audio clipping

    Hi everyone! I have searched high and low and simply cannot figure out how to fix this problem. My ultimate goal is to run FFT on I2S audio input from a BC127 Bluetooth module. I am able to get Teensy to accept the I2S input, but the output appears to have clipping (I'm not sure if that's the right term, distortion on lower-range sounds).

    My setup is wired thus:

    • BC127 OUT/MOSI -> Teensy 3.6 Pin 13
    • BC127 CLK/CLK -> Teensy 3.6 Pin 9
    • BC127 SYNC/CS -> Teensy 3.6 Pin 23
    • BC127 SPI/PCM -> Teensy 3.6 Pin 33 (written low to select PCM/I2S mode over SPI)


    Please note that this setup does not use an audio shield, though I did try on another Teensy 3.6 with an audio shield and the results were the same.

    I have also tried the following combinations with the following results:

    • BC127 Analog out: undistorted
    • BC127 I2S out: undistorted
    • Teensy 3.6 Guitar sample I2S out: undistorted
    • Teensy 3.6 Guitar sample DAC out: undistorted


    Given that the BC127 appears to be producing undistorted audio and that the Teensy is capable of producing undistorted audio via I2S and DAC outputs, it seems like something is happening when the BC127 passes the I2S signal through the Teensy.

    Code:
    Code:
    #include <Audio.h>
    #include <Wire.h>
    #include <SPI.h>
    #include <SD.h>
    #include <SerialFlash.h>
    
    // GUItool: begin automatically generated code
    AudioInputI2S            i2s1;           //xy=289,390
    AudioMixer4              mixer1;         //xy=491,409
    AudioOutputAnalogStereo  dacs1;          //xy=654,403
    AudioConnection          patchCord1(i2s1, 0, mixer1, 0);
    AudioConnection          patchCord2(i2s1, 1, mixer1, 1);
    AudioConnection          patchCord3(mixer1, 0, dacs1, 0);
    AudioConnection          patchCord4(mixer1, 0, dacs1, 1);
    // GUItool: end automatically generated code
    
    
    void setup() {
    
      pinMode(33, OUTPUT);
      digitalWrite(33, LOW);
      
      // Audio connections require memory to work.  For more
      // detailed information, see the MemoryAndCpuUsage example
      AudioMemory(12);
      mixer1.gain(0, 0.15);
      mixer1.gain(1, 0.15);
      mixer1.gain(2, 0);
      mixer1.gain(3, 0);
    }
    
    void loop() {
    }
    I tried to include photos of the setup and a sound clip of what I'm talking about, but they were all rejected for some reason. I want to emphasize that I'm not sure that "clipping" is the right description, but there's distortion that sounds like it's too loud when there is a low/bass tone, though the mid- and high-ranges seem to come through well.

    I'm running on Windows 7 64-bit and running Teensyduino v1.42.

    This is the final step in a long project so I look forward to any help you're able to offer! Thank you very much in advance!

    Edit: I should note that when I say I can get undistorted I2S from the BC127, it seems to require me to hold the amp at a particular angle to the BC127. If I don't, the audio becomes severely distorted or cuts out entirely. However, when the BC127 is feeding audio to Teensy, I can move them relative to each other while the signal is still strong except for the problematic distortion.
    Last edited by steve9211; 03-19-2019 at 02:34 AM. Reason: Forgot to include possibly diagnostically relevant information

  2. #2
    Senior Member
    Join Date
    Jul 2014
    Posts
    2,187
    Quote Originally Posted by steve9211 View Post
    I tried to include photos of the setup and a sound clip of what I'm talking about, but they were all rejected for some reason. I want to emphasize that I'm not sure that "clipping" is the right description, but there's distortion that sounds like it's too loud when there is a low/bass tone, though the mid- and high-ranges seem to come through well.
    Granted that clipping is an analog term and not applicable to digital signals (I2S), the most likely reason why you could get corrupt data into and from teensy is bad or too long connection.
    Indeed a photo would help.

  3. #3
    Junior Member
    Join Date
    Mar 2019
    Posts
    5
    I tried Firefox and Chrome, but I just can't seem to upload anything. Here is a link to the setup:

    https://www.dropbox.com/s/o9zws9jug1...72848.jpg?dl=0

    Here is a closer-up view of the wiring and connections:

    https://www.dropbox.com/s/ocd2wmf3ez...74138.jpg?dl=0

    The white wires that connect the BC127 and Teensy are about 30 mm long.

  4. #4
    Junior Member
    Join Date
    Mar 2019
    Posts
    5
    And actually, here is a link to a sound sample of the distortion:

    https://www.dropbox.com/s/z8o9mhme9y...12-26.wav?dl=0

  5. #5
    Junior Member
    Join Date
    Mar 2019
    Posts
    5
    If anyone is working on this, thank you very much, but I ended up implementing a workaround. I ran one analog output from the BC127 to the Teensy's input for the FFT and split the other analog output for the speakers. It's not as elegant as I would like, but it seems to work as I would want it to!

    If anyone has any input, I would still very much like to figure out how to use I2S if for no other reason but curiosity! However, I can't argue that there's a pressing need to know at the moment.

  6. #6
    Senior Member
    Join Date
    Feb 2017
    Posts
    285
    I wasn't able to quickly find a complete BC127 datasheet online. Perhaps you could attach one? So, as just a guess, I'd propose that the device is either set up for the wrong data format (PCM vs I2s) and/or the wrong mode (Master vs Slave).

    EDIT:
    And, is it operating at the proper clock rate: Bit Clock = 64 * Fs?
    Last edited by gfvalvo; 03-22-2019 at 04:49 PM.

  7. #7
    Junior Member
    Join Date
    Mar 2019
    Posts
    5
    That's a good question about the clock. I can only assume that it is correct because I set Teensy as the I2S master and the BC127 as the I2S slave. What's strange is that the distortion seems to be only associated with either volume or pitch because the distortion happens during bass hits. Otherwise it is undistorted, so I would think that it would either work entirely or not at all if it were a clock issue.

    For reference, there are a couple of data sheets floating around:



    None of them list clock information as far as I can tell.

Posting Permissions

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