Got audio compressor code running. Now how do I debug the levels?

Status
Not open for further replies.

Mike5000

Well-known member
I got the audio compressor code from MarkzP running https://github.com/MarkzP/AudioEffectDynamics on my Teensy 3.6 it seems. I am completely new to the Teensy platform.

To install the compressor library I just used the Arduino library manager and installed the zip from the Git archive https://github.com/MarkzP/AudioEffectDynamics/archive/master.zip

Hardware: I run the Teensy 3.6 + Audio Shield Rev. B + the small electret condenser microphone.

Problem: The audio is quite distorted so I need a way to debug the levels, change parameters to the compressor and limiter etc on the fly.

Question 1: How do you normally debug audio levels when you don't have a TFT? Is there some code available that dumps the buffer levels as a value thru the serial port so I can see where there is overflow or too low levels etc?

Question 2: Do you have a proposal for a simple "serial command parser" or something that I can use to do change these parameters via the serial port on the fly?
I was thinking calling compr.gate(threshold, attack, release, ratio, kneeWidth, autoMakeupGain, makeupGain) with new values everytime I send a command.

Alternatively I have a USB MIDI keyboard that probably could be used. However I dont know how to read MIDI values. Apart from the other thread where I saw that it is probably possible to use the second USB port on the Teensy 3.6 for that.


Code:
// COMPRESSOR CODE FROM MARKZP
// https://github.com/MarkzP/AudioEffectDynamics
// There is something strange with the settings / gains it seems
#include <effect_dynamics.h>

// Normal stuff to include
#include <Audio.h>
#include <Wire.h>
#include <SPI.h>
#include <SD.h>
#include <SerialFlash.h>

AudioEffectDynamics compr;               // Instantiate a compressor object
                                         // https://github.com/MarkzP/AudioEffectDynamics

AudioInputI2S            i2s1;            // In obj   
AudioOutputI2S           i2s2;            // Out obj


AudioConnection          patchCord1(i2s1, 0, compr, 0); // inp to compr
AudioConnection          patchCord2(compr, 0, i2s2, 0); // compr to out (L/R headset)
AudioConnection          patchCord3(compr, 0, i2s2, 1); // compr to out (L/R headset)

AudioControlSGTL5000     sgtl5000_1;     // instantiate object for the chip on audio shield

void setup() {
  Serial.begin(9600);
  AudioMemory(8);
  sgtl5000_1.enable();
  sgtl5000_1.volume(0.6);
  sgtl5000_1.inputSelect(AUDIO_INPUT_MIC);  // Use the condenser mic
  sgtl5000_1.micGain(1);

  
  //Sets the gate parameters. Threshold is in dbFS. release is in seconds
  //call like this: void gate(float threshold = -60.0f, float release = 0.02f)
  compr.gate(-60.0f, 0.02f);

  //Sets the compression parameters.
  //threshold, kneeWidth & makeupGain are in db(FS). attack and release are in seconds
  //ratio is expressed as x:1 i.e. 1 for no compression, 60 for brickwall limiting
  //Set kneeWidth to 0 for hard knee
  //If autoMakeupGain is true, makeup will be computed to leave a 6db margin under the limiter threshold.
  //call like this: void compression(float threshold = -35.0f, float attack = 0.005f, float release = 0.2f, float ratio = 45.0f, float kneeWidth = 6.0f, bool autoMakeupGain = true, float makeupGain = 12.0f)
   compr.compression(-35.0f, 0.005f, 0.2f, 45.0f, 6.0f, true, 12.0f);

  //Sets the hard limiter parameters
  //threshold is in dbFS. attack & release are in seconds
  //call like this: void limit(float threshold = -6.0f, float attack = 0.005f, float release = 0.01f)
  compr.limit(-6.0f, 0.005f, 0.01f);
  
   delay(10000);                          // This will cause a reinit approx 10000 secs. Todo: fix later
                                        
}

void loop() {
  // do nothing
}
 
Status
Not open for further replies.
Back
Top