0.4.251
This commit is contained in:
@@ -10,6 +10,7 @@
|
||||
|
||||
#include "audioVS1053Ex.h"
|
||||
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
AudioBuffer::AudioBuffer(size_t maxBlockSize) {
|
||||
// if maxBlockSize isn't set use defaultspace (1600 bytes) is enough for aac and mp3 player
|
||||
@@ -349,26 +350,32 @@ size_t Audio::bufferFree(){
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
void Audio::setVolume(uint8_t vol){
|
||||
|
||||
// Set volume. Both left and right.
|
||||
// Input value is 0..21. 21 is the loudest.
|
||||
// Input value is 0..254. 254 is the loudest.
|
||||
// Clicking reduced by using 0xf8 to 0x00 as limits.
|
||||
uint16_t value; // Value to send to SCI_VOL
|
||||
|
||||
//if(vol > 21) vol=21;
|
||||
//uint8_t vol2 = map(vol, 0, 254, 128, 254);
|
||||
//uint8_t vol2 = log((float)vol)*23+128;
|
||||
//uint8_t vol2 = log10((float)vol)*50.0+128;
|
||||
uint8_t lgvol = log10(((float)vol+1)) * 50.54571334 + 128;
|
||||
//uint8_t vol2 = sqrt((float)vol)*7.5+128;
|
||||
if(vol != curvol){
|
||||
curvol = vol; // #20
|
||||
//vol=volumetable[vol]; // Save for later use
|
||||
value=map(lgvol, 0, 254, 0xF8, 0x00); // 0..100% to one channel
|
||||
value=(value << 8) | value;
|
||||
|
||||
write_register(SCI_VOL, value); // Volume left and right
|
||||
uint8_t valueL, valueR;
|
||||
int16_t balance_map = map(m_balance, -16, 16, -100, 100);
|
||||
|
||||
valueL = vol;
|
||||
valueR = vol;
|
||||
if (balance_map < 0) {
|
||||
valueR = (float)valueR-(float)valueR * abs((float)balance_map)/100;
|
||||
} else if (balance_map > 0) {
|
||||
valueL = (float)valueL-(float)valueL * abs((float)balance_map)/100;
|
||||
}
|
||||
curvol = vol;
|
||||
|
||||
//uint8_t lgvolL = log10(((float)valueL+1)) * 64.54571334 + 96;
|
||||
//uint8_t lgvolR = log10(((float)valueR+1)) * 64.54571334 + 96;
|
||||
uint8_t lgvolL = VS1053VOL(valueL);
|
||||
uint8_t lgvolR = VS1053VOL(valueR);
|
||||
if(lgvolL==VS1053VOLM) lgvolL=0;
|
||||
if(lgvolR==VS1053VOLM) lgvolR=0;
|
||||
valueL=map(lgvolL, 0, 254, 0xF8, 0x00);
|
||||
valueR=map(lgvolR, 0, 254, 0xF8, 0x00);
|
||||
value=(valueL << 8) | valueR;
|
||||
write_register(SCI_VOL, value);
|
||||
}
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
void Audio::setTone(uint8_t *rtone){ // Set bass/treble (4 nibbles)
|
||||
@@ -383,11 +390,24 @@ void Audio::setTone(uint8_t *rtone){ // Set bass/treble (4
|
||||
}
|
||||
write_register(SCI_BASS, value); // Volume left and right
|
||||
}
|
||||
/*
|
||||
Name Bits Description
|
||||
ST AMPLITUDE 15:12 Treble Control in 1.5 dB steps (-8..7, 0 = off)
|
||||
ST FREQLIMIT 11:8 Lower limit frequency in 1000 Hz steps (1..15) // 1000..15000
|
||||
SB AMPLITUDE 7:4 Bass Enhancement in 1 dB steps (0..15, 0 = off)
|
||||
SB FREQLIMIT 3:0 Lower limit frequency in 10 Hz steps (2..15) // 20..150
|
||||
*/
|
||||
void Audio::setTone(int8_t gainLowPass, int8_t gainBandPass, int8_t gainHighPass){
|
||||
// TODO
|
||||
if(gainLowPass<0) gainLowPass=0;
|
||||
if(gainLowPass>15) gainLowPass=15;
|
||||
if(gainBandPass<0) gainBandPass=0;
|
||||
if(gainBandPass>13) gainBandPass=13;
|
||||
uint8_t rtone[] = {map(gainHighPass, -16, 16, -8, 7), 2+gainBandPass, gainLowPass, 15-gainBandPass};
|
||||
setTone(rtone);
|
||||
}
|
||||
void Audio::setBalance(int8_t bal){
|
||||
// TODO
|
||||
m_balance = bal;
|
||||
setVolume(curvol);
|
||||
}
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
uint8_t Audio::getVolume() // Get the currenet volume setting.
|
||||
|
||||
Reference in New Issue
Block a user