Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length



Pages: [1]
  Print  
Author Topic: Issues playing mp3s with a vs1053  (Read 923 times)
xt0rted
Newbie
*
Posts: 5


View Profile
« on: January 02, 2010, 04:38:46 AM »

I’m trying to use a VS1053 breakout board from sparkfun to play mp3s. I’m having some trouble getting this all to work though. I’ve copied the VS1002 class from the Embedded Master SDK and used the same method of sending data as in the MP3Example class but I don’t get audio. The method to send a sine wave works, but sending an mp3 file doesn’t.

I had tried a number of mp3 files at different bitrates but none of them would play back. After some testing I found that changing the value the chip is initialized with from 0x800 to 0xC00 allowed me to hear a 16kbps mp3 clearly and would play through to the end. When I try a 128kbps mp3 I’ll get anywhere from 1-4 seconds of audio, and then it cuts off and I’ll get a low clicking type noise until data is finished being sent to the chip.

I’ve tried adapting the VS1053 class from the ChipworkX SDK but I’m very new to this type of programming and not very familiar with this hardware so I’m not really sure what I need to change to get it to work with this board. Here’s my modified VS1002 class as well as the code I’m using to play a file.

Code:
private const int BufferLength = 2048;
static byte[] Buffer = new byte[BufferLength];

private static void PlayMusic()
{
    Directory.SetCurrentDirectory(@"\USB0\Test");
    var FileName = "440Hz_44100Hz_16bit_30sec.mp3";

    VS1002.Initialize();

    using (var file = File.Open(FileName, FileMode.Open, FileAccess.Read))
    {
        var read = 0;
        do
        {
            read = file.Read(Buffer, 0, BufferLength);
            VS1002.SendData(Buffer);
        } while (read > 0);
    }
}

Code:
public static class VS1002
{
    static private SPI.Configuration conf = new SPI.Configuration(Cpu.Pin.GPIO_NONE, false, 0, 0, false, true, 3000, SPI.SPI_module.SPI1);
    static private SPI mySPI;
    static private OutputPort SCI;
    static private OutputPort SDI;
    static private OutputPort RESET;
    static private InputPort DREQ;
    static private bool isInitialized = false;
    static private byte[] block = new byte[32];
    static private byte SPIWriteReadByte(byte ch)
    {
        byte[] CH = new byte[1];
        byte[] CH1 = new byte[1];
        CH[0] = ch;
        mySPI.WriteRead(CH, CH1);
        return CH1[0];
    }
    static public void SCI_Write(Byte address, UInt16 data)
    {
        SCI.Write(false);
        Thread.Sleep(10);
        SPIWriteReadByte(0x02);
        SPIWriteReadByte(address);
        SPIWriteReadByte((byte)(data >> 8));
        SPIWriteReadByte((byte)data);
        SCI.Write(true);
    }
    static public UInt16 SCI_Read(byte address)
    {
        UInt16 temp;
        SCI.Write(false);
        Thread.Sleep(10);
        SPIWriteReadByte(0x03);
        SPIWriteReadByte(address);
        temp = SPIWriteReadByte(0);
        temp <<= 8;
        temp += SPIWriteReadByte(0);
        SCI.Write(true);
        return temp;
    }

    // Let VS1002 sends Sine Wave for testing purposes.
    static public void SendSineWaveP(Byte pitch)
    {
        SCI_Write(0, 0x0c20);
        SDI.Write(false);
        Thread.Sleep(10);
        SPIWriteReadByte(0x53);
        SPIWriteReadByte(0xEF);
        SPIWriteReadByte(0x6E);
        SPIWriteReadByte(pitch);
        SPIWriteReadByte(0);
        SPIWriteReadByte(0);
        SPIWriteReadByte(0);
        SPIWriteReadByte(0);
        SDI.Write(true);
        Thread.Sleep(10);
    }
    public static void Shutdown()
    {
        SCI.Dispose();
        SDI.Dispose();
        RESET.Dispose();
        DREQ.Dispose();
        mySPI.Dispose();
        isInitialized = false;
    }

    public static void Initialize()
    {
        // Initialize Pins
        if (isInitialized)
            Shutdown();
        mySPI = new SPI(conf);
        SCI = new OutputPort(USBizi.Pins.E38x, false);
        SDI = new OutputPort(USBizi.Pins.E43x, false);
        RESET = new OutputPort(USBizi.Pins.E37x, false);
        DREQ = new InputPort(USBizi.Pins.E36x, false, Port.ResistorMode.PullUp);

        isInitialized = true;
        ////
        RESET.Write(false);
        SCI.Write(true);
        SDI.Write(true);
        Thread.Sleep(100);
        // delay 100ms
        RESET.Write(true);
        while (DREQ.Read() == false) ;
        Thread.Sleep(100);
        ////SCI_Write(0x00, 0x800);
        SCI_Write(0x00, 0xC00);
        SCI_Write(0x3, 0x98 << 8);

        Thread.Sleep(300);
        SCI_Write(0xB, 0x4B << 8 | 0x4B); // volume
        Thread.Sleep(300);
        if (SCI_Read(0xB) != (0x4B << 8 | 0x4B))
        {
            throw new Exception("Failed to initialize VS1002 encoder");
        }
    }

    public static void SendData(byte[] data)
    {
        Int32 size = data.Length - data.Length % 32;
        SDI.Write(false);
        for (int i = 0; i < size; i += 32)
        {
            while (DREQ.Read() == false) ; // wait till done
            Array.Copy(data, i, block, 0, 32);
            mySPI.Write(block);
        }
        SDI.Write(true);
    }
}

Logged
SupportAdmin
Administrator
Hero Member
*****
Posts: 5394



View Profile WWW
« Reply #1 on: January 02, 2010, 05:54:17 AM »

VS1053 is what we have on ChipworkX so the code from ChipworkX SDK should be what you need. You only need to change the IOs and SPI to where you have connected your MP3 decoder board. Note that you may have some issues with the hardware connections
Logged
support
Administrator
Sr. Member
*****
Posts: 473


View Profile
« Reply #2 on: January 02, 2010, 10:34:06 AM »

Or you have wrong configuration of the use SPI or GPIO.
Logged
xt0rted
Newbie
*
Posts: 5


View Profile
« Reply #3 on: January 02, 2010, 02:37:55 PM »

Here's how I have it wired to H2:

1   VCC
2   GND
3   DREQ
4   RESET
5   CS
6   GPIO0
7   SO
8   SI
9   SCLK
10 BSYNC
Logged
xt0rted
Newbie
*
Posts: 5


View Profile
« Reply #4 on: January 03, 2010, 02:36:00 AM »

I tried the VS1053 class from the ChipworkX SDK again and this time I got it working. In case anyone else wants to use this I left the class as-is and used pin 43 for dataConfig, 38 for cmdConfig, 37 for Reset and 36 for DREQ.

I think part of my issue before was that I was trying to read off the SD card. When I tried reading from a thumb drive it worked (limited since flac, wav and higher than 128k mp3s still aren’t playing right, if at all) but when I use the SD card all I get is a low clicking until the data is finished being sent.

I’m trying on 3 different cards from 3 different manufacturers too. I have a 2GB from PNY, 4GB SDHC from SanDisk and a 16GB SDHC from Kingston. The 16GB one keeps causing an exception when it tries to be mounted, but the other two mount fine. But then playing off them doesn’t work.
Logged
bavaria_blue
Newbie
*
Posts: 1


View Profile
« Reply #5 on: March 02, 2010, 02:06:29 PM »

I have also problems working with the Sparkfun VS1053 and Embedded Master Breakout... it plays about some second or nothing, then it's playing some noise. I tried various files, so I would like to check the connectors, since the SV7 pins are harder to solder than the other big pins on the embedded master breakout. ;-)

The SV7 pins should be identical with some of the pins on the side, right?
But for this I would need the exact mapping of these pins for the UART (SV7). I thought I have seen such a list in an user manual or somewhere else, but I opened all available documents and didn't find it (anymore?). The schematic does not mention Exx names, so I guess SV7 is the following:
1 = VCC
2 = GND
3 = E29
4 = E28
5 = E12
6 = E11
7= E25
8 = E24
9 = E50
10 = E49

Is that correct? And can I easily check on these pins instead of directly on UART, since its better to reach for me?
What would be the alternative pins xt0rted mentioned on Embedded Master Breakout?
E.g. E36 does not exist on Embedded Master Breakout, neither P0.36. And pin 36 would be GND from the TFT expansion...
Some little help would be great for my evaluation. Smiley
Logged
Pages: [1]
  Print  
 
Jump to: