added last of dap 'bits' to control_sgtl5000.* and include an example for bass enhance, need to make one for surround stuff.dds
@@ -745,6 +745,42 @@ unsigned short AudioControlSGTL5000::dap_avc_enable(void) | |||
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) | |||
{ | |||
n=(n*(((float)range)/100))+0.499; |
@@ -71,6 +71,14 @@ public: | |||
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); | |||
protected: | |||
bool muted; |
@@ -59,8 +59,8 @@ elapsedMillis chgMsec=0; | |||
float tone1=0; | |||
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); | |||
tone2=floor(((tone2-512)/512)*70)/10; |
@@ -46,8 +46,8 @@ elapsedMillis chgMsec=0; | |||
float tone1=0; | |||
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); | |||
tone2=floor(((tone2-512)/512)*70)/10; |
@@ -42,8 +42,8 @@ elapsedMillis chgMsec=0; | |||
float lastBal=1024; | |||
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); | |||
bal1=((bal1-512)/512)*100; | |||
bal1=(int)bal1; |
@@ -44,8 +44,8 @@ float lastBal=1024; | |||
float vol1=75; | |||
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); | |||
bal1=((bal1-512)/512)*100; | |||
bal1=(int)bal1; |
@@ -48,8 +48,8 @@ elapsedMillis chgMsec=0; | |||
float lastVol=1024; | |||
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; | |||
vol1=(int)vol1; | |||
if(lastVol!=vol1) |
@@ -0,0 +1,63 @@ | |||
/* 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; | |||
} | |||
} | |||