Control the SGTL5000 chip on the audio shield. SGTL5000 is always used in slave mode, where Teensy controls all I2S timing.
This object has no audio inputs or outputs. Separate i2s objects are used to send and receive audio data. I2S master mode objects must be used, because this object configures the SGTL5000 in slave mode, where it depends on Teensy to provide all I2S clocks. This object controls how the SGTL5000 will use those I2S audio streams.
These are the most commonly used SGTL5000 functions.
enable();
Start the SGTL5000. This function should be called first.
volume(level);
Set the headphone volume level. Range is 0 to 1.0, but 0.8 corresponds to the maximum undistorted output for a full scale signal. Usually 0.5 is a comfortable listening level. The line level outputs are not changed by this function.
inputSelect(input);
Select which input to use: AUDIO_INPUT_LINEIN or AUDIO_INPUT_MIC.
micGain(dB);
When using the microphone input, set the amplifier gain. The input number is in decibels, from 0 to 63.
The default signal levels should be used for most applications, but these functions allow you to customize the analog signals.
muteHeadphone();
Silence the headphone output.
unmuteHeadphone();
Turn the headphone output on.
muteLineout();
Silence the line level outputs.
unmuteLineout();
Turn the line level outputs on.
lineInLevel(both);
Adjust the sensitivity of the line-level inputs. Fifteen settings are possible:
0: 3.12 Volts p-p 1: 2.63 Volts p-p 2: 2.22 Volts p-p 3: 1.87 Volts p-p 4: 1.58 Volts p-p 5: 1.33 Volts p-p (default) 6: 1.11 Volts p-p 7: 0.94 Volts p-p 8: 0.79 Volts p-p 9: 0.67 Volts p-p 10: 0.56 Volts p-p 11: 0.48 Volts p-p 12: 0.40 Volts p-p 13: 0.34 Volts p-p 14: 0.29 Volts p-p 15: 0.24 Volts p-p
lineInLevel(left, right);
Adjust the sensitivity of the line-level inputs, with different settings for left and right. The same 15 settings are available.
lineOutLevel(both);
Adjust the line level output voltage range. The following settings are possible:
13: 3.16 Volts p-p 14: 2.98 Volts p-p 15: 2.83 Volts p-p 16: 2.67 Volts p-p 17: 2.53 Volts p-p 18: 2.39 Volts p-p 19: 2.26 Volts p-p 20: 2.14 Volts p-p 21: 2.02 Volts p-p 22: 1.91 Volts p-p 23: 1.80 Volts p-p 24: 1.71 Volts p-p 25: 1.62 Volts p-p 26: 1.53 Volts p-p 27: 1.44 Volts p-p 28: 1.37 Volts p-p 29: 1.29 Volts p-p (default) 30: 1.22 Volts p-p 31: 1.16 Volts p-p
lineOutLevel(left, right);
Adjust the line level outout voltage range, with separate settings for left and right. The same settings (13 to 31) are available.
Usually these digital signal conditioning features should be left at their default settings.
adcHighPassFilterFreeze();
By default, the analog input (either line-level inputs or mic) is high-pass filtered, to remove any DC component. This function freezes the filter, so the current DC component is still substracted, but the filter stops tracking any DC or low frequency changes.
adcHighPassFilterDisable();
Completely disable the analog input filter. DC and sub-audible low frequencies are allowed to enter the digital signal.
adcHighPassFilterEnable();
Turn the DC-blocking filter back on, if disabled, or allows it to resume tracking DC and low frequency changes, if previously frozen. This is the default setting.
dacVolume(both);
Normally output volume should be used with volume(), which changes the analog gain in the headphone amplifier. This function on the other hand controls digital attenuation before conversion to analog, which reduces resolution, but allows another fine control of output signal level. The ranges is 0 to 1.0, with the default (no digital attenuation) at 1.0.
dacVolume uses zero-crossing detect to avoid clicks, and ramping is handled by the chip so that a new volume may be set directly in a single call.
dacVolume(left, right);
Adjust the digital output volume separately on left and right channels.
The optional digital audio processor is capable of implementing one or more of: automatic volume control, surround sound control, bass enhancement, and tonal adjustments (either a simple tone control, or a parametric equalizer, or a graphic equalizer), in that order.
These signal processing features are implemented in the SGTL5000 chip, so they do not consume CPU time on Teensy. However, the order of these processes is fixed in the hardware.
It is good practice to mute the outputs before enabling or disabling the Audio Processor, to avoid clicks or thumps.
audioPreProcessorEnable();
Enable the audio processor to pre-process the input (from either line-level inputs or microphone) before it's sent to Teensy by I2S.
audioPostProcessorEnable();
Enable the audio processor to post-process Teensy's I2S output before it's turned into analog signals for the headphones and/or line level outputs.
audioProcessorDisable();
Disable the audio processor.
autoVolumeControl(maxGain, response, hardLimit, threshold, attack, decay);
Configures the auto volume control, which is implemented as a compressor/expander or hard limiter. maxGain is the maximum gain that can be applied for expanding, and can take one of three values: 0 (0dB), 1 (6.0dB) and 2 (12dB). Values greater than 2 are treated as 2. response controls the integration time for the compressor and can take four values: 0 (0ms), 1 (25ms), 2 (50ms) or 3 (100ms). Larger values average the volume over a longer time, allowing short-term peaks through.
If hardLimit is 0, a 'soft knee' compressor is used to progressively compress louder values which are near to or above the threashold (the louder they are, the greater the compression). If it is 1, a hard compressor is used (all values above the threashold are the same loudness). The threashold is specified as a float in the range 0dBFS to -96dBFS, where -18dBFS is a typical value. attack is a float controlling the rate of decrease in gain when the signal is over threashold, in dB/s. decay controls how fast gain is restored once the level drops below threashold, again in dB/s. It is typically set to a longer value than attack.
autoVolumeEnable();
Enables auto volume control, using the previously specified settings.
autoVolumeDisable();
Disables auto volume control.
surroundSoundEnable();
Enable virtual surround processing, to give a broader and deeper stereo image (even with mono input).
surroundSoundDisable();
Disable virtual surround processing. Before disabling, ramp up the width to maximum to avoid pops.
surroundSound(width);
Configures virtual surround width from 0 (mono) to 7 (widest).
surroundSound(width, select);
Configures virtual surround width from 0 (mono) to 7 (widest). select may be set to 1 (disable), 2 (mono input) or 3 (stereo input).
enhanceBassEnable();
Enable bass enhancement. A mono, low-pass filtered copy of the original stereo signal has bass levels boosted and is then mixed back into the stereo signal, which is then optionally high pass filtered (to remove inaudible subsonic frequencies).
enhanceBassDisable();
Disable bass enhancement. Before disabling, ramp down the bass enhancement level to zero.
enhanceBass(lr_lev, bass_lev);
Configures the bass enhancement by setting the levels of the original stereo signal and the bass-enhanced mono level which will be mixed together. There is no high-pass filter.
When changing bass level, call this function repeatedly to ramp up or down the bass in steps of 0.5dB, to avoid pops.
enhanceBass(lr_lev, bass_lev, hpf_bypass, cutoff);
Configures the bass enhancement by setting the levels of the original stereo signal and the bass-enhanced mono level which will be mixed together. The high-pass filter may be enabled (0) or bypassed (1). The cutoff frequency is specified as follows:
value frequency 0 80Hz 1 100Hz 2 125Hz 3 150Hz 4 175Hz 5 200Hz 6 225Hz
When changing bass level, call this function repeatedly to ramp up or down the bass in steps of 0.5dB, to avoid pops.
eqSelect(n);
Selects the type of frequency control, where n is one of
FLAT_FREQUENCY (0)
Equalizers and tone controls disabled, flat frequency response.
PARAMETRIC_EQUALIZER (1)
Enables the 7-band parametric equalizer, thus disabling the
tone controls and graphic equalizer.
TONE_CONTROLS (2)
Enables bass and treble tone controls, disabling the parametric
equalization and graphic equalizer.
GRAPHIC_EQUALIZER (3)
Enables the five-band graphic equalizer, disabling the parametric
equalization and tone controls.
eqBands(bass, treble);
Configures bass and treble tone controls, which are implemented as one second order low pass filter (bass) in parallel with one second order high pass filter (treble).
When changing bass or treble level, call this function repeatedly to ramp up or down the level in steps of 0.04 (=0.5dB) or so, to avoid pops.
eqBands(bass, mid_bass, midrange, mid_treble, treble);
Configures the graphic equalizer. It is implemented by five parallel, second order biquad filters with fixed frequencies of 115Hz, 330Hz, 990Hz, 3kHz, and 9.9kHz. Each band has a range of adjustment from 1.00 (+12dB) to -1.00 (-11.75dB).
eqBand(bandNum, n);
Configures the gain or cut on one band in the graphic equalizer. bandnum can range from 1 to 5; n is a float in the range 1.00 to -1.00.
When changing a band, call this function repeatedly to ramp up the gain in steps of 0.5dB, to avoid pops.
eqFilter(filterNum, filterParameters);
Configurs the parametric equalizer. The number of filters (1 to 7) is specified along with a pointer to an array of filter coefficients. The parametric equalizer is implemented using 7 cascaded, second order bi-quad filters whose frequencies, gain, and Q may be freely configured, but each filter can only be specified as a set of filter coefficients.
eqFilterCount(n);
Enables zero or more of the already enabled parametric filters.
Nearly all of the library's examples use this object. These examples demonstrate its special features.
File > Examples > Audio > HardwareTesting > PassThroughStereo
File > Examples > Audio > HardwareTesting > SGTL5000 > dap_bass_enhance
File > Examples > Audio > HardwareTesting > SGTL5000 > dap_avc_agc
File > Examples > Audio > HardwareTesting > SGTL5000 > balanceDAC
File > Examples > Audio > HardwareTesting > SGTL5000 > balanceHP
File > Examples > Audio > HardwareTesting > SGTL5000 > CalcBiquadToneControlDAP
TODO: add example with rock/classical/speech presets, where rock uses bass boost and surround enhancement while speech uses bandpass filtering and auto volume control compression.
TODO: add example with two analogRead pots for bass and treble to demonstrate ramping.