Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
VS1053.cpp
00001 /* mbed VLSI VS1053b library 00002 * Copyright (c) 2010 Christian Schmiljun 00003 * 00004 * Permission is hereby granted, free of charge, to any person obtaining a copy 00005 * of this software and associated documentation files (the "Software"), to deal 00006 * in the Software without restriction, including without limitation the rights 00007 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 00008 * copies of the Software, and to permit persons to whom the Software is 00009 * furnished to do so, subject to the following conditions: 00010 * 00011 * The above copyright notice and this permission notice shall be included in 00012 * all copies or substantial portions of the Software. 00013 * 00014 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 00015 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 00016 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 00017 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 00018 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 00019 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 00020 * THE SOFTWARE. 00021 */ 00022 00023 /* This code based on: 00024 * mbeduino_MP3_Shield_MP3Player 00025 * http://mbed.org/users/xshige/programs/mbeduino_MP3_Shield_MP3Player/lgcx63 00026 * 2010-10-16 00027 */ 00028 00029 #include "VS1053.h" 00030 #include "mbed.h" 00031 00032 // patch binarys 00033 #include "Patches/VS1053b_patch_1_5.c" 00034 #include "Patches/VS1053b_patch_1_5_flac.c" 00035 #include "Patches/VS1053b_patch_1_4_flac.c" 00036 #include "Patches/VS1053b_specana_0_9.c" 00037 #include "Patches/VS1053b_pcm_recorder_0_9.c" 00038 00039 const char VS1053::_sampleRateTable[4][4] = { 00040 11, 12, 8, 0, 00041 11, 12, 8, 0, 00042 22, 24, 16, 0, 00043 44, 48, 32, 0 00044 }; 00045 00046 /* ================================================================== 00047 * Constructor 00048 * =================================================================*/ 00049 VS1053::VS1053( 00050 PinName mosi, PinName miso, PinName sck, PinName cs, PinName rst, 00051 PinName dreq, PinName dcs, char* buffer, int buffer_size) 00052 : 00053 _spi(mosi, miso, sck), 00054 _CS(cs), 00055 _RST(rst), 00056 _DCS(dcs), 00057 _DREQ(dreq), 00058 _DREQ_INTERUPT_IN(dreq) 00059 { 00060 _volume = DEFAULT_VOLUME; 00061 _balance = DEFAULT_BALANCE_DIFERENCE_LEFT_RIGHT; 00062 _sb_amplitude = DEFAULT_BASS_AMPLITUDE; 00063 _sb_freqlimit = DEFAULT_BASS_FREQUENCY; 00064 _st_amplitude = DEFAULT_TREBLE_AMPLITUDE; 00065 _st_freqlimit = DEFAULT_TREBLE_FREQUENCY; 00066 _buffer = buffer; 00067 BUFFER_SIZE = buffer_size; 00068 _DREQ_INTERUPT_IN.mode(PullDown); 00069 INTERRUPT_HANDLER_DISABLE; 00070 bufferReset(); 00071 } 00072 00073 00074 /*=================================================================== 00075 * Functions 00076 *==================================================================*/ 00077 00078 void VS1053::cs_low(void) { 00079 _CS = 0; 00080 } 00081 void VS1053::cs_high(void) { 00082 _CS = 1; 00083 } 00084 void VS1053::dcs_low(void) { 00085 _DCS = 0; 00086 00087 } 00088 void VS1053::dcs_high(void) { 00089 _DCS = 1; 00090 } 00091 void VS1053::sci_en(void) { //SCI enable 00092 cs_high(); 00093 dcs_high(); 00094 cs_low(); 00095 } 00096 void VS1053::sci_dis(void) { //SCI disable 00097 cs_high(); 00098 } 00099 void VS1053::sdi_en(void) { //SDI enable 00100 dcs_high(); 00101 cs_high(); 00102 dcs_low(); 00103 } 00104 void VS1053::sdi_dis(void) { //SDI disable 00105 dcs_high(); 00106 } 00107 void VS1053::reset(void) { //hardware reset 00108 INTERRUPT_HANDLER_DISABLE; 00109 wait_ms(10); 00110 _RST = 0; 00111 wait_ms(5); 00112 _RST = 1; 00113 wait_ms(10); 00114 } 00115 void VS1053::power_down(void) { //hardware and software reset 00116 cs_low(); 00117 reset(); 00118 // sci_write(0x00, SM_PDOWN); 00119 sci_write(0x00, 0x10); // tempo 00120 wait(0.01); 00121 reset(); 00122 } 00123 void VS1053::spi_initialise(void) { 00124 _RST = 1; //no reset 00125 _spi.format(8,0); //spi 8bit interface, steady state low 00126 // _spi.frequency(1000000); //rising edge data record, freq. 1Mhz 00127 _spi.frequency(2000000); //rising edge data record, freq. 2Mhz 00128 00129 00130 cs_low(); 00131 for (int i=0; i<4; i++) { 00132 _spi.write(0xFF); //clock the chip a bit 00133 } 00134 cs_high(); 00135 dcs_high(); 00136 wait_us(5); 00137 } 00138 void VS1053::sdi_initialise(void) { 00139 _spi.frequency(8000000); //set to 8 MHz to make fast transfer 00140 cs_high(); 00141 dcs_high(); 00142 } 00143 void VS1053::sci_write(unsigned char address, unsigned short int data) { 00144 // TODO disable all interrupts 00145 __disable_irq(); 00146 sci_en(); //enables SCI/disables SDI 00147 00148 while (!_DREQ); //wait unitl data request is high 00149 _spi.write(0x02); //SCI write 00150 _spi.write(address); //register address 00151 _spi.write((data >> 8) & 0xFF); //write out first half of data word 00152 _spi.write(data & 0xFF); //write out second half of data word 00153 00154 sci_dis(); //enables SDI/disables SCI 00155 wait_us(5); 00156 00157 // TODO enable all interrupts 00158 __enable_irq(); 00159 } 00160 void VS1053::sdi_write(unsigned char datum) { 00161 00162 sdi_en(); 00163 00164 while (!_DREQ); 00165 _spi.write(datum); 00166 00167 sdi_dis(); 00168 } 00169 unsigned short VS1053::sci_read(unsigned short int address) { 00170 // TODO disable all interrupts 00171 __disable_irq(); 00172 00173 cs_low(); //enables SCI/disables SDI 00174 00175 while (!_DREQ); //wait unitl data request is high 00176 _spi.write(0x03); //SCI write 00177 _spi.write(address); //register address 00178 unsigned short int received = _spi.write(0x00); //write out dummy byte 00179 received <<= 8; 00180 received |= _spi.write(0x00); //write out dummy byte 00181 00182 cs_high(); //enables SDI/disables SCI 00183 00184 // TODO enable all interrupts 00185 __enable_irq(); 00186 return received; //return received word 00187 } 00188 void VS1053::sine_test_activate(unsigned char wave) { 00189 cs_high(); //enables SDI/disables SCI 00190 00191 while (!_DREQ); //wait unitl data request is high 00192 _spi.write(0x53); //SDI write 00193 _spi.write(0xEF); //SDI write 00194 _spi.write(0x6E); //SDI write 00195 _spi.write(wave); //SDI write 00196 _spi.write(0x00); //filler byte 00197 _spi.write(0x00); //filler byte 00198 _spi.write(0x00); //filler byte 00199 _spi.write(0x00); //filler byte 00200 00201 cs_low(); //enables SCI/disables SDI 00202 } 00203 void VS1053::sine_test_deactivate(void) { 00204 cs_high(); 00205 00206 while (!_DREQ); 00207 _spi.write(0x45); //SDI write 00208 _spi.write(0x78); //SDI write 00209 _spi.write(0x69); //SDI write 00210 _spi.write(0x74); //SDI write 00211 _spi.write(0x00); //filler byte 00212 _spi.write(0x00); //filler byte 00213 _spi.write(0x00); //filler byte 00214 _spi.write(0x00); //filler byte 00215 } 00216 00217 unsigned short int VS1053::wram_read(unsigned short int address) { 00218 unsigned short int tmp1,tmp2; 00219 sci_write(SCI_WRAMADDR,address); 00220 tmp1=sci_read(SCI_WRAM); 00221 sci_write(SCI_WRAMADDR,address); 00222 tmp2=sci_read(SCI_WRAM); 00223 if (tmp1==tmp2) return tmp1; 00224 sci_write(SCI_WRAMADDR,address); 00225 tmp1=sci_read(SCI_WRAM); 00226 if (tmp1==tmp2) return tmp1; 00227 sci_write(SCI_WRAMADDR,address); 00228 tmp1=sci_read(SCI_WRAM); 00229 if (tmp1==tmp2) return tmp1; 00230 return tmp1; 00231 } 00232 00233 void VS1053::wram_write(unsigned short int address, unsigned short int data) { 00234 sci_write(SCI_WRAMADDR,address); 00235 sci_write(SCI_WRAM,data); 00236 return; 00237 } 00238 00239 void VS1053::setPlaySpeed(unsigned short speed) 00240 { 00241 wram_write(para_playSpeed, speed); 00242 DEBUGOUT("VS1053b: Change speed. New speed: %d\r\n", speed); 00243 } 00244 00245 void VS1053::terminateStream(void) { 00246 while(bufferCount() > 0) 00247 ; 00248 DEBUGOUT("VS1053b: Song terminating..\r\n"); 00249 // send at least 2052 bytes of endFillByte[7:0]. 00250 // read endFillByte (0 .. 15) from wram 00251 unsigned short endFillByte=wram_read(para_endFillByte); 00252 // clear endFillByte (8 .. 15) 00253 endFillByte = endFillByte ^0x00FF; 00254 for (int n = 0; n < 2052; n++) 00255 sdi_write(endFillByte); 00256 00257 // set SCI MODE bit SM CANCEL 00258 unsigned short sciModeByte = sci_read(SCI_MODE); 00259 sciModeByte |= SM_CANCEL; 00260 sci_write(SCI_MODE, sciModeByte); 00261 00262 // send up 2048 bytes of endFillByte[7:0]. 00263 for (int i = 0; i < 64; i++) 00264 { 00265 // send at least 32 bytes of endFillByte[7:0] 00266 for (int n = 0; n < 32; n++) 00267 sdi_write(endFillByte); 00268 // read SCI MODE; if SM CANCEL is still set, repeat 00269 sciModeByte = sci_read(SCI_MODE); 00270 if ((sciModeByte & SM_CANCEL) == 0x0000) 00271 { 00272 break; 00273 } 00274 } 00275 00276 if ((sciModeByte & SM_CANCEL) == 0x0000) 00277 { 00278 DEBUGOUT("VS1053b: Song sucessfully sent. Terminating OK\r\n"); 00279 DEBUGOUT("VS1053b: SCI MODE = %#x, SM_CANCEL = %#x\r\n", sciModeByte, sciModeByte & SM_CANCEL); 00280 sci_write(SCI_DECODE_TIME, 0x0000); 00281 } 00282 else 00283 { 00284 DEBUGOUT("VS1053b: SM CANCEL hasn't cleared after sending 2048 bytes, do software reset\r\n"); 00285 DEBUGOUT("VS1053b: SCI MODE = %#x, SM_CANCEL = %#x\r\n", sciModeByte, sciModeByte & SM_CANCEL); 00286 initialize(); 00287 } 00288 } 00289 00290 void VS1053::write_plugin(const unsigned short *plugin, unsigned int len) { 00291 unsigned int i; 00292 unsigned short addr, n, val; 00293 00294 for (i=0; i<len;) { 00295 addr = plugin[i++]; 00296 n = plugin[i++]; 00297 if (n & 0x8000U) { //RLE run, replicate n samples 00298 n &= 0x7FFF; 00299 val = plugin[i++]; 00300 while (n--) { 00301 sci_write(addr,val); 00302 } 00303 } else { //copy run, copy n sample 00304 while (n--) { 00305 val = plugin[i++]; 00306 sci_write(addr,val); 00307 } 00308 } 00309 } 00310 00311 return; 00312 } 00313 00314 00315 bool VS1053::initialize(void) { 00316 _RST = 1; 00317 cs_high(); //chip disabled 00318 spi_initialise(); //initialise MBED 00319 00320 sci_write(SCI_MODE, (SM_SDINEW+SM_RESET)); // set mode reg. 00321 wait_ms(10); 00322 00323 #ifdef DEBUG 00324 unsigned int info = wram_read(para_chipID_0); 00325 DEBUGOUT("VS1053b: ChipID_0:%04X\r\n", info); 00326 info = wram_read(para_chipID_1); 00327 DEBUGOUT("VS1053b: ChipID_1:%04X\r\n", info); 00328 info = wram_read(para_version); 00329 DEBUGOUT("VS1053b: Structure version:%04X\r\n", info); 00330 #endif 00331 00332 //get chip version, set clock multiplier and load patch 00333 int i = (sci_read(SCI_STATUS) & 0xF0) >> 4; 00334 if (i == 4) { 00335 00336 DEBUGOUT("VS1053b: Installed Chip is: VS1053\r\n"); 00337 00338 sci_write(SCI_CLOCKF, (SC_MULT_XTALIx50)); 00339 wait_ms(10); 00340 #ifdef VS_PATCH 00341 // loading patch 00342 write_plugin(vs1053b_patch, sizeof(vs1053b_patch)/2); 00343 00344 DEBUGOUT("VS1053b: Patch is loaded.\r\n"); 00345 DEBUGOUT("VS1053b: Patch size:%d bytes\r\n",sizeof(vs1053b_patch)); 00346 00347 #endif // VS_PATCH 00348 } 00349 else 00350 { 00351 DEBUGOUT("VS1053b: Not Supported Chip\r\n"); 00352 return false; 00353 } 00354 00355 // change spi to higher speed 00356 sdi_initialise(); 00357 changeVolume(); 00358 changeBass(); 00359 _isIdle = true; 00360 return true; 00361 } 00362 00363 void VS1053::setVolume(float vol) 00364 { 00365 if (vol > -0.5) 00366 _volume = -0.5; 00367 else 00368 _volume = vol; 00369 00370 changeVolume(); 00371 } 00372 00373 float VS1053::getVolume(void) 00374 { 00375 return _volume; 00376 } 00377 00378 void VS1053::setBalance(float balance) 00379 { 00380 _balance = balance; 00381 00382 changeVolume(); 00383 } 00384 00385 float VS1053::getBalance(void) 00386 { 00387 return _balance; 00388 } 00389 00390 void VS1053::changeVolume(void) 00391 { 00392 // volume calculation 00393 unsigned short volCalced = (((char)(_volume / -0.5f)) << 8) + (char)((_volume - _balance) / -0.5f); 00394 00395 sci_write(SCI_VOL, volCalced); 00396 00397 DEBUGOUT("VS1053b: Change volume to %#x (%f, Balance = %f)\r\n", volCalced, _volume, _balance); 00398 } 00399 00400 int VS1053::getTrebleFrequency(void) 00401 { 00402 return _st_freqlimit * 1000; 00403 } 00404 00405 00406 void VS1053::setTrebleFrequency(int frequency) 00407 { 00408 frequency /= 1000; 00409 00410 if(frequency < 1) 00411 { 00412 frequency = 1; 00413 } 00414 else if(frequency > 15) 00415 { 00416 frequency = 15; 00417 } 00418 _st_freqlimit = frequency; 00419 changeBass(); 00420 } 00421 00422 int VS1053::getTrebleAmplitude(void) 00423 { 00424 return _st_amplitude; 00425 } 00426 00427 void VS1053::setTrebleAmplitude(int amplitude) 00428 { 00429 if(amplitude < -8) 00430 { 00431 amplitude = -8; 00432 } 00433 else if(amplitude > 7) 00434 { 00435 amplitude = 7; 00436 } 00437 _st_amplitude = amplitude; 00438 changeBass(); 00439 } 00440 00441 int VS1053::getBassFrequency(void) 00442 { 00443 return _sb_freqlimit * 10; 00444 } 00445 00446 void VS1053::setBassFrequency(int frequency) 00447 { 00448 frequency /= 10; 00449 00450 if(frequency < 2) 00451 { 00452 frequency = 2; 00453 } 00454 else if(frequency > 15) 00455 { 00456 frequency = 15; 00457 } 00458 _sb_freqlimit = frequency; 00459 changeBass(); 00460 } 00461 00462 int VS1053::getBassAmplitude(void) 00463 { 00464 return _sb_amplitude; 00465 } 00466 00467 void VS1053::setBassAmplitude(int amplitude) 00468 { 00469 if(amplitude < -15) 00470 { 00471 amplitude = -15; 00472 } 00473 else if(amplitude > 0) 00474 { 00475 amplitude = 0; 00476 } 00477 _sb_amplitude = amplitude; 00478 changeBass(); 00479 } 00480 00481 void VS1053::changeBass(void) 00482 { 00483 unsigned short bassCalced = ((_st_amplitude & 0x0f) << 12) 00484 | ((_st_freqlimit & 0x0f) << 8) 00485 | ((_sb_amplitude & 0x0f) << 4) 00486 | ((_sb_freqlimit & 0x0f) << 0); 00487 00488 sci_write(SCI_BASS, bassCalced); 00489 00490 DEBUGOUT("VS1053b: Change bass settings to:\r\n") 00491 DEBUGOUT("VS1053b: --Treble: Amplitude=%i, Frequency=%i\r\n", getTrebleAmplitude(), getTrebleFrequency()); 00492 DEBUGOUT("VS1053b: --Bass: Amplitude=%i, Frequency=%i\r\n", getBassAmplitude(), getBassFrequency()); 00493 } 00494 00495 /*=================================================================== 00496 * Buffer handling 00497 *==================================================================*/ 00498 00499 unsigned int VS1053::bufferLength(void) 00500 { 00501 return BUFFER_SIZE; 00502 } 00503 00504 unsigned char VS1053::bufferGetByte(void) 00505 { 00506 unsigned char retVal = 0x00; 00507 if (bufferCount() > 0x00) 00508 { 00509 retVal = *_bufferReadPointer++; 00510 if (_bufferReadPointer >= _buffer + BUFFER_SIZE) 00511 { 00512 _bufferReadPointer = _buffer; 00513 } 00514 } 00515 return retVal; 00516 } 00517 00518 bool VS1053::bufferSetByte(char c) 00519 { 00520 if (bufferFree() > 0x00) 00521 { 00522 *_bufferWritePointer++ = c; 00523 if (_bufferWritePointer >= _buffer + BUFFER_SIZE) 00524 { 00525 _bufferWritePointer = _buffer; 00526 } 00527 return true; 00528 } 00529 return false; 00530 } 00531 00532 bool VS1053::bufferPutStream(const char *s, unsigned int length) 00533 { 00534 if (bufferFree() >= length) 00535 { 00536 while (length--) 00537 { 00538 *_bufferWritePointer++ = *s++; 00539 if (_bufferWritePointer >= _buffer + BUFFER_SIZE) 00540 { 00541 _bufferWritePointer = _buffer; 00542 } 00543 } 00544 return true; 00545 } 00546 return false; 00547 } 00548 00549 unsigned int VS1053::bufferFree(void) 00550 { 00551 if(_bufferReadPointer > _bufferWritePointer) 00552 { 00553 return _bufferReadPointer - _bufferWritePointer - 1; 00554 } 00555 else if(_bufferReadPointer < _bufferWritePointer) 00556 { 00557 return BUFFER_SIZE - (_bufferWritePointer - _bufferReadPointer) - 1; 00558 } 00559 return BUFFER_SIZE - 1; 00560 } 00561 00562 unsigned int VS1053::bufferCount(void) 00563 { 00564 return BUFFER_SIZE - bufferFree() - 1; 00565 } 00566 00567 void VS1053::bufferReset(void) 00568 { 00569 _bufferReadPointer = _buffer; 00570 _bufferWritePointer = _buffer; 00571 } 00572 00573 00574 void VS1053::dataRequestHandler(void) 00575 { 00576 if (_isIdle && _DREQ) 00577 { 00578 _isIdle = false; 00579 // write buffer to vs1053b 00580 unsigned length = bufferCount(); 00581 int i = 0; 00582 sdi_en(); 00583 00584 while (length > 0) 00585 { 00586 int l2 = (length > 32) ? 32 : length; 00587 //DEBUGOUT("L2: %i\r\n", l2); 00588 for( ; l2 != 0; l2--) 00589 { 00590 _spi.write(bufferGetByte()); 00591 } 00592 00593 length -= l2; 00594 00595 if (!_DREQ || i > 4) 00596 break; 00597 i++; 00598 } 00599 00600 sdi_dis(); 00601 00602 _isIdle = true; 00603 } 00604 } 00605 00606 void VS1053::play(void) 00607 { 00608 INTERRUPT_HANDLER_ENABLE; 00609 DEBUGOUT("VS1053b: Play.\r\n"); 00610 } 00611 00612 void VS1053::pause(void) 00613 { 00614 INTERRUPT_HANDLER_DISABLE; 00615 DEBUGOUT("VS1053b: Pause.\r\n"); 00616 } 00617 00618 void VS1053::stop(void) 00619 { 00620 INTERRUPT_HANDLER_DISABLE; 00621 __disable_irq(); 00622 DEBUGOUT("VS1053b: Song stoping..\r\n"); 00623 while(!_isIdle) 00624 ; 00625 00626 // set SCI MODE bit SM CANCEL 00627 unsigned short sciModeByte = sci_read(SCI_MODE); 00628 sciModeByte |= SM_CANCEL; 00629 sci_write(SCI_MODE, sciModeByte); 00630 00631 // send up 2048 bytes of audio data. 00632 for (int i = 0; i < 64; i++) 00633 { 00634 // send at least 32 bytes of audio data 00635 int z = bufferCount(); 00636 if (z > 32) 00637 z = 32; 00638 for (int n = 0; n < z; n++) 00639 { 00640 _spi.write(bufferGetByte()); 00641 } 00642 // read SCI MODE; if SM CANCEL is still set, repeat 00643 sciModeByte = sci_read(SCI_MODE); 00644 if ((sciModeByte & SM_CANCEL) == 0x0000) 00645 { 00646 break; 00647 } 00648 } 00649 00650 if ((sciModeByte & SM_CANCEL) == 0x0000) 00651 { 00652 // send at least 2052 bytes of endFillByte[7:0]. 00653 // read endFillByte (0 .. 15) from wram 00654 unsigned short endFillByte=wram_read(para_endFillByte); 00655 // clear endFillByte (8 .. 15) 00656 endFillByte = endFillByte ^0x00FF; 00657 for (int n = 0; n < 2052; n++) 00658 sdi_write(endFillByte); 00659 DEBUGOUT("VS1053b: Song sucessfully stopped.\r\n"); 00660 DEBUGOUT("VS1053b: SCI MODE = %#x, SM_CANCEL = %#x\r\n", sciModeByte, sciModeByte & SM_CANCEL); 00661 sci_write(SCI_DECODE_TIME, 0x0000); 00662 } 00663 else 00664 { 00665 DEBUGOUT("VS1053b: SM CANCEL hasn't cleared after sending 2048 bytes, do software reset\r\n"); 00666 DEBUGOUT("VS1053b: SCI MODE = %#x, SM_CANCEL = %#x\r\n", sciModeByte, sciModeByte & SM_CANCEL); 00667 initialize(); 00668 } 00669 00670 bufferReset(); 00671 __enable_irq(); 00672 } 00673 00674 void VS1053::getAudioInfo(AudioInfo* aInfo) 00675 { 00676 // volume calculation 00677 unsigned short hdat0 = sci_read(SCI_HDAT0); 00678 unsigned short hdat1 = sci_read(SCI_HDAT1); 00679 00680 DEBUGOUT("VS1053b: Audio info\r\n"); 00681 00682 AudioInfo* retVal = aInfo; 00683 retVal->type = UNKNOWN; 00684 00685 if (hdat1 == 0x7665) 00686 { 00687 // audio is WAV 00688 retVal->type = WAV; 00689 } 00690 else if (hdat1 == 0x4154 || hdat1 == 0x4144 || hdat1 == 0x4D34 ) 00691 { 00692 // audio is AAC 00693 retVal->type = AAC; 00694 } 00695 else if (hdat1 == 0x574D ) 00696 { 00697 // audio is WMA 00698 retVal->type = WMA; 00699 } 00700 else if (hdat1 == 0x4D54 ) 00701 { 00702 // audio is MIDI 00703 retVal->type = MIDI; 00704 } 00705 else if (hdat1 == 0x4F76 ) 00706 { 00707 // audio is OGG VORBIS 00708 retVal->type = OGG_VORBIS; 00709 } 00710 else if (hdat1 >= 0xFFE0 && hdat1 <= 0xFFFF) 00711 { 00712 // audio is mp3 00713 retVal->type = MP3; 00714 00715 DEBUGOUT("VS1053b: Audio is mp3\r\n"); 00716 retVal->ext.mp3 .id = (MP3_ID)((hdat1 >> 3) & 0x0003); 00717 switch((hdat1 >> 1) & 0x0003) 00718 { 00719 case 3: 00720 retVal->ext.mp3 .layer = 1; 00721 break; 00722 case 2: 00723 retVal->ext.mp3 .layer = 2; 00724 break; 00725 case 1: 00726 retVal->ext.mp3 .layer = 3; 00727 break; 00728 default: 00729 retVal->ext.mp3 .layer = 0; 00730 break; 00731 } 00732 retVal->ext.mp3 .protrectBit = (hdat1 >> 0) & 0x0001; 00733 00734 char srate = (hdat0 >> 10) & 0x0003; 00735 retVal->ext.mp3 .kSampleRate = _sampleRateTable[retVal->ext.mp3 .id][srate]; 00736 00737 retVal->ext.mp3 .padBit = (hdat0 >> 9) & 0x0001; 00738 retVal->ext.mp3 .mode =(MP3_MODE)((hdat0 >> 6) & 0x0003); 00739 retVal->ext.mp3 .extension = (hdat0 >> 4) & 0x0003; 00740 retVal->ext.mp3 .copyright = (hdat0 >> 3) & 0x0001; 00741 retVal->ext.mp3 .original = (hdat0 >> 2) & 0x0001; 00742 retVal->ext.mp3 .emphasis = (hdat0 >> 0) & 0x0003; 00743 00744 DEBUGOUT("VS1053b: ID: %i, Layer: %i, Samplerate: %i, Mode: %i\r\n", retVal->ext.mp3 .id, retVal->ext.mp3 .layer, retVal->ext.mp3 .kSampleRate, retVal->ext.mp3 .mode); 00745 } 00746 00747 // read byteRate 00748 unsigned short byteRate = wram_read(para_byteRate); 00749 retVal->kBitRate = (byteRate * 8) / 1000; 00750 DEBUGOUT("VS1053b: BitRate: %i kBit/s\r\n", retVal->kBitRate ); 00751 00752 // decode time 00753 retVal->decodeTime = sci_read(SCI_DECODE_TIME); 00754 DEBUGOUT("VS1053b: Decodetime: %i s\r\n", retVal->decodeTime ); 00755 00756 }
Generated on Sun Jul 17 2022 15:50:53 by
1.7.2