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.
Dependents: Lab3_1 RTOS-VS1053b-mp3_semaphore RTOS-VS1053b-mp3_v01
Diff: VS1053.cpp
- Revision:
- 6:eed008905159
- Parent:
- 5:ead95c0f7800
- Child:
- 8:5e4a21202223
--- a/VS1053.cpp Sat Dec 25 00:29:04 2010 +0000
+++ b/VS1053.cpp Sat Jan 08 15:45:58 2011 +0000
@@ -36,12 +36,12 @@
#include "Patches/VS1053b_specana_0_9.c"
#include "Patches/VS1053b_pcm_recorder_0_9.c"
-
-void test(void)
-{
-// DEBUGOUT("Interupt\r\n");
-}
-
+const char VS1053::_sampleRateTable[4][4] = {
+ 11, 12, 8, 0,
+ 11, 12, 8, 0,
+ 22, 24, 16, 0,
+ 44, 48, 32, 0
+};
/* ==================================================================
* Constructor
@@ -274,12 +274,12 @@
{
DEBUGOUT("VS1053b: Song sucessfully sent. Terminating OK\r\n");
DEBUGOUT("VS1053b: SCI MODE = %#x, SM_CANCEL = %#x\r\n", sciModeByte, sciModeByte & SM_CANCEL);
+ sci_write(SCI_DECODE_TIME, 0x0000);
}
else
{
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
+ DEBUGOUT("VS1053b: SCI MODE = %#x, SM_CANCEL = %#x\r\n", sciModeByte, sciModeByte & SM_CANCEL);
initialize();
}
}
@@ -650,15 +650,99 @@
sdi_write(endFillByte);
DEBUGOUT("VS1053b: Song sucessfully stopped.\r\n");
DEBUGOUT("VS1053b: SCI MODE = %#x, SM_CANCEL = %#x\r\n", sciModeByte, sciModeByte & SM_CANCEL);
+ sci_write(SCI_DECODE_TIME, 0x0000);
}
else
{
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
+ DEBUGOUT("VS1053b: SCI MODE = %#x, SM_CANCEL = %#x\r\n", sciModeByte, sciModeByte & SM_CANCEL);
initialize();
}
bufferReset();
__enable_irq();
+}
+
+void VS1053::getAudioInfo(AudioInfo* aInfo)
+{
+ // volume calculation
+ unsigned short hdat0 = sci_read(SCI_HDAT0);
+ unsigned short hdat1 = sci_read(SCI_HDAT1);
+
+ DEBUGOUT("VS1053b: Audio info\r\n");
+
+ AudioInfo* retVal = aInfo;
+ retVal->type = UNKNOWN;
+
+ if (hdat1 == 0x7665)
+ {
+ // audio is WAV
+ retVal->type = WAV;
+ }
+ else if (hdat1 == 0x4154 || hdat1 == 0x4144 || hdat1 == 0x4D34 )
+ {
+ // audio is AAC
+ retVal->type = AAC;
+ }
+ else if (hdat1 == 0x574D )
+ {
+ // audio is WMA
+ retVal->type = WMA;
+ }
+ else if (hdat1 == 0x4D54 )
+ {
+ // audio is MIDI
+ retVal->type = MIDI;
+ }
+ else if (hdat1 == 0x4F76 )
+ {
+ // audio is OGG VORBIS
+ retVal->type = OGG_VORBIS;
+ }
+ else if (hdat1 >= 0xFFE0 && hdat1 <= 0xFFFF)
+ {
+ // audio is mp3
+ retVal->type = MP3;
+
+ DEBUGOUT("VS1053b: Audio is mp3\r\n");
+ retVal->ext.mp3.id = (MP3_ID)((hdat1 >> 3) & 0x0003);
+ switch((hdat1 >> 1) & 0x0003)
+ {
+ case 3:
+ retVal->ext.mp3.layer = 1;
+ break;
+ case 2:
+ retVal->ext.mp3.layer = 2;
+ break;
+ case 1:
+ retVal->ext.mp3.layer = 3;
+ break;
+ default:
+ retVal->ext.mp3.layer = 0;
+ break;
+ }
+ retVal->ext.mp3.protrectBit = (hdat1 >> 0) & 0x0001;
+
+ char srate = (hdat0 >> 10) & 0x0003;
+ retVal->ext.mp3.kSampleRate = _sampleRateTable[retVal->ext.mp3.id][srate];
+
+ retVal->ext.mp3.padBit = (hdat0 >> 9) & 0x0001;
+ retVal->ext.mp3.mode =(MP3_MODE)((hdat0 >> 6) & 0x0003);
+ retVal->ext.mp3.extension = (hdat0 >> 4) & 0x0003;
+ retVal->ext.mp3.copyright = (hdat0 >> 3) & 0x0001;
+ retVal->ext.mp3.original = (hdat0 >> 2) & 0x0001;
+ retVal->ext.mp3.emphasis = (hdat0 >> 0) & 0x0003;
+
+ 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);
+ }
+
+ // read byteRate
+ unsigned short byteRate = wram_read(para_byteRate);
+ retVal->kBitRate = (byteRate * 8) / 1000;
+ DEBUGOUT("VS1053b: BitRate: %i kBit/s\r\n", retVal->kBitRate);
+
+ // decode time
+ retVal->decodeTime = sci_read(SCI_DECODE_TIME);
+ DEBUGOUT("VS1053b: Decodetime: %i s\r\n", retVal->decodeTime);
+
}
\ No newline at end of file