Audio Shield line-out question

robedney

Active member
Using the Teensy pass through sketch example to simplify, I am adjusting the line-out volume from the Audio Shield to an amp. I'm using the sgtl5000_1.lineOutLevel(left,right) command but the range of control, although it works, seems limited (for example I cannot approach zero output). My understanding is that the parameters for left/right are 13 through 31. Please, what am I doing wrong???




CSS:
/*
 * A simple hardware test which receives audio from the audio shield
 * Line-In pins and send it to the Line-Out pins and headphone jack.
 *
 * This example code is in the public domain.
 */

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

// GUItool: begin automatically generated code
AudioInputI2S            i2s1;           //xy=200,69
AudioOutputI2S           i2s2;           //xy=365,94
AudioConnection          patchCord1(i2s1, 0, i2s2, 0);
AudioConnection          patchCord2(i2s1, 1, i2s2, 1);
AudioControlSGTL5000     sgtl5000_1;     //xy=302,184
// GUItool: end automatically generated code


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


void setup() {
  // Audio connections require memory to work.  For more
  // detailed information, see the MemoryAndCpuUsage example
  AudioMemory(12);

  // Enable the audio shield, select input, and enable output
  sgtl5000_1.enable();
  sgtl5000_1.inputSelect(myInput);
  sgtl5000_1.volume(0.5);
   sgtl5000_1.lineOutLevel(31, 31);
}

elapsedMillis volmsec=0;

void loop() {
  // every 50 ms, adjust the volume
  if (volmsec > 50) {
    float vol = analogRead(15);
    vol = vol / 1023.0;
    //audioShield.volume(vol); // <-- uncomment if you have the optional
    volmsec = 0;               //     volume pot on your audio shield
  }
  //lineOutLevel(22, 22);
}
 
Think of the function that you are currently calling as a "gain" setting (determines the maximum possible output). Actual volume should be controlled with the sgtl5000_1.volume() function (see screen capture), which takes a parameter ranging between 0.0 & 1.0. Take note of the "0.8 maximimum without distortion" warning on the level value.

Hope that helps . . .

Mark J Culross

1717710134787.png
 
Thanks for that --however there's a limitation to the volume(level) control in that is effects both left and right channels equally. I'd like control over what I feed to the amp separately per channel. the other issue is that -- from what I've read and tested -- the volume(level) control only effects the headphone jack on the shield and not the audio out pins. More thoughts??? Am I wrong????
 
Doh, sorry. I skipped right over the fact that volume() affects only the headphones. You are 100% correct. So, my next suggestion (hopefully, after a little more thought than the last time) would be to possibly include something like a mixer in each of the L & R signal paths feeding the L & R channels of your I2S output. You would still use the lineOutLevel() as the primary gain setting, but use the individual mixer setting to adjust the fine control level of the L & R signals indepenently (even all the way to 0-level).

Hope that helps (better than the last) . . .

Mark J Culross
KD5RXT
 
dacVolume in the SGTL5000 control object is another option to control the overall volume before output.
 
The sgtl5000 lineOutLevel() functions are meant to adjust the overall signal level. They're not meant to be a volume control which goes down to zero.
 
Back
Top