@@ -189,12 +189,32 @@ void VS1053::begin() {
189189void VS1053::setVolume (uint8_t vol) {
190190 // Set volume. Both left and right.
191191 // Input value is 0..100. 100 is the loudest.
192- uint16_t value ; // Value to send to SCI_VOL
192+ uint8_t valueL, valueR ; // Values to send to SCI_VOL
193193
194194 curvol = vol; // Save for later use
195- value = map (vol, 0 , 100 , 0xFF , 0x00 ); // 0..100% to one channel
196- value = (value << 8 ) | value;
197- write_register (SCI_VOL, value); // Volume left and right
195+ valueL = vol;
196+ valueR = vol;
197+
198+ if (curbalance < 0 ) {
199+ valueR = max (0 , vol + curbalance);
200+ } else if (curbalance > 0 ) {
201+ valueL = max (0 , vol - curbalance);
202+ }
203+
204+ valueL = map (valueL, 0 , 100 , 0xFE , 0x00 ); // 0..100% to left channel
205+ valueR = map (valueR, 0 , 100 , 0xFE , 0x00 ); // 0..100% to right channel
206+
207+ write_register (SCI_VOL, (valueL << 8 ) | valueR); // Volume left and right
208+ }
209+
210+ void VS1053::setBalance (int8_t balance) {
211+ if (balance > 100 ) {
212+ curbalance = 100 ;
213+ } else if (balance < -100 ) {
214+ curbalance = -100 ;
215+ } else {
216+ curbalance = balance;
217+ }
198218}
199219
200220void VS1053::setTone (uint8_t *rtone) { // Set bass/treble (4 nibbles)
@@ -212,6 +232,10 @@ uint8_t VS1053::getVolume() { // Get the currenet volume setting.
212232 return curvol;
213233}
214234
235+ int8_t VS1053::getBalance () { // Get the currenet balance setting.
236+ return curbalance;
237+ }
238+
215239void VS1053::startSong () {
216240 sdi_send_fillers (10 );
217241}
0 commit comments