Shop OBEX P1 Docs P2 Docs Learn Events
MP3 help, running slow — Parallax Forums

MP3 help, running slow

science_geekscience_geek Posts: 247
edited 2008-09-25 00:22 in Propeller 1
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)

Comments

  • BaggersBaggers Posts: 3,019
    edited 2008-09-21 21:42
    Hi science_geek,

    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

    ·
  • science_geekscience_geek Posts: 247
    edited 2008-09-21 21:48
    i cant use 512, because the vs1002 only accepts 32 bytes at a time, i can only put as many as it will take,
  • BaggersBaggers Posts: 3,019
    edited 2008-09-21 22:08
    yes, that's not a problem, just load 512 into the buffer, then do a loop ( 16 times ) to send the 32 bytes

    CON
        _clkmode = xtal1 + pll16x
        _xinfreq = 5_000_000
    VAR
        Byte SDBuffer[noparse][[/noparse]512]
        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~
         
      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 == 1
          Poss += sdfat.pread(@SDBuffer,512)
                                                            
          Count~
          repeat i from 0 to 15
            if Bytes <  32
              repeat Bytes
                MP3.WriteDataByte(SDBuffer[noparse][[/noparse] ( i << 5 ) + Read++])
              quit        
            MP3.WriteDataBuffer(@SDBuffer +  ( i << 5 ))
            Bytes-=32
    
    

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    http://www.propgfx.co.uk/forum/·home of the PropGFX Lite

    ·
  • Bob Lawrence (VE1RLL)Bob Lawrence (VE1RLL) Posts: 1,720
    edited 2008-09-21 22:39
    @science_geek

    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
  • rokickirokicki Posts: 1,000
    edited 2008-09-22 02:09
    You might even have better luck with a larger buffer size, such as 2048.

    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).
  • Kit MortonKit Morton Posts: 39
    edited 2008-09-22 03:28
    The fsrw is defiantly fast enough to be used with only a 32 byte buffer.

    To me this sounds like a clock speed issue. In your code you have:
    MP3.WriteReg(1,300000)
    


    This does nothing to the clock divider register. You need to write the clock divider to register 3 of the vs1002.
    vs1002 datasheet pages 28-29 said...
    SCI CLOCKF is used to tell if the input clock XTALI is running at something else than 24.576 MHz. XTALI is set in 2 kHz steps. Thus, the formula for calculating the correct value for this register is XTALI/2000 (XTALI is in Hz). Values may be between 0..32767, although hardware limits the highest allowed speed. Also, with speeds lower than 24.576 MHz all sample rates and bitstream widths are no longer available.

    Setting the MSB of SCI CLOCKF to 1 activates internal clock-doubling. A clock of upto 15 MHz may be doubled depending on the voltage provided to the chip.

    Note: SCI CLOCKF must be set before beginning decoding audio data; otherwise the sample rate will not be set correctly.

    Note: Unlike with VS1011, SCI CLOCKF only needs to be written to after a hardware reset.

    Example 1: For a 26 MHz clock the value would be 26000000/2000 = 13000.

    Example 2: For a 13 MHz external clock and using internal clock-doubling for a 26 MHz internal frequency, the value would be 0x8000 + 13000000/2000 = 39268.

    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:
    MP3.WriteReg(3,$B000)
    


    I think that you should be able to get it to play at the right speed

    -Kit

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    PHRED, FIRST Team 847, Member
    Go -> PHRED
  • BaggersBaggers Posts: 3,019
    edited 2008-09-22 10:56
    Ah, yeah that probably wouldn't help thanks Kit, like I said, I don't have an MP3 decoder chip, so wouldn't have known that was a fault.

    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

    ·
  • science_geekscience_geek Posts: 247
    edited 2008-09-22 17:50
    thanks alot kit for all your help with this but, its still playing slow, what pin am i supposed to send this to, could having something hooked up wrong so that its not getting told that line of code some how affect it

    Post Edited (science_geek) : 9/22/2008 5:56:32 PM GMT
  • science_geekscience_geek Posts: 247
    edited 2008-09-22 20:55
    ok, i have figured out something important, the vs1002 isnt getting the speed byte sent to it, i switched the name of the two variables and it had no effect, here is the code that im using, its the unchanged object obex, here is the vs1002 controller without the example
  • science_geekscience_geek Posts: 247
    edited 2008-09-25 00:22
    ok, after days of trial and error, and utter frustration i have it...not working, i was wondering if somebody could explain the assembly code portion of the code i attached early(as my asm code interp is...how you say...LACKING)
Sign In or Register to comment.