Teensy 4.0 audio board input from an electric guitar

Hi, I'm making a project using Teensy 4.0 and audioboard. I want to get an input signal from an electric guitar and output the sound to an amp.

I wired the cables like this:


The black cable is the input and the white cable is the output.
And here is my code:

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

// GUItool: begin automatically generated code
AudioInputI2S            i2s1;           //xy=320,325
AudioOutputI2S           i2s2;           //xy=535,324
AudioConnection          patchCord1(i2s1, 0, i2s2, 0);
AudioConnection          patchCord2(i2s1, 1, i2s2, 1);
AudioControlSGTL5000     sgtl5000_1;     //xy=323,403
// GUItool: end automatically generated code



void setup() {
  // put your setup code here, to run once:
  delay(250);
  AudioMemory(10);
  delay(250);

  sgtl5000_1.enable();
  sgtl5000_1.inputSelect(AUDIO_INPUT_LINEIN);
  sgtl5000_1.volume(1);

}

void loop() {
  // put your main code here, to run repeatedly:
  delay(200);
}

I will add other features later including an OLED screen and a rotary encoder but for now, I just want to pass the audio through the teensy. But for some reason, my guitar amp doesn't make any sound. Any solutions?

Guitar pickups are very high impedance devices (which is why they tend to hum, make noise etc.). The SGTL5000 chip has an input impedance of 2.9k or 29k depending on if it's running in line input or mic input mode. The output impedance of your guitar pickup is probably 1~10Meg, so 2-3 orders of magnitude higher than the input impedance of your audio board.
Long story short: I think you need a small pre-amp between your guitar and your Teensy audio module.

Thank you for the information but I am really new to teensy and audio processing so would you explain to me a bit more?
(Also I'm Korean so my English might sound a little rude)

Ok, I'll try to simplify: I think you will need a pre-amplifier between your guitar and your Teensy audio input module. There are modules available for this, probably.

But there might also be very well a problem with your code; I haven't checked it, but one thing that comes to mind is that your audio module can be configured for either a line input (which probably won't work with your guitar) or a microphone input (which may work fine). This should be addressed in the Audio library documentation you use. One thing I did found in a quick search is this function in the SGTL5000 code you're using:

bool AudioControlSGTL5000::micGain(unsigned int dB)

You could fiddle with the mic gain a bit (set it really high) to see if you get a signal that way.

I tried

void setup() {
  // put your setup code here, to run once:
  delay(250);
  AudioMemory(10);
  delay(250);

  sgtl5000_1.enable();
  sgtl5000_1.inputSelect(AUDIO_INPUT_MIC);
  sgtl5000_1.volume(1);
  sgtl5000_1.micGain(100);
}

And

void setup() {
  // put your setup code here, to run once:
  delay(250);
  AudioMemory(10);
  delay(250);

  sgtl5000_1.enable();
  sgtl5000_1.inputSelect(AUDIO_INPUT_LINEIN);
  sgtl5000_1.volume(1);
  sgtl5000_1.lineInLevel(100);
}

but neither of them worked. So I think I will have to use a pre-amp.

Yes, maybe, but there may also be a different problem going on. I don't know for sure; if you can easily get your hands on a pre-amp, it's worth trying it, but I'd expect you would at least get some signal the way you're doing it now.
When debugging audio circuits it's always nice to have access to an oscilloscope so you can visualize the signal in different places.

I've never used a Teensy and I don't know anything about your "audioboard" or the libraries you're using....

If the audioboard has a mic input that should "work" but it's "not correct". The lower impedance on a mic input will "load" the guitar, weakening the signal and altering the tone. But since microphone signals are weaker than guitar signals, the additional gain will will make-up for the weak signal (at least to some extent).

A line input might "work" too. It has higher impedance than a microphone input, but not as high as a guitar input so the guitar is still "loaded". And a line-input has little or no gain.

In the end you'll need a preamp but you may be able to get started without one.

The cheapest/easiest way to get a preamp is with a small mixer. Of course you'll need one with a guitar input.

You can also build a preamp with an op-amp, but make sure you're building one that's designed for guitar (high impedance input). You don't need a lot of gain... Mostly you're "converting" from high impedance to low impedance.

Or just to get started... Instead of using a guitar you can connect the headphone output from your computer or phone (or the output from a CD player, etc.).

Or, some guitar amplifiers have a headphone-output and you can use that, but then you couldn't connect the output of your effects box to the same amplifier.

You should be able to test the output by generating some sounds/signals in software with no input.

And you can read the input and send the results to the serial monitor. ...There is too much data (44,100 samples per second, etc.) and the readings will "look random" so you can't tell much from that raw data but you should be able to determine it there is a signal and the difference between a loud or quiet signal.)

It seems like your main loop should be "doing something". Typically, you need to read-in and audio sample, do some processing (sometimes on multiple samples) and then write-out a sample to the DAC. The input and output have to be at the same sample rate and most audio processing requires a known sample rate (such as 44.1kHz). Maybe Audio.h takes care of that, but I don't know.

No, not needed, the Teensy Audio library handles all this, so long as you create the objects, connect them up and call AudioMemory().

I think you need to set the gain for the SGTL5000 line input to max.

You should get something from the guitar, but the impedance mismatch will lose the high frequencies (quitar inputs are highly inductive, its the inductive reactance that's high, and this is worse at high frequencies).

There's a very active forum at forum.pjrc.com

Nevermind. I did a bunch of hardware stuff and got it to work without a preamp. But thanks for you advice