Browse Source

Merge pull request #10 from robsoles/master

adding surround and bass enhance controls
dds
Paul Stoffregen 11 years ago
parent
commit
67099c39de
8 changed files with 117 additions and 10 deletions
  1. +36
    -0
      control_sgtl5000.cpp
  2. +8
    -0
      control_sgtl5000.h
  3. +2
    -2
      examples/CalcBiquadToneControl/CalcBiquadToneControl.ino
  4. +2
    -2
      examples/SGTL5000_Specific/CalcBiquadToneControlDAP/CalcBiquadToneControlDAP.ino
  5. +2
    -2
      examples/SGTL5000_Specific/balanceDAC/balanceDAC.ino
  6. +2
    -2
      examples/SGTL5000_Specific/balanceHP/balanceHP.ino
  7. +2
    -2
      examples/SGTL5000_Specific/dap_avc_agc/dap_avc_agc.ino
  8. +63
    -0
      examples/SGTL5000_Specific/dap_bass_enhance/dap_bass_enhance.ino

+ 36
- 0
control_sgtl5000.cpp View File

return modify(DAP_AVC_CTRL,1,1); return modify(DAP_AVC_CTRL,1,1);
} }


unsigned short AudioControlSGTL5000::dap_bass_enhance(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)
{
modify(DAP_BASS_ENHANCE,(hpf_bypass&1)<<8|(cutoff&7)<<4,1<<8|7<<4);
return dap_bass_enhance(lr_lev,bass_lev);
}
unsigned short AudioControlSGTL5000::dap_bass_enhance_enable(uint8_t n)
{
return modify(DAP_BASS_ENHANCE,n&1,1);
}
unsigned short AudioControlSGTL5000::dap_bass_enhance_enable(void)
{
return dap_bass_enhance_enable(1);
}
unsigned short AudioControlSGTL5000::dap_surround(uint8_t width)
{
return modify(DAP_SGTL_SURROUND,(width&7)<<4,7<<4);
}
unsigned short AudioControlSGTL5000::dap_surround(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)
{
if(n) n=3;
return modify(DAP_SGTL_SURROUND,n,3);
}
unsigned short AudioControlSGTL5000::dap_surround_enable(void)
{
dap_surround_enable(1);
}


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

+ 8
- 0
control_sgtl5000.h View File

unsigned short dap_avc(uint8_t maxGain, uint8_t lbiResponse, uint8_t hardLimit, float threshold, float attack, float decay); 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(uint8_t n);
unsigned short dap_avc_enable(void); 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);


protected: protected:
bool muted; bool muted;

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

float tone1=0; float tone1=0;


void loop() { void loop() {
// every 10 ms, check for adjustment the tone & vol
if (chgMsec > 10) { // more regular updates for actual changes seems better.
// every 10 ms, check for adjustment
if (chgMsec > 10) {
float tone2=analogRead(15); float tone2=analogRead(15);
tone2=floor(((tone2-512)/512)*70)/10; tone2=floor(((tone2-512)/512)*70)/10;

+ 2
- 2
examples/SGTL5000_Specific/CalcBiquadToneControlDAP/CalcBiquadToneControlDAP.ino View File

float tone1=0; float tone1=0;


void loop() { void loop() {
// every 10 ms, check for adjustment the tone & vol
if (chgMsec > 10) { // more regular updates for actual changes seems better.
// every 10 ms, check for adjustment
if (chgMsec > 10) {
float tone2=analogRead(15); float tone2=analogRead(15);
tone2=floor(((tone2-512)/512)*70)/10; tone2=floor(((tone2-512)/512)*70)/10;

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

float lastBal=1024; float lastBal=1024;


void loop() { void loop() {
// every 10 ms, check for adjustment the balance & vol
if (chgMsec > 10) { // more regular updates for actual changes seems better.
// every 10 ms, check for adjustment
if (chgMsec > 10) {
float bal1=analogRead(15); float bal1=analogRead(15);
bal1=((bal1-512)/512)*100; bal1=((bal1-512)/512)*100;
bal1=(int)bal1; bal1=(int)bal1;

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

float vol1=75; float vol1=75;


void loop() { void loop() {
// every 10 ms, check for adjustment the balance & vol
if (chgMsec > 10) { // more regular updates for actual changes seems better.
// every 10 ms, check for adjustment
if (chgMsec > 10) {
float bal1=analogRead(15); float bal1=analogRead(15);
bal1=((bal1-512)/512)*100; bal1=((bal1-512)/512)*100;
bal1=(int)bal1; bal1=(int)bal1;

+ 2
- 2
examples/SGTL5000_Specific/dap_avc_agc/dap_avc_agc.ino View File

float lastVol=1024; float lastVol=1024;


void loop() { void loop() {
// every 10 ms, check for adjustment the balance & vol
if (chgMsec > 10) { // more regular updates for actual changes seems better.
// every 10 ms, check for adjustment
if (chgMsec > 10) {
float vol1=analogRead(15)/10.23; float vol1=analogRead(15)/10.23;
vol1=(int)vol1; vol1=(int)vol1;
if(lastVol!=vol1) if(lastVol!=vol1)

+ 63
- 0
examples/SGTL5000_Specific/dap_bass_enhance/dap_bass_enhance.ino View File

/* DAP Bass enhance example SGTL5000 only

This example code is in the public domain
*/

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


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

// Create the Audio components. These should be created in the
// order data flows, inputs/sources -> processing -> outputs
//

AudioInputI2S audioInput; // audio shield: mic or line-in
AudioOutputI2S audioOutput; // audio shield: headphones & line-out

// Create Audio connections between the components
//
AudioConnection c1(audioInput, 0, audioOutput, 0); // left passing through
AudioConnection c2(audioInput, 1, audioOutput, 1); // right passing through

// Create an object to control the audio shield.
//
AudioControlSGTL5000 audioShield;

void setup() {
// Audio connections require memory to work. For more
// detailed information, see the MemoryAndCpuUsage example
AudioMemory(4);
// Enable the audio shield and set the output volume.
audioShield.enable();
audioShield.inputSelect(myInput);
audioShield.volume(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);
// please see http://www.pjrc.com/teensy/SGTL5000.pdf page 50 for valid values for BYPASS_HPF and CUTOFF
}

elapsedMillis chgMsec=0;
float lastVol=1024;

void loop() {
// every 10 ms, check for adjustment
if (chgMsec > 10) { // more regular updates for actual changes seems better.
float vol1=analogRead(15)/10.23;
vol1=(int)vol1;
if(lastVol!=vol1)
{
audioShield.volume(vol1);
lastVol=vol1;
}
chgMsec = 0;
}
}


Loading…
Cancel
Save