playing audio by specifying file name

Designing hardware that use VLSI Solution's devices as the system controller for the entire design.
Post Reply
akita11
User
Posts: 4
Joined: Mon 2017-06-12 13:57

playing audio by specifying file name

Post by akita11 » Mon 2017-06-12 14:10

Hi, I'm using VS1011e with player1011esci.bin firmware (ver1.18), which is feed from host MCU.
It works for file-number specified play, counting file numbers on SD, and other functions,
however, the playing by specifying file name always results in playing the first file on SD.

The code for playing is follows. The contents of filename written(1) and the read-out written file name(2) are identical, such as "12345678MP3". (I confirmed the char[] to word[] padding by the code descibed in "5.2 Reading the 8.3-character Filename" in standalone player's datasheet PDF. It is OK).
Although the result of VS_AICTRL0 register gets 0, which means OK (file located), but the contents of WRAM read is always the filename of the first file on SD, even if the specified filename is wrong (non-existing filename)

I appreciate any advice for modifying the code to operate correctly.

Code: Select all

// (1)writing filename
WriteVS10xxRegister(VS_WRAMADDR, 0x4780);
for (i = 0; i < 6; i++)  WriteVS10xxRegister(VS_WRAM, name[i]);

// (2)reading written filename
WriteVS10xxRegister(VS_WRAMADDR, 0x4780);
for (i = 0; i < 6; i++) uint16_t w = ReadVS10xxRegister(VS_WRAM);

WriteVS10xxRegister(VS_AICTRL3, (1 << 8) | 0x14); // set CTRL3_BY_NAME bit
WriteVS10xxRegister(VS_AICTRL0, 0xffff); // start
wait(1); // wait for a while
printf("result=%d\r\n", ReadVS10xxRegister(VS_AICTRL0)); // gets 0 (OK)

// (3)reading located filename
WriteVS10xxRegister(VS_WRAMADDR, 0x4780);
for (i = 0; i < 6; i++) uint16_t w = ReadVS10xxRegister(VS_WRAM);

User avatar
pasi
VLSI Staff
Posts: 1510
Joined: Thu 2010-07-15 16:04

Re: playing audio by specifying file name

Post by pasi » Mon 2017-06-12 15:41

Hi,

What are the exact values of your name[] array?

If the named file is not found, then the first file will be opened instead, and its name will then be copied to the fileName array.
Visit https://www.facebook.com/VLSISolution VLSI Solution on Facebook

akita11
User
Posts: 4
Joined: Mon 2017-06-12 13:57

Re: playing audio by specifying file name

Post by akita11 » Tue 2017-06-13 4:32

Thank you for your reply.
I'm generating name[] array by the MKWORD macro provided in datasheet from the specifying filename, fname[], as follows:

Code: Select all

#define MKWORD(a,b) (((int)(unsigned char)(a)<<8)|(unsigned char)(b))
unsigned short name[6] = {
    MKWORD(fname[0], fname[1]), MKWORD(fname[2], fname[3]),
    MKWORD(fname[4], fname[5]), MKWORD(fname[6], fname[7]),
    MKWORD(fname[8], fname[9]), MKWORD(fname[10], fname[11])
};
Here, fname[] is something like (this is a case which "1234567.mp3" is in SD):

Code: Select all

strcpy(fname, "1234567 MP3");
It is my misunderstanding that SCI_AICTRL0 will be non-zero when specified file located; will be zero when file not found. In my project, the SCI_AICTRL0 always becomes zero, which indicates the fname will be wrong.

User avatar
pasi
VLSI Staff
Posts: 1510
Joined: Thu 2010-07-15 16:04

Re: playing audio by specifying file name

Post by pasi » Tue 2017-06-13 10:52

Your filename "1234567 MP3" looks good, provided it is NUL-terminated and thus the low 8 bits of name[5] are 0.

File numbering starts from 0, so 0 is a valid file number.

The only thing that comes to mind is that the 8.3-character name is not what we expect. You could open the files by number and read out and print the filenames.
Visit https://www.facebook.com/VLSISolution VLSI Solution on Facebook

akita11
User
Posts: 4
Joined: Mon 2017-06-12 13:57

Re: playing audio by specifying file name

Post by akita11 » Wed 2017-06-14 8:09

I've tried to each play by song by specifying number (writing 0x8000+song number to AICTRL0), and then read 6 words from WRAM (at WRAMADDR 0x4780), and checked it as filename.
It was the actual filename (8.3 format) as I intended to play by specifying file name, so I believe the filename format would be OK.

I've checked the above procedure by the following code:

Code: Select all

while(1){
    WriteVS10xxRegister(0x0f, (3<<1)); // pause after play
    WriteVS10xxRegister(0x0c, 0x8000+s); // select song
    printf("%d\r\n", s);
    wait(1); // wait 1sec
    WriteVS10xxRegister(0x07, 0x4780);
    for (i = 0; i < 6; i++) { // read filename
        uint16_t w = ReadVS10xxRegister(0x06);
        pc.printf("%c%c", w >> 8, w & 0xff);
    }
    pc.printf("\r\n");
    s++;
    wait(5); // wait 6 sec
}
The results are something like:

Code: Select all

0
1234567 MP3
1
ABCDEFGHMP3
...
Here, the first file is "1234567.mp3", and the second is "abcdefgh.mp3" in SD.

I appreciate any suggestions for debug.

User avatar
pasi
VLSI Staff
Posts: 1510
Joined: Thu 2010-07-15 16:04

Re: playing audio by specifying file name

Post by pasi » Wed 2017-06-14 10:49

The standalone.pdf in the vs1011/vs1003 standalone player gives an open by name example, which shows how to iterate through the files and compare the filenames to be able to open the desired file, or you can build an index table in the controller.

The player code is restarted for each file, and the system initialization clears memory. This should not happen except the first time after reset though. (In vs1053/vs1063 that memory clearing is performed before SPI Boot, not in the system initialization function.)

I will probably need to build the setup to try this myself.
Visit https://www.facebook.com/VLSISolution VLSI Solution on Facebook

User avatar
pasi
VLSI Staff
Posts: 1510
Joined: Thu 2010-07-15 16:04

Re: playing audio by specifying file name

Post by pasi » Thu 2017-06-15 11:56

I tried with player1011esci version 1.18, and it seems to work as long as the filename is terminated with a 0.

4780 -> WRAMADDR, 3031 2020 2020 2020 4d50 3300 -> WRAM

Something I noticed: If the named file is found, the open by name flag stays set, so you have to clear that yourself. If you use pause-before-play, you'll be writing to AICTRL3 anyway.

Note that the first file is number 0, so you are expected to get 0 if you try to open "1234567 MP3\0" and it is the first file in the directory. Also note that files do not appear in the same order in Windows as they appear in the directory.
Visit https://www.facebook.com/VLSISolution VLSI Solution on Facebook

akita11
User
Posts: 4
Joined: Mon 2017-06-12 13:57

Re: playing audio by specifying file name

Post by akita11 » Fri 2017-06-16 6:33

Thank you for your advise. It seems to be the best way to generate filename-index table at first in MCU program, and to use index to play the audio by specifying filename.

Post Reply