Browse Source

control_sgtl5000.* overhaul with many renames.

While changing everything else I also modified most things regarding
gain or volume from using 0 to 100 (or -100 thru 0 to 100) to using 1
(or -1 to 1) with only one exception I can think of right now in the
autoVolumeControl(..); - I modified all examples I found .volume or
similar in to suit.

I found opportunity to write these changes, I did not have a chance to
test much more extensively than just compiling it. I will have a chance
to test them by about 24 hours time.
dds
robsoles 10 years ago
parent
commit
511d9a1625
24 changed files with 148 additions and 128 deletions
  1. +64
    -44
      control_sgtl5000.cpp
  2. +34
    -28
      control_sgtl5000.h
  3. +1
    -3
      examples/CalcBiquadToneControl/CalcBiquadToneControl.ino
  4. +1
    -1
      examples/DialTone_DTMF/DialTone_DTMF.ino
  5. +1
    -1
      examples/FFT/FFT.ino
  6. +2
    -2
      examples/Filter/Filter.ino
  7. +1
    -1
      examples/PassThrough/PassThrough.ino
  8. +1
    -1
      examples/PassThroughAnalog/PassThroughAnalog.ino
  9. +1
    -1
      examples/PassThroughPlusTone/PassThroughPlusTone.ino
  10. +1
    -1
      examples/PlayFromSketch/PlayFromSketch.ino
  11. +2
    -2
      examples/PlayMidiTones/PlayMidiTones.ino
  12. +2
    -2
      examples/PlaySynthMusic/PlaySynthMusic.ino
  13. +2
    -2
      examples/PlayWavFromSdCard/PlayWavFromSdCard.ino
  14. +9
    -10
      examples/SGTL5000_Specific/CalcBiquadToneControlDAP/CalcBiquadToneControlDAP.ino
  15. +5
    -5
      examples/SGTL5000_Specific/balanceDAC/balanceDAC.ino
  16. +5
    -5
      examples/SGTL5000_Specific/balanceHP/balanceHP.ino
  17. +3
    -5
      examples/SGTL5000_Specific/dap_avc_agc/dap_avc_agc.ino
  18. +5
    -6
      examples/SGTL5000_Specific/dap_bass_enhance/dap_bass_enhance.ino
  19. +1
    -1
      examples/SpectrumAnalyzer/SpectrumAnalyzer.ino
  20. +1
    -1
      examples/StereoPeakMeter/StereoPeakMeter.ino
  21. +1
    -1
      examples/ToneSweep/ToneSweep.ino
  22. +2
    -2
      examples/effect_chorus/effect_chorus.ino
  23. +1
    -1
      examples/effect_flange/effect_flange.ino
  24. +2
    -2
      examples/fir_filter/fir_filter.ino

+ 64
- 44
control_sgtl5000.cpp View File

@@ -532,13 +532,13 @@ bool AudioControlSGTL5000::enable(void)
write(CHIP_ANA_HP_CTRL, 0x7F7F); // set volume (lowest level)
write(CHIP_ANA_CTRL, 0x0136); // enable zero cross detectors
//mute = false;
semi_automated = true;
return true;
}

unsigned int AudioControlSGTL5000::read(unsigned int reg)
{
unsigned int val;

Wire.beginTransmission(SGTL5000_I2C_ADDR);
Wire.write(reg >> 8);
Wire.write(reg);
@@ -605,26 +605,26 @@ bool AudioControlSGTL5000::volume(float left, float right)


// CHIP_LINE_OUT_VOL
unsigned short AudioControlSGTL5000::lo_lvl(uint8_t n)
unsigned short AudioControlSGTL5000::lineOutLevel(uint8_t n)
{
n&=31;
return modify(CHIP_LINE_OUT_VOL,(n<<8)|n,(31<<8)|31);
}

unsigned short AudioControlSGTL5000::lo_lvl(uint8_t left, uint8_t right)
unsigned short AudioControlSGTL5000::lineOutLevel(uint8_t left, uint8_t right)
{
left&=31;
right&=31;
return modify(CHIP_LINE_OUT_VOL,(right<<8)|left,(31<<8)|31);
}

unsigned short AudioControlSGTL5000::dac_vol(float n) // set both directly
unsigned short AudioControlSGTL5000::dacVolume(float n) // set both directly
{
if(read(CHIP_ADCDAC_CTRL)&(3<<2)!=((n>0 ? 0:3)<<2)) modify(CHIP_ADCDAC_CTRL,(n>0 ? 0:3)<<2,3<<2);
unsigned char m=calcVol(n,0xC0);
return modify(CHIP_DAC_VOL,((0xFC-m)<<8)|(0xFC-m),65535);
}
unsigned short AudioControlSGTL5000::dac_vol(float left, float right)
unsigned short AudioControlSGTL5000::dacVolume(float left, float right)
{
unsigned short adcdac=((right>0 ? 0:2)|(left>0 ? 0:1))<<2;
if(read(CHIP_ADCDAC_CTRL)&(3<<2)!=adcdac) modify(CHIP_ADCDAC_CTRL,adcdac,1<<2);
@@ -632,23 +632,23 @@ unsigned short AudioControlSGTL5000::dac_vol(float left, float right)
return modify(CHIP_DAC_VOL,m,65535);
}

unsigned short AudioControlSGTL5000::adc_hpf(uint8_t bypass, uint8_t freeze)
unsigned short AudioControlSGTL5000::adcHighPassFilterControl(uint8_t bypass, uint8_t freeze)
{
return modify(CHIP_ADCDAC_CTRL, (freeze&1)<<1|bypass&1,3);
}

unsigned short AudioControlSGTL5000::adc_hpf(uint8_t bypass)
unsigned short AudioControlSGTL5000::adcHighPassFilterControl(uint8_t bypass)
{
return modify(CHIP_ADCDAC_CTRL, bypass&1,1);
}


// DAP_CONTROL
unsigned short AudioControlSGTL5000::dap_mix_enable(uint8_t n)
unsigned short AudioControlSGTL5000::audioMixerEnable(uint8_t n)
{
return modify(DAP_CONTROL,(n&1)<<4,1<<4);
}
unsigned short AudioControlSGTL5000::dap_enable(uint8_t n)
unsigned short AudioControlSGTL5000::audioProcessorEnable(uint8_t n)
{
if(n) n=1;
unsigned char i2s_sel=3*n; // ADC if n==0 else DAP
@@ -656,52 +656,50 @@ unsigned short AudioControlSGTL5000::dap_enable(uint8_t n)
return route(i2s_sel,SGTL_I2S_TEENSY,SGTL_ADC);
}

unsigned short AudioControlSGTL5000::dap_enable(void)
unsigned short AudioControlSGTL5000::audioProcessorEnable(void)
{
return dap_enable(1);
return audioProcessorEnable(1);
}

// DAP_PEQ
unsigned short AudioControlSGTL5000::dap_peqs(uint8_t n) // valid to n&7, 0 thru 7 filters enabled.
unsigned short AudioControlSGTL5000::eqFilterCount(uint8_t n) // valid to n&7, 0 thru 7 filters enabled.
{
return modify(DAP_PEQ,(n&7),7);
}

// DAP_AUDIO_EQ
unsigned short AudioControlSGTL5000::dap_audio_eq(uint8_t n) // 0=NONE, 1=PEQ (7 IIR Biquad filters), 2=TONE (tone), 3=GEQ (5 band EQ)
unsigned short AudioControlSGTL5000::eqSelect(uint8_t n) // 0=NONE, 1=PEQ (7 IIR Biquad filters), 2=TONE (tone), 3=GEQ (5 band EQ)
{
return modify(DAP_AUDIO_EQ,n&3,3);
}


// DAP_AUDIO_EQ_BASS_BAND0 & DAP_AUDIO_EQ_BAND1 & DAP_AUDIO_EQ_BAND2 etc etc
unsigned short AudioControlSGTL5000::dap_audio_eq_band(uint8_t bandNum, float n) // by signed percentage -100/+100; dap_audio_eq(3);
{ // 0x00==-12dB, 0x2F==0dB, 0x5F==12dB
n=((n/100)*48)+0.499;
if(n<-47) n=-47;
if(n>48) n=48;
n+=47;
return modify(DAP_AUDIO_EQ_BASS_BAND0+(bandNum*2),(unsigned int)n,127);
unsigned short AudioControlSGTL5000::eqBand(uint8_t bandNum, float n)
{
if(semi_automated) automate(1,3);
return dap_audio_eq_band(bandNum, n);
}
void AudioControlSGTL5000::dap_audio_eq_geq(float bass, float mid_bass, float midrange, float mid_treble, float treble)
void AudioControlSGTL5000::eqBands(float bass, float mid_bass, float midrange, float mid_treble, float treble)
{
if(semi_automated) automate(1,3);
dap_audio_eq_band(0,bass);
dap_audio_eq_band(1,mid_bass);
dap_audio_eq_band(2,midrange);
dap_audio_eq_band(3,mid_treble);
dap_audio_eq_band(4,treble);
}
void AudioControlSGTL5000::dap_audio_eq_tone(float bass, float treble) // dap_audio_eq(2);
void AudioControlSGTL5000::eqBands(float bass, float treble) // dap_audio_eq(2);
{
if(semi_automated) automate(1,2);
dap_audio_eq_band(0,bass);
dap_audio_eq_band(4,treble);
}

// SGTL5000 PEQ Coefficient loader
void AudioControlSGTL5000::load_peq(uint8_t filterNum, int *filterParameters)
void AudioControlSGTL5000::eqFilter(uint8_t filterNum, int *filterParameters)
{
// 1111 11111111 11111111

// TODO: add the part that selects 7 PEQ filters.
if(semi_automated) automate(1,1,filterNum+1);
modify(DAP_FILTER_COEF_ACCESS,(uint16_t)filterNum,15);
write(DAP_COEF_WR_B0_MSB,(*filterParameters>>4)&65535);
write(DAP_COEF_WR_B0_LSB,(*filterParameters++)&15);
write(DAP_COEF_WR_B1_MSB,(*filterParameters>>4)&65535);
@@ -713,8 +711,6 @@ void AudioControlSGTL5000::load_peq(uint8_t filterNum, int *filterParameters)
write(DAP_COEF_WR_A2_MSB,(*filterParameters>>4)&65535);
write(DAP_COEF_WR_A2_LSB,(*filterParameters++)&15);
write(DAP_FILTER_COEF_ACCESS,(uint16_t)0x100|filterNum);
delay(10); // seems necessary, didn't work for 1ms.
modify(DAP_FILTER_COEF_ACCESS,(uint16_t)filterNum,15);
}

/* Valid values for dap_avc parameters
@@ -743,8 +739,9 @@ void AudioControlSGTL5000::load_peq(uint8_t filterNum, int *filterParameters)
decay
floating point figure is dB/s rate at which gain is reduced
*/
unsigned short AudioControlSGTL5000::dap_avc(uint8_t maxGain, uint8_t lbiResponse, uint8_t hardLimit, float threshold, float attack, float decay)
unsigned short AudioControlSGTL5000::autoVolumeControl(uint8_t maxGain, uint8_t lbiResponse, uint8_t hardLimit, float threshold, float attack, float decay)
{
if(semi_automated&&(!read(DAP_CONTROL)&1)) audioProcessorEnable(1);
if(maxGain>2) maxGain=2;
lbiResponse&=3;
hardLimit&=1;
@@ -756,59 +753,82 @@ unsigned short AudioControlSGTL5000::dap_avc(uint8_t maxGain, uint8_t lbiRespons
write(DAP_AVC_DECAY,dec);
return modify(DAP_AVC_CTRL,maxGain<<12|lbiResponse<<8|hardLimit<<5,3<<12|3<<8|1<<5);
}
unsigned short AudioControlSGTL5000::dap_avc_enable(uint8_t n)
unsigned short AudioControlSGTL5000::autoVolumeEnable(uint8_t n)
{
n&=1;
return modify(DAP_AVC_CTRL,n,1);
}
unsigned short AudioControlSGTL5000::dap_avc_enable(void)
unsigned short AudioControlSGTL5000::autoVolumeEnable(void)
{
return modify(DAP_AVC_CTRL,1,1);
}

unsigned short AudioControlSGTL5000::dap_bass_enhance(float lr_lev, float bass_lev)
unsigned short AudioControlSGTL5000::enhanceBass(float lr_lev, float bass_lev)
{
return modify(DAP_BASS_ENHANCE_CTRL,(0x3F-calcVol(lr_lev,0x3F))<<8|0x7F-calcVol(bass_lev,0x7F),0x3F<<8|0x7F);
}
unsigned short AudioControlSGTL5000::dap_bass_enhance(float lr_lev, float bass_lev, uint8_t hpf_bypass, uint8_t cutoff)
unsigned short AudioControlSGTL5000::enhanceBass(float lr_lev, float bass_lev, uint8_t hpf_bypass, uint8_t cutoff)
{
modify(DAP_BASS_ENHANCE,(hpf_bypass&1)<<8|(cutoff&7)<<4,1<<8|7<<4);
return dap_bass_enhance(lr_lev,bass_lev);
return enhanceBass(lr_lev,bass_lev);
}
unsigned short AudioControlSGTL5000::dap_bass_enhance_enable(uint8_t n)
unsigned short AudioControlSGTL5000::enhanceBassEnable(uint8_t n)
{
return modify(DAP_BASS_ENHANCE,n&1,1);
}
unsigned short AudioControlSGTL5000::dap_bass_enhance_enable(void)
unsigned short AudioControlSGTL5000::enhanceBassEnable(void)
{
return dap_bass_enhance_enable(1);
return enhanceBassEnable(1);
}
unsigned short AudioControlSGTL5000::dap_surround(uint8_t width)
unsigned short AudioControlSGTL5000::surroundSound(uint8_t width)
{
return modify(DAP_SGTL_SURROUND,(width&7)<<4,7<<4);
}
unsigned short AudioControlSGTL5000::dap_surround(uint8_t width, uint8_t select)
unsigned short AudioControlSGTL5000::surroundSound(uint8_t width, uint8_t select)
{
return modify(DAP_SGTL_SURROUND,(width&7)<<4|select&3,7<<4|3);
}
unsigned short AudioControlSGTL5000::dap_surround_enable(uint8_t n)
unsigned short AudioControlSGTL5000::surroundSoundEnable(uint8_t n)
{
if(n) n=3;
return modify(DAP_SGTL_SURROUND,n,3);
}
unsigned short AudioControlSGTL5000::dap_surround_enable(void)
unsigned short AudioControlSGTL5000::surroundSoundEnable(void)
{
dap_surround_enable(1);
surroundSoundEnable(1);
}


unsigned char AudioControlSGTL5000::calcVol(float n, unsigned char range)
{
n=(n*(((float)range)/100))+0.499;
// n=(n*(((float)range)/100))+0.499;
n=(n*((float)range))+0.499;
if ((unsigned char)n>range) n=range;
return (unsigned char)n;
}

// DAP_AUDIO_EQ_BASS_BAND0 & DAP_AUDIO_EQ_BAND1 & DAP_AUDIO_EQ_BAND2 etc etc
unsigned short AudioControlSGTL5000::dap_audio_eq_band(uint8_t bandNum, float n) // by signed percentage -100/+100; dap_audio_eq(3);
{
n=((n/1)*48)+0.499;
if(n<-47) n=-47;
if(n>48) n=48;
n+=47;
return modify(DAP_AUDIO_EQ_BASS_BAND0+(bandNum*2),(unsigned int)n,127);
}

void AudioControlSGTL5000::automate(uint8_t dap, uint8_t eq)
{
if((dap!=0)&&(!read(DAP_CONTROL)&1)) audioProcessorEnable(1);
if(read(DAP_AUDIO_EQ)&3!=eq) eqSelect(eq);
}

void AudioControlSGTL5000::automate(uint8_t dap, uint8_t eq, uint8_t filterCount)
{
automate(dap,eq);
if(filterCount>read(DAP_PEQ)&7) eqFilterCount(filterCount);
}


// if(SGTL5000_PEQ) quantization_unit=524288; if(AudioFilterBiquad) quantization_unit=2147483648;
void calcBiquad(uint8_t filtertype, float fC, float dB_Gain, float Q, uint32_t quantization_unit, uint32_t fS, int *coef)

+ 34
- 28
control_sgtl5000.h View File

@@ -38,7 +38,7 @@ class AudioControlSGTL5000 : public AudioControl
public:
bool enable(void);
bool disable(void) { return false; }
bool volume(float n) { return volumeInteger(n * 1.29 + 0.499); }
bool volume(float n) { return volumeInteger(n * 129 + 0.499); }
bool inputLevel(float n) {return false;}
bool muteHeadphone(void) { return write(0x0024, ana_ctrl | (1<<4)); }
bool unmuteHeadphone(void) { return write(0x0024, ana_ctrl & ~(1<<4)); }
@@ -61,34 +61,35 @@ public:
unsigned short route(uint8_t i2s_out, uint8_t dac, uint8_t dap) { return route(i2s_out,dac,dap,0); }
bool volume(float left, float right);
unsigned short micGain(unsigned int n) { return modify(0x002A, n&3, 3); }
unsigned short lo_lvl(uint8_t n);
unsigned short lo_lvl(uint8_t left, uint8_t right);
unsigned short dac_vol(float n);
unsigned short dac_vol(float left, float right);
unsigned short adc_hpf(uint8_t bypass, uint8_t freeze);
unsigned short adc_hpf(uint8_t bypass);
unsigned short dap_mix_enable(uint8_t n);
unsigned short dap_enable(uint8_t n);
unsigned short dap_enable(void);
unsigned short dap_peqs(uint8_t n);
unsigned short dap_audio_eq(uint8_t n);
unsigned short dap_audio_eq_band(uint8_t bandNum, float n);
void dap_audio_eq_geq(float bass, float mid_bass, float midrange, float mid_treble, float treble);
void dap_audio_eq_tone(float bass, float treble);
void load_peq(uint8_t filterNum, int *filterParameters);
unsigned short dap_avc(uint8_t maxGain, uint8_t lbiResponse, uint8_t hardLimit, float threshold, float attack, float decay);
unsigned short dap_avc_enable(uint8_t n);
unsigned short dap_avc_enable(void);
unsigned short dap_bass_enhance(float lr_lev, float bass_lev);
unsigned short dap_bass_enhance(float lr_lev, float bass_lev, uint8_t hpf_bypass, uint8_t cutoff);
unsigned short dap_bass_enhance_enable(uint8_t n);
unsigned short dap_bass_enhance_enable(void);
unsigned short dap_surround(uint8_t width);
unsigned short dap_surround(uint8_t width, uint8_t select);
unsigned short dap_surround_enable(uint8_t n);
unsigned short dap_surround_enable(void);
unsigned short lineOutLevel(uint8_t n);
unsigned short lineOutLevel(uint8_t left, uint8_t right);
unsigned short dacVolume(float n);
unsigned short dacVolume(float left, float right);
unsigned short adcHighPassFilterControl(uint8_t bypass, uint8_t freeze);
unsigned short adcHighPassFilterControl(uint8_t bypass);
unsigned short audioMixerEnable(uint8_t n);
unsigned short audioProcessorEnable(uint8_t n);
unsigned short audioProcessorEnable(void);
unsigned short eqFilterCount(uint8_t n);
unsigned short eqSelect(uint8_t n);
unsigned short eqBand(uint8_t bandNum, float n);
void eqBands(float bass, float mid_bass, float midrange, float mid_treble, float treble);
void eqBands(float bass, float treble);
void eqFilter(uint8_t filterNum, int *filterParameters);
unsigned short autoVolumeControl(uint8_t maxGain, uint8_t lbiResponse, uint8_t hardLimit, float threshold, float attack, float decay);
unsigned short autoVolumeEnable(uint8_t n);
unsigned short autoVolumeEnable(void);
unsigned short enhanceBass(float lr_lev, float bass_lev);
unsigned short enhanceBass(float lr_lev, float bass_lev, uint8_t hpf_bypass, uint8_t cutoff);
unsigned short enhanceBassEnable(uint8_t n);
unsigned short enhanceBassEnable(void);
unsigned short surroundSound(uint8_t width);
unsigned short surroundSound(uint8_t width, uint8_t select);
unsigned short surroundSoundEnable(uint8_t n);
unsigned short surroundSoundEnable(void);
void killAutomation(void) { semi_automated=false; }

protected:
protected:
bool muted;
bool volumeInteger(unsigned int n); // range: 0x00 to 0x80
uint16_t ana_ctrl;
@@ -98,6 +99,11 @@ public:
unsigned int read(unsigned int reg);
bool write(unsigned int reg, unsigned int val);
unsigned int modify(unsigned int reg, unsigned int val, unsigned int iMask);
unsigned short dap_audio_eq_band(uint8_t bandNum, float n);
private:
bool semi_automated;
void automate(uint8_t dap, uint8_t eq);
void automate(uint8_t dap, uint8_t eq, uint8_t filterCount);
};

//For Filter Type: 0 = LPF, 1 = HPF, 2 = BPF, 3 = NOTCH, 4 = PeakingEQ, 5 = LowShelf, 6 = HighShelf

+ 1
- 3
examples/CalcBiquadToneControl/CalcBiquadToneControl.ino View File

@@ -38,7 +38,7 @@ void setup() {
// Enable the audio shield, select the input and set the output volume.
audioShield.enable();
audioShield.inputSelect(myInput);
audioShield.volume(75);
audioShield.volume(0.75);
audioShield.unmuteLineout();

calcBiquad(FILTER_PARAEQ,110,0,0.2,2147483648,44100,updateFilter);
@@ -47,8 +47,6 @@ void setup() {
calcBiquad(FILTER_PARAEQ,4400,0,0.167,2147483648,44100,updateFilter);
filterTone_L.updateCoefs(1,updateFilter);
filterTone_R.updateCoefs(1,updateFilter);
Serial.begin(9600);
}

elapsedMillis chgMsec=0;

+ 1
- 1
examples/DialTone_DTMF/DialTone_DTMF.ino View File

@@ -44,7 +44,7 @@ void setup() {

// Enable the audio shield and set the output volume.
audioShield.enable();
audioShield.volume(82);
audioShield.volume(0.82);
while (!Serial) ;
delay(100);

+ 1
- 1
examples/FFT/FFT.ino View File

@@ -31,7 +31,7 @@ void setup() {
// Enable the audio shield and set the output volume.
audioShield.enable();
audioShield.inputSelect(myInput);
audioShield.volume(60);
audioShield.volume(0.6);
}

void loop() {

+ 2
- 2
examples/Filter/Filter.ino View File

@@ -37,7 +37,7 @@ void setup() {
// Enable the audio shield and set the output volume.
audioShield.enable();
audioShield.inputSelect(myInput);
audioShield.volume(60);
audioShield.volume(0.6);
}

elapsedMillis volmsec=0;
@@ -46,7 +46,7 @@ void loop() {
// every 50 ms, adjust the volume
if (volmsec > 50) {
float vol = analogRead(15);
vol = vol / 10.24;
vol = vol / 1024;
audioShield.volume(vol);
volmsec = 0;
}

+ 1
- 1
examples/PassThrough/PassThrough.ino View File

@@ -32,7 +32,7 @@ void setup() {
// Enable the audio shield and set the output volume.
audioShield.enable();
audioShield.inputSelect(myInput);
audioShield.volume(60);
audioShield.volume(0.6);
}

elapsedMillis volmsec=0;

+ 1
- 1
examples/PassThroughAnalog/PassThroughAnalog.ino View File

@@ -28,7 +28,7 @@ void setup() {

// Enable the audio shield and set the output volume.
audioShield.enable();
audioShield.volume(60);
audioShield.volume(0.6);
}

void loop() {

+ 1
- 1
examples/PassThroughPlusTone/PassThroughPlusTone.ino View File

@@ -52,7 +52,7 @@ void setup() {
// Enable the audio shield and set the output volume.
audioShield.enable();
audioShield.inputSelect(myInput);
audioShield.volume(60);
audioShield.volume(0.60);
}

elapsedMillis volmsec=0;

+ 1
- 1
examples/PlayFromSketch/PlayFromSketch.ino View File

@@ -68,7 +68,7 @@ void setup() {

// turn on the output
audioShield.enable();
audioShield.volume(50);
audioShield.volume(0.5);

// by default the Teensy 3.1 DAC uses 3.3Vp-p output
// if your 3.3V power has noise, switching to the

+ 2
- 2
examples/PlayMidiTones/PlayMidiTones.ino View File

@@ -61,7 +61,7 @@ void setup()
AudioMemory(8);
codec.enable();
codec.volume(volume);
codec.volume(0.5);
// I want output on the line out too
codec.unmuteLineout();

@@ -108,7 +108,7 @@ if(0) {
int n = analogRead(15);
if (n != volume) {
volume = n;
codec.volume((float)n / 10.23);
codec.volume((float)n / 1023);
}
c = *sp++;

+ 2
- 2
examples/PlaySynthMusic/PlaySynthMusic.ino View File

@@ -84,7 +84,7 @@ void setup()
AudioMemory(10);
codec.enable();
codec.volume(volume);
codec.volume(0.5);
// I want output on the line out too
// Comment this if you don't it
codec.unmuteLineout();
@@ -135,7 +135,7 @@ if(0) {
int n = analogRead(15);
if (n != volume) {
volume = n;
codec.volume((float)n / 10.23);
codec.volume((float)n / 1023);
}
c = *sp++;

+ 2
- 2
examples/PlayWavFromSdCard/PlayWavFromSdCard.ino View File

@@ -25,7 +25,7 @@ void setup() {
AudioMemory(5);

audioShield.enable();
audioShield.volume(20);
audioShield.volume(0.5);

SPI.setMOSI(7);
SPI.setSCK(14);
@@ -36,7 +36,7 @@ void setup() {

void loop() {
float vol = analogRead(15);
vol = vol / 10.24;
vol = vol / 1024;
audioShield.volume(vol);
delay(20);
}

+ 9
- 10
examples/SGTL5000_Specific/CalcBiquadToneControlDAP/CalcBiquadToneControlDAP.ino View File

@@ -30,16 +30,15 @@ void setup() {
// Enable the audio shield, select the input and set the output volume.
audioShield.enable();
audioShield.inputSelect(myInput);
audioShield.volume(75);
audioShield.volume(0.75);
audioShield.unmuteLineout();
audioShield.dap_enable(); // enable the DAP block in SGTL5000
audioShield.dap_audio_eq(1); // using PEQ Biquad filters
audioShield.dap_peqs(2); // enable filter 0 & filter 1

calcBiquad(FILTER_PARAEQ,110,0,0.2,524288,44100,updateFilter);
audioShield.load_peq(0,updateFilter);
// audioShield.audioProcessorEnable(); // enable the DAP block in SGTL5000
// audioShield.eqSelect(1); // using PEQ Biquad filters
// audioShield.eqFilterCount(2); // enable filter 0 & filter 1
calcBiquad(FILTER_PARAEQ,110,0,0.2,524288,44100,updateFilter); // automation negates the need
audioShield.eqFilter(0,updateFilter); // for the three lines commented out above.
calcBiquad(FILTER_PARAEQ,4400,0,0.167,524288,44100,updateFilter);
audioShield.load_peq(1,updateFilter);
audioShield.eqFilter(1,updateFilter);
}

elapsedMillis chgMsec=0;
@@ -55,9 +54,9 @@ void loop() {
{
// calcBiquad(FilterType,FrequencyC,dBgain,Q,QuantizationUnit,SampleRate,int*);
calcBiquad(FILTER_PARAEQ,110,-tone2,0.2,524288,44100,updateFilter);
audioShield.load_peq(0,updateFilter);
audioShield.eqFilter(0,updateFilter);
calcBiquad(FILTER_PARAEQ,4400,tone2,0.167,524288,44100,updateFilter);
audioShield.load_peq(1,updateFilter);
audioShield.eqFilter(1,updateFilter);
tone1=tone2;
}
chgMsec = 0;

+ 5
- 5
examples/SGTL5000_Specific/balanceDAC/balanceDAC.ino View File

@@ -34,7 +34,7 @@ void setup() {
// Enable the audio shield and set the output volume.
audioShield.enable();
audioShield.inputSelect(myInput);
audioShield.volume(75);
audioShield.volume(0.75);
audioShield.unmuteLineout();
}

@@ -45,17 +45,17 @@ void loop() {
// every 10 ms, check for adjustment
if (chgMsec > 10) {
float bal1=analogRead(15);
bal1=((bal1-512)/512)*100;
bal1=((bal1-512)/512);
bal1=(int)bal1;
if(lastBal!=bal1)
{
if(bal1<0)
{ // leaning toward left...
audioShield.dac_vol(100,100+bal1);
audioShield.dacVolume(1,1+bal1);
} else if(bal1>0) { // to the right
audioShield.dac_vol(100-bal1,100);
audioShield.dacVolume(1-bal1,1);
} else { // middle
audioShield.dac_vol(100);
audioShield.dacVolume(1);
}
lastBal=bal1;
}

+ 5
- 5
examples/SGTL5000_Specific/balanceHP/balanceHP.ino View File

@@ -34,28 +34,28 @@ void setup() {
// Enable the audio shield and set the output volume.
audioShield.enable();
audioShield.inputSelect(myInput);
audioShield.volume(60);
audioShield.volume(0.75);
audioShield.unmuteLineout();
}

elapsedMillis chgMsec=0;

float lastBal=1024;
float vol1=75;
float vol1=0.75;

void loop() {
// every 10 ms, check for adjustment
if (chgMsec > 10) {
float bal1=analogRead(15);
bal1=((bal1-512)/512)*100;
bal1=((bal1-512)/512);
bal1=(int)bal1;
if(lastBal!=bal1)
{
if(bal1<0)
{
audioShield.volume(vol1,(vol1/100)*(100+bal1));
audioShield.volume(vol1,vol1*(1+bal1));
} else {
audioShield.volume((vol1/100)*(100-bal1),vol1);
audioShield.volume(vol1*(1-bal1),vol1);
}
lastBal=bal1;
}

+ 3
- 5
examples/SGTL5000_Specific/dap_avc_agc/dap_avc_agc.ino View File

@@ -34,14 +34,12 @@ void setup() {
// Enable the audio shield and set the output volume.
audioShield.enable();
audioShield.inputSelect(myInput);
audioShield.volume(75);
audioShield.volume(0.75);
audioShield.unmuteLineout();
// have to enable DAP to use AVC
audioShield.dap_enable();
// here are some settings for AVC that have a fairly obvious effect
audioShield.dap_avc(2,1,0,-5,0.5,0.5); // see comments starting line #699 of control_sgtl5000.cpp in ./libraries/audio/
audioShield.autoVolumeControl(2,1,0,-5,0.5,0.5); // see comments starting line #699 of control_sgtl5000.cpp in ./libraries/audio/
// AVC has its own enable/disable bit
audioShield.dap_avc_enable(); // you can use audioShield.dap_avc_enable(0); to turn off AVC
// you can use audioShield.autoVolumeEnable(0); to turn off AVC
}

elapsedMillis chgMsec=0;

+ 5
- 6
examples/SGTL5000_Specific/dap_bass_enhance/dap_bass_enhance.ino View File

@@ -34,13 +34,12 @@ void setup() {
// Enable the audio shield and set the output volume.
audioShield.enable();
audioShield.inputSelect(myInput);
audioShield.volume(75);
audioShield.volume(0.75);
audioShield.unmuteLineout();
// have to enable DAP to use bass enhance
audioShield.dap_enable();
audioShield.dap_bass_enhance_enable(); // all we need to do for default bass enhancement settings.
// audioShield.dap_bass_enhance((float)lr_level,(float)bass_level);
// audioShield.dap_bass_enhance((float)lr_level,(float)bass_level,(uint8_t)hpf_bypass,(uint8_t)cutoff);
// just enable it to use default settings.
audioShield.enhanceBassEnable(); // all we need to do for default bass enhancement settings.
// audioShield.enhanceBass((float)lr_level,(float)bass_level);
// audioShield.enhanceBass((float)lr_level,(float)bass_level,(uint8_t)hpf_bypass,(uint8_t)cutoff);
// please see http://www.pjrc.com/teensy/SGTL5000.pdf page 50 for valid values for BYPASS_HPF and CUTOFF
}


+ 1
- 1
examples/SpectrumAnalyzer/SpectrumAnalyzer.ino View File

@@ -43,7 +43,7 @@ void setup() {
// Enable the audio shield and set the output volume.
audioShield.enable();
audioShield.inputSelect(myInput);
audioShield.volume(60);
audioShield.volume(0.6);
lcd.begin(16, 2);
lcd.print("Audio Spectrum");

+ 1
- 1
examples/StereoPeakMeter/StereoPeakMeter.ino View File

@@ -27,7 +27,7 @@ void setup() {
AudioMemory(6);
audioShield.enable();
audioShield.inputSelect(myInput);
audioShield.volume(75);
audioShield.volume(0.75);
audioShield.unmuteLineout();
Serial.begin(Serial.baud());
}

+ 1
- 1
examples/ToneSweep/ToneSweep.ino View File

@@ -56,7 +56,7 @@ void setup(void)
AudioMemory(2);

audioShield.enable();
audioShield.volume(50);
audioShield.volume(0.5);
// I want output on the line out too
audioShield.unmuteLineout();
// audioShield.muteHeadphone();

+ 2
- 2
examples/effect_chorus/effect_chorus.ino View File

@@ -96,7 +96,7 @@ void setup() {

audioShield.enable();
audioShield.inputSelect(myInput);
audioShield.volume(50);
audioShield.volume(0.5);
// Warn that the passthru pin is grounded
if(!digitalRead(PASSTHRU_PIN)) {
@@ -134,7 +134,7 @@ void loop()
int n = analogRead(15);
if (n != volume) {
volume = n;
audioShield.volume((float)n / 10.23);
audioShield.volume((float)n / 1023);
}
if(0) {
if(millis() - last_time >= 5000) {

+ 1
- 1
examples/effect_flange/effect_flange.ino View File

@@ -157,7 +157,7 @@ void setup() {

audioShield.enable();
audioShield.inputSelect(myInput);
audioShield.volume(50);
audioShield.volume(0.5);
// Warn that the passthru pin is grounded
if(!digitalRead(PASSTHRU_PIN)) {

+ 2
- 2
examples/fir_filter/fir_filter.ino View File

@@ -82,7 +82,7 @@ void setup() {

audioShield.enable();
audioShield.inputSelect(myInput);
audioShield.volume(50);
audioShield.volume(0.5);
// Warn that the passthru pin is grounded
if(!digitalRead(PASSTHRU_PIN)) {
@@ -115,7 +115,7 @@ void loop()
int n = analogRead(15);
if (n != volume) {
volume = n;
audioShield.volume((float)n / 10.23);
audioShield.volume((float)n / 1023);
}
// update the two buttons

Loading…
Cancel
Save