Audio/led noise / distortion

Status
Not open for further replies.

Bugilt

New member
I'm getting a ton of distortion/noise from what seems to be spi. Here is a audio file from the headphone jack on the audio shield. https://dl.dropboxusercontent.com/u/32253157/Noisey.wma

The wiring is a 3.5mm plug wired to the audio input l/r on the audio shield. The teensy 3.1/3.2 is powered by battery 4.2v. The lights aren't connected for trouble shooting.

original source: https://github.com/2xAA/Audio-Light-Tube

I've edited the code from above to work with the audio shield.

Code:
#include <Audio.h>
#include <Wire.h>
#include <SPI.h>
#include <SD.h>
#include <SerialFlash.h>
#include <Adafruit_NeoPixel.h>


#define NEOPIN          0
#define NUMPIXELS      144

Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUMPIXELS, NEOPIN, NEO_GRB + NEO_KHZ400);

const int myInput = AUDIO_INPUT_LINEIN;
// const int myInput = AUDIO_INPUT_MIC;

// GUItool: begin automatically generated code
AudioInputI2S            i2s1;           //xy=290,327
AudioMixer4              mixer1;         //xy=510,359
AudioOutputI2S           i2s2;           //xy=701,459
AudioAnalyzeRMS          rms1;           //xy=735,363
AudioAnalyzePeak         peak1;          //xy=739,294
AudioAnalyzeFFT256       fft256_1;       //xy=742,329
AudioConnection          patchCord1(i2s1, 0, mixer1, 0);
AudioConnection          patchCord2(i2s1, 1, mixer1, 1);
AudioConnection          patchCord3(mixer1, rms1);
AudioConnection          patchCord4(mixer1, peak1);
AudioConnection          patchCord5(mixer1, 0, i2s2, 0);
AudioConnection          patchCord6(mixer1, fft256_1);
// GUItool: end automatically generated code

AudioControlSGTL5000 audioShield;

int rgbColour[3];
int mode = 0; //default mode
int modes = 6; //num modes

const int buttonPin = 2;     // button pin
int buttonState = 0;         // current state of the button
int lastButtonState = 0;     // previous state of the button
bool pressed = false;

int MAXBRIGHTNESS = 25;

void setup() {
  
  AudioMemory(6);
  audioShield.enable();
  audioShield.inputSelect(myInput);
  audioShield.volume(10);
  
  pinMode(buttonPin, INPUT);

  AudioMemory(16);
  Serial.begin(9600);
  pixels.begin();
  pixels.setBrightness(255); // 0-255
  
  // Start off with red.
  rgbColour[0] = 150;
  rgbColour[1] = 75;
  rgbColour[2] = 25; 
}

elapsedMillis fps;
float floatPeak = 0;
int monoPeak = 0;
int maxPeak = 0;
bool initialised = false;
float rmsValue = 0.0;

float mapfloat(float x, float in_min, float in_max, float out_min, float out_max) {
 return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
}

void loop() { 

  // read the pushbutton input pin:
  buttonState = digitalRead(buttonPin);
  
  
  // compare the buttonState to its previous state
  if (buttonState != lastButtonState) {
    // if the state has changed, increment the counter
    if (buttonState == HIGH && pressed == false) {
      
      // if the current state is HIGH then the button
      // wend from off to on:
      if(mode+1 < modes) mode++;
      else mode = 0;
      pressed = true;
      
      // clear the strip
      for(int i = 0; i < NUMPIXELS; i++) {
        pixels.setPixelColor(i, pixels.Color(0, 0, 0));
      }
      pixels.show();
    }
    
  }

  if(buttonState == LOW) {
    pressed = false;
  }
  
  if (fps > 24 || initialised) {
    if (peak1.available()) {
      initialised = true;
      
      floatPeak = peak1.read() * 30.0;
      monoPeak = floatPeak;
      if(maxPeak < monoPeak) maxPeak = monoPeak;
      if(mode == 0) vuMeter();
    }

    if(rms1.available()) {
      rmsValue = rms1.read();
    }

    
    if(mode == 1) fftBlink();
    if(mode == 2) rms();
    if(mode == 3) chaseStrobe();
  }
  
  if(mode == 4) strobe();
  if(mode == 5) multiStrobe();
}

I've done the following:
remove the leds
different teensy and audio shield
different pins for the led data
 
Last edited:
Status
Not open for further replies.
Back
Top