Add the RTOS processing. for the Network radio streaming receiver.
Fork of VS1053b by
Diff: VS1053.cpp
- Revision:
- 2:5bab956cb59e
- Parent:
- 1:ced2c297cc1b
- Child:
- 3:88a645490529
--- a/VS1053.cpp Thu Dec 16 21:54:03 2010 +0000 +++ b/VS1053.cpp Wed Dec 22 18:09:33 2010 +0000 @@ -48,9 +48,14 @@ _CS(cs), _RST(rst), _DREQ(dreq), - _DCS(dcs) { + _DCS(dcs) +{ _volume = DEFAULT_VOLUME; _balance = DEFAULT_BALANCE_DIFERENCE_LEFT_RIGHT; + _sb_amplitude = DEFAULT_BASS_AMPLITUDE; + _sb_freqlimit = DEFAULT_BASS_FREQUENCY; + _st_amplitude = DEFAULT_TREBLE_AMPLITUDE; + _st_freqlimit = DEFAULT_TREBLE_FREQUENCY; } /*=================================================================== @@ -227,9 +232,7 @@ void VS1053::setPlaySpeed(unsigned short speed) { wram_write(para_playSpeed, speed); -#ifdef DEBUG - printf("VS1053b: Change speed. New speed: %d\r\n", speed); -#endif + DEBUGOUT("VS1053b: Change speed. New speed: %d\r\n", speed); } void VS1053::terminateStream(void) { @@ -262,17 +265,13 @@ if ((sciModeByte & SM_CANCEL) == 0x0000) { -#ifdef DEBUG - printf("VS1053b: Song sucessfully sent. Terminating OK\r\n"); - printf("VS1053b: SCI MODE = %#x, SM_CANCEL = %#x\r\n", sciModeByte, sciModeByte & SM_CANCEL); -#endif + DEBUGOUT("VS1053b: Song sucessfully sent. Terminating OK\r\n"); + DEBUGOUT("VS1053b: SCI MODE = %#x, SM_CANCEL = %#x\r\n", sciModeByte, sciModeByte & SM_CANCEL); } else { -#ifdef DEBUG - printf("VS1053b: SM CANCEL hasn't cleared after sending 2048 bytes, do software reset\r\n"); - printf("VS1053b: SCI MODE = %#x, SM_CANCEL = %#x\r\n", sciModeByte, sciModeByte & SM_CANCEL); -#endif + DEBUGOUT("VS1053b: SM CANCEL hasn't cleared after sending 2048 bytes, do software reset\r\n"); + DEBUGOUT("VS1053b: SCI MODE = %#x, SM_CANCEL = %#x\r\n", sciModeByte, sciModeByte & SM_CANCEL); //TODO: testing initialize(); } @@ -313,37 +312,33 @@ #ifdef DEBUG unsigned int info = wram_read(para_chipID_0); - printf("VS1053b: ChipID_0:%04X\r\n", info); + DEBUGOUT("VS1053b: ChipID_0:%04X\r\n", info); info = wram_read(para_chipID_1); - printf("VS1053b: ChipID_1:%04X\r\n", info); + DEBUGOUT("VS1053b: ChipID_1:%04X\r\n", info); info = wram_read(para_version); - printf("VS1053b: Structure version:%04X\r\n", info); + DEBUGOUT("VS1053b: Structure version:%04X\r\n", info); #endif //get chip version, set clock multiplier and load patch int i = (sci_read(SCI_STATUS) & 0xF0) >> 4; if (i == 4) { -#ifdef DEBUG - printf("VS1053b: Installed Chip is: VS1053\r\n"); -#endif + + DEBUGOUT("VS1053b: Installed Chip is: VS1053\r\n"); + sci_write(SCI_CLOCKF, (SC_MULT_XTALIx50)); wait_ms(10); #ifdef VS_PATCH // loading patch write_plugin(vs1053b_patch, sizeof(vs1053b_patch)/2); - -#ifdef DEBUG - printf("VS1053b: Patch is loaded.\r\n"); - printf("VS1053b: Patch size:%d bytes\r\n",sizeof(vs1053b_patch)); -#endif + + DEBUGOUT("VS1053b: Patch is loaded.\r\n"); + DEBUGOUT("VS1053b: Patch size:%d bytes\r\n",sizeof(vs1053b_patch)); #endif // VS_PATCH } else { -#ifdef DEBUG - printf("VS1053b: Not Supported Chip\r\n"); -#endif + DEBUGOUT("VS1053b: Not Supported Chip\r\n"); return false; } @@ -385,9 +380,102 @@ // volume calculation unsigned short volCalced = (((char)(_volume / -0.5f)) << 8) + (char)((_volume - _balance) / -0.5f); - sci_write(0x0B, volCalced); + sci_write(SCI_VOL, volCalced); + + DEBUGOUT("VS1053b: Change volume to %#x (%f, Balance = %f)\r\n", volCalced, _volume, _balance); +} + +int VS1053::getTrebleFrequency(void) +{ + return _st_freqlimit * 1000; +} + + +void VS1053::setTrebleFrequency(int frequency) +{ + frequency /= 1000; + + if(frequency < 1) + { + frequency = 1; + } + else if(frequency > 15) + { + frequency = 15; + } + _st_freqlimit = frequency; + changeBass(); +} + +int VS1053::getTrebleAmplitude(void) +{ + return _st_amplitude; +} + +void VS1053::setTrebleAmplitude(int amplitude) +{ + if(amplitude < -8) + { + amplitude = -8; + } + else if(amplitude > 7) + { + amplitude = 7; + } + _st_amplitude = amplitude; + changeBass(); +} -#ifdef DEBUG - printf("VS1053b: Change volume to %#x (%f, Balance = %f)\r\n", volCalced, _volume, _balance); -#endif +int VS1053::getBassFrequency(void) +{ + return _sb_freqlimit * 10; +} + +void VS1053::setBassFrequency(int frequency) +{ + frequency /= 10; + + if(frequency < 2) + { + frequency = 2; + } + else if(frequency > 15) + { + frequency = 15; + } + _sb_freqlimit = frequency; + changeBass(); +} + +int VS1053::getBassAmplitude(void) +{ + return _sb_amplitude; } + +void VS1053::setBassAmplitude(int amplitude) +{ + if(amplitude < -15) + { + amplitude = -15; + } + else if(amplitude > 0) + { + amplitude = 0; + } + _sb_amplitude = amplitude; + changeBass(); +} + +void VS1053::changeBass(void) +{ + unsigned short bassCalced = ((_st_amplitude & 0x0f) << 12) + | ((_st_freqlimit & 0x0f) << 8) + | ((_sb_amplitude & 0x0f) << 4) + | ((_sb_freqlimit & 0x0f) << 0); + + sci_write(SCI_BASS, bassCalced); + + DEBUGOUT("VS1053b: Change bass settings to:\r\n") + DEBUGOUT("VS1053b: --Treble: Amplitude=%i, Frequency=%i\r\n", getTrebleAmplitude(), getTrebleFrequency()); + DEBUGOUT("VS1053b: --Bass: Amplitude=%i, Frequency=%i\r\n", getBassAmplitude(), getBassFrequency()); +}