MP3 help, running slow
science_geek
Posts: 247
im using the vs1002 mp3 decoder chip with the vs1002 object from obex, i have it up and running, but it is running very very slow, i have tried changing the clock variable but it doesnt do anything, here is the example code im using
CON
··· _clkmode = xtal1 + pll16x
··· _xinfreq = 5_000_000
VAR
··· Byte SDBuffer[noparse][[/noparse]32]
··· Long Stack2[noparse][[/noparse]1000]
OBJ
· MP3 : "vs1002 mp3"
· sdfat : "fsrw"
PUB Start | Bytes, Read, Count, Poss
· MP3.start (0,1,2,3,4)········ ' Start mp3 object·
· dira[noparse][[/noparse]5]~
····
· sdfat.mount(8)
· sdfat.popen(string("CRUSADE.mp3"), "r")············· ' <<-- Change mp3 file name here.
· MP3.WriteReg(1,300000)································ ' <<-- Set clock devider. This is verry improtant, if you do not it will play very slowly
· MP3.SetVolume(80,0)························································· ' Volume defalts to zero on startup, so it must be set.
· DataOut
PUB DataOut | Bytes, Read, Count, Poss········
· repeat
··· if ina[noparse][[/noparse]5] == 1
····· Poss += sdfat.pread(@SDBuffer,32)
·······················································
····· Count~
····· if Bytes <· 32
······· repeat Bytes
········· MP3.WriteDataByte(SDBuffer[noparse][[/noparse]Read++])
······· quit·······
····· MP3.WriteDataBuffer(@SDBuffer)
CON
··· _clkmode = xtal1 + pll16x
··· _xinfreq = 5_000_000
VAR
··· Byte SDBuffer[noparse][[/noparse]32]
··· Long Stack2[noparse][[/noparse]1000]
OBJ
· MP3 : "vs1002 mp3"
· sdfat : "fsrw"
PUB Start | Bytes, Read, Count, Poss
· MP3.start (0,1,2,3,4)········ ' Start mp3 object·
· dira[noparse][[/noparse]5]~
····
· sdfat.mount(8)
· sdfat.popen(string("CRUSADE.mp3"), "r")············· ' <<-- Change mp3 file name here.
· MP3.WriteReg(1,300000)································ ' <<-- Set clock devider. This is verry improtant, if you do not it will play very slowly
· MP3.SetVolume(80,0)························································· ' Volume defalts to zero on startup, so it must be set.
· DataOut
PUB DataOut | Bytes, Read, Count, Poss········
· repeat
··· if ina[noparse][[/noparse]5] == 1
····· Poss += sdfat.pread(@SDBuffer,32)
·······················································
····· Count~
····· if Bytes <· 32
······· repeat Bytes
········· MP3.WriteDataByte(SDBuffer[noparse][[/noparse]Read++])
······· quit·······
····· MP3.WriteDataBuffer(@SDBuffer)
Comments
I don't have a VS1002, and have not used the mp3 object, but I'm guessing the reason it's slow I the SD side of your code, so try having a 512 byte SDBuffer, and reading 512 bytes at a time, as it's a lot faster reading 512byte block from SD [noparse];)[/noparse]
Baggers.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
http://www.propgfx.co.uk/forum/·home of the PropGFX Lite
·
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
http://www.propgfx.co.uk/forum/·home of the PropGFX Lite
·
Baggers gave you a great tip and example:
I used that chip no problem with a PIC micro and C . I didn't have any speed problems. Part of a C demo/ example is below (to show buffer size that I used)
=======================================================================================================
unsigned long i, file_size;
char data_buffer_32[noparse][[/noparse]32];
const BUFFER_SIZE = 512;
char BufferLarge[noparse][[/noparse]BUFFER_SIZE];
char volume_left, volume_right;
========================
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Aka: CosmicBob
If that's not fast enough you might try two cogs, one devoted to reading the
SD card, another one devoted to feeding the MP3 chip, using a circular
buffer (say 4K or some such).
To me this sounds like a clock speed issue. In your code you have:
This does nothing to the clock divider register. You need to write the clock divider to register 3 of the vs1002.
Using that formula you can correctly figure out the clock divider for any given crystal. Most boards that use the vs1002 use a 12.288Mhz crystal. Because this speed is less then the desired 24.576Mhz you have to use the clock doubler, that makes your clock speed 24.576Mhz. So using the formula we have 24576000Hz / 2000 = 12288. Then we set the MSB (that is the 16th bit) and we get 45056 or $B000.
Now if you set the clock divider register to that, like this:
I think that you should be able to get it to play at the right speed
-Kit
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
PHRED, FIRST Team 847, Member
Go -> PHRED
Bob, Thanks [noparse]:)[/noparse]
science_geek, let us know if you finally get it working [noparse];)[/noparse]
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
http://www.propgfx.co.uk/forum/·home of the PropGFX Lite
·
Post Edited (science_geek) : 9/22/2008 5:56:32 PM GMT