PDA

View Full Version : Question about audio board line in



davidbrai
02-20-2016, 11:20 PM
Hi,

I'm fairly new to connecting audio to the teensy, so sorry for the noobish questions :)

Looking at the teensy audio adaptor board, there's line-in for right and left.

1. I'm assuming the input to that is analog voltage, is that correct?
2. What is the voltage level required for that input?
3. Will connecting the output of a audio jack to that input work? or do I need to amplify the signal?

Thanks!

B.Jacquot
02-23-2016, 01:19 AM
In the order you're asking:

1. Yes, the line in and out are analog voltage.
2. The maximum voltage range is about 3.3V peak to peak.
3. Try it and see. The first stage of amplification is actually within the codec on the audio board - take a look at the "lineInLevel" and "lineOutLevel" methods on the SGTL5000 object.

One trick worth mentioning: the footprint on the audio board matches the one for line I/O on your average PC motherboard. If you can scavenge the line I/O jack piece from an old PC, you can plug it right in.

davidbrai
02-24-2016, 11:37 PM
Thanks a lot, worked perfectly!

PaulStoffregen
02-25-2016, 01:37 AM
Would you believe analog the voltage ranges are actually software programmable?

For details, look in the design tool. Scroll to the end in the left side panal and click on the "sgtl5000" object to make its documentation appear on the right side panel. Then on the right side, scroll to the "Signal Levels" section.

http://www.pjrc.com/teensy/gui/?info=AudioControlSGTL5000

spencoid
02-16-2017, 01:52 AM
i am interested in changing the input level to the sgtl5000 dynamically but if my sketch changes this setting the audio stops working completely. do i need to disable the sgtl5000? there is a function to enable it but none that i see to disable it.

audioShield.lineInLevel(audio_scale);

PaulStoffregen
02-16-2017, 03:39 AM
Maybe it's a bug in your program? Or maybe it's a bug in the audio library.

As a general rule, I do not even begin looking until a complete program to reproduce the problem is posted.

spencoid
02-16-2017, 03:54 AM
Maybe it's a bug in your program? Or maybe it's a bug in the audio library.

As a general rule, I do not even begin looking until a complete program to reproduce the problem is posted.

this is the relevant code block. if this line (audioShield.lineInLevel(audio_scale);) is commented out, the whole program runs fine. it is a rather long complicated sketch. i can try to reduce it to a working minimum if necessary but was hoping that this is enough evidence of the problem.


if (no_three_knob == false){
readEncoder_2 = readEnc2.read();
if (readEncoder_2 != 0){
readEnc2.write(0);
stroke_scale += (readEncoder_2);
stroke_scale = constrain(stroke_scale, 0, 3);
}
if (readEncoder_2 != 0){
readEnc2.write(0);
audio_scale += (readEncoder_2);
audio_scale = constrain(audio_scale, 0, 15);
// audioShield.lineInLevel(); // 0 to 15 5 default sets sensitivity 0 less sensitive 15 more sensitive
audioShield.lineInLevel(audio_scale);
}
}

spencoid
02-16-2017, 04:02 AM
left in a block that was commented out in the original code. i was switching between setting different variables with the same encoder.



if (no_three_knob == false){
readEncoder_2 = readEnc2.read();
if (readEncoder_2 != 0){
readEnc2.write(0);
audio_scale += (readEncoder_2);
audio_scale = constrain(audio_scale, 0, 15);
// audioShield.lineInLevel(); // 0 to 15 5 default sets sensitivity 0 less sensitive 15 more sensitive
audioShield.lineInLevel(audio_scale);
}
}

PaulStoffregen
02-16-2017, 11:23 AM
i can try to reduce it to a working minimum if necessary but was hoping that this is enough evidence of the problem.


Sadly, no it is not enough. If you follow this forum for any length of time, you'll see I do put quite a lot of work into investigating and fixing problems. In this case, I will put a rotary encoder on a breadboard together with a Teensy 3.2 and audio shield. If this really is a bug in a library, I very likely will find and fix it. I might not be able to get to it right away, but I do keep a list of every thread where a reproducible-looking problem is reported.

But something I'm don't do is fill in the missing code with my own guesswork. I've gone down that path many, many times. Almost always it takes a lot of work for zero results. Until a complete program is posted, I don't put a reported problem on my list of issues to investigate.

spencoid
02-16-2017, 05:39 PM
I was just hoping to learn what the LED flickering represents. This can be reproduced with just the sample code for peak detection.

If you want to hook up a stepper or something that displays the step and direction signals, here is the minimal code that produces the jitter. I left the include for encoder because it is essential for my large sketch but commenting this out does not change the jitter so i doubt it is a conflict with the encoder library. this code does not read any encoders just runs the accelstepper in response to mono peaks.



#define ENCODER_DO_NOT_USE_INTERRUPTS
#define ENCODER_OPTIMIZE_INTERRUPTS
//#include <Encoder.h>
#include <EEPROM.h>
#include <AccelStepper.h>

// Audio Stuff
#include <Audio.h>
#include <Wire.h>

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

AudioInputI2S i2s1; //xy=286,128
AudioMixer4 mixer1;
AudioAnalyzePeak peak1; //xy=512,149
AudioAnalyzeRMS rms1;

AudioConnection patchCord1(i2s1, 0, mixer1, 0);
AudioConnection patchCord2(i2s1, 1, mixer1, 1);
AudioConnection patchCord3(mixer1, peak1);
AudioConnection patchCord4(mixer1, rms1);

AudioControlSGTL5000 audioShield;
// end of Audio Stuff

//Encoder readEnc1(5, 6);

AccelStepper stepper(AccelStepper::DRIVER,3,4);

int acceleration;
int readEncoder_1;
int readEncoder_2;
int speed;
long stroke;
float stroke_scale = 1;
elapsedMillis fps;

void setup() {
Serial.begin(57600);
while(!Serial && millis() < 2000 );
Serial.println("begin setup");

AudioMemory(6);
audioShield.enable();
audioShield.lineInLevel(5); // 0 to 15 5 default sets sensitivity 0 less sensitive 15 more sensitive
audioShield.inputSelect(myInput);
audioShield.volume(0);

stepper.setPinsInverted(true,true,true);
stepper.setMinPulseWidth(20);
stepper.setCurrentPosition(0) ;
stepper.setMaxSpeed(30000.0);
stepper.setAcceleration(200000.0);

delay(500); // this is needed for some reason to let voltage stabilize???
// these pins need to be connected between audio board and teensy,
// others hould be left unconnected for this sketch 9,11,13,18,19,22,23 3.3 v gnd

pinMode(3, OUTPUT); // step
pinMode(4, OUTPUT); // direction
// the following are for digital encoder, no pullup required but might be necessary for slave operation???
pinMode(5, INPUT_PULLUP);
pinMode(6, INPUT_PULLUP);

Serial.println("end setup");
}

void loop() {
stepper.run();
uint8_t monoPeak;
uint8_t monoRms;
float stroke_scale_float; // why float? needed in larger sketch
if(fps > 1) {
stepper.run();
fps=0;
if (peak1.available() && rms1.available()) { // need to set up patches etc
fps = 0;
monoPeak = peak1.read() * 600.0;
monoRms = rms1.read() * 600.0;
}
stroke = monoRms * stroke_scale;
Serial.print("stroke ");
Serial.println(stroke);
if (stroke > 70){
stepper.moveTo(stroke);
stepper.run();
}
}
}

spencoid
02-17-2017, 05:06 AM
never mind! i still do not know what the flickering of the LED represents but can live without knowing. i fixed the noise problem by inserting a low pass filter between the mixer and the peak and rms detection. it is totally quiet now when there is no input signal. i don't care much about the high frequency stuff because most beats i want to follow are at lower frequencies.

there may be some sort of bug in the audio library that is causing this high frequency noise or hypersensitivity to it so it might be good to check this out some day but for me it is no longer a priority.




AudioConnection patchCord1(i2s1, 0, mixer1, 0);
AudioConnection patchCord2(i2s1, 1, mixer1, 1);
AudioConnection patchCord3(mixer1, biquad1);
AudioConnection patchCord4(biquad1, peak1);
AudioConnection patchCord5(biquad1, rms1);

int stage = 0;
float frequency = 1000;
float Q = .7071;
biquad1.setLowpass(0, frequency, Q);