Sorting of mp3 file
-
- User
- Posts: 10
- Joined: Tue 2021-04-13 12:29
Sorting of mp3 file
Hello,
I'm working on a custom board with 2 VS1010d and 2 sd card with identical mp3 files inside. Rarely happens that if I ask the list of the files from serial, they are not sorted in the same way. How the VS1010d sort the files? I need to have identical list of file for my application, how can i solve the problem?
Thank you
I'm working on a custom board with 2 VS1010d and 2 sd card with identical mp3 files inside. Rarely happens that if I ask the list of the files from serial, they are not sorted in the same way. How the VS1010d sort the files? I need to have identical list of file for my application, how can i solve the problem?
Thank you
Re: Sorting of mp3 file
Hi,
I have a strong belief that the order goes like described below in dir command, but this is fopen(filespec, "rb#number") feature so it also applicable to players. The code which implements this wasn't the easiest code to read.
There are some ways to do this.
I have a strong belief that the order goes like described below in dir command, but this is fopen(filespec, "rb#number") feature so it also applicable to players. The code which implements this wasn't the easiest code to read.
Code: Select all
if (directoryEntries <= 30) {
PrintSubDirs();
PrintFilesInAlphabeticalOrder();
} else {
PrintFilesAndDirectoriesInCreationOrder();
}
- First is the brutal way:
Write some kind of playlist. This can be done on PC or by writing a VS1010 program and then learn that there isn't enough memory to do this easiest way. - Then there is the boring way:
write the media every time in same order. - The Elon Musk way (Remove the problem):
Keep file count below 30 - Treeplayer way:
I think in cheap radio application, there was the treeplayer which played music in order it was using some caching tree traveller.
- Attachments
-
- dirhandler.h
- (383 Bytes) Downloaded 25 times
-
- dirhandler.c
- (4.54 KiB) Downloaded 29 times
-
- User
- Posts: 10
- Joined: Tue 2021-04-13 12:29
Re: Sorting of mp3 file
Thank you for the answer.
I never use more than 30 mp3. I normally use 10-12 mp3 inside the SD, but I have the problem anyway. It seems that VS1010d always use this PrintFilesAndDirectoriesInCreationOrder(). Is it possible?
Perform a file sort on SD from PC could solve this?
Or maybe setting a title order? (1-xxx.mp3, 2-yyy.mp3, ...)
I need a safe procedure for production. It can be boring and slow but has to be safe.
Thank you
I never use more than 30 mp3. I normally use 10-12 mp3 inside the SD, but I have the problem anyway. It seems that VS1010d always use this PrintFilesAndDirectoriesInCreationOrder(). Is it possible?
Perform a file sort on SD from PC could solve this?
Or maybe setting a title order? (1-xxx.mp3, 2-yyy.mp3, ...)
I need a safe procedure for production. It can be boring and slow but has to be safe.
Thank you
Re: Sorting of mp3 file
I think I know how this works. Below is dir /x run from cmd.exe. It shows files with short name and with long name in creation order
Now on VS1010:
This looks like sorted sorted by short name.
So if you have The_Oscillators_-_Sine_1k000_0dbfs.mp3 and The_Oscillators_-_Sine_1k000_-6dbfs.mp3, those are sorted by creation order, because they differ only in the end of the long filename and short name is in creation order.
But if you are happy with tens of filenames from a single directory, I could try to write some relatively smart code.
Code: Select all
Directory of D:\test
11/01/2023 11.01 <DIR> .
11/01/2023 11.01 <DIR> ..
11/01/2023 11.02 2 03_FIR~1.TXT 03_first_file.txt
11/01/2023 11.02 2 01_SEC~1.TXT 01_second_file.txt
11/01/2023 11.03 2 02_THI~1.TXT 02_third_file.txt
11/01/2023 11.05 2 MYLONG~1.TXT mylongfile3.txt
11/01/2023 11.06 2 MYLONG~2.TXT mylongfile2.txt
11/01/2023 11.06 2 MYLONG~3.TXT mylongfile1.txt
11/01/2023 13.19 31 windir.txt
Code: Select all
VS1010>dir s:test
File list of SD/SD Card s:test
D 1: test
1 file(s) found.
File list of SD/SD Card s:test/*
D 1: .
D 2: ..
3: 01_second_file.txt
4: 02_third_file.txt
5: 03_first_file.txt
6: mylongfile3.txt
7: mylongfile2.txt
8: mylongfile1.txt
9: WINDIR.TXT
9 file(s) found.
So if you have The_Oscillators_-_Sine_1k000_0dbfs.mp3 and The_Oscillators_-_Sine_1k000_-6dbfs.mp3, those are sorted by creation order, because they differ only in the end of the long filename and short name is in creation order.
But if you are happy with tens of filenames from a single directory, I could try to write some relatively smart code.
Re: Sorting of mp3 file
Two hours of quick hacking. Contains bugs and features.
The speed of this program is geological. Hopefully it is good enough proof of concept. And it can't give the first index.
My trick is that right after fopen() the long file name is available for Identify() so it is possible to sort with it. However sorting is nlog(n) operation fopen() and fclose() aren't the fast things to do.
Comparison could use strcasecmp() so the windir.txt would be last in my test case. And the real solution would be give the index for this program and sort it once and after that just use it. After that the program could be dropped from memory and the buffers would be freed. The index which parent allocated would still stay in memory.
The speed of this program is geological. Hopefully it is good enough proof of concept. And it can't give the first index.
My trick is that right after fopen() the long file name is available for Identify() so it is possible to sort with it. However sorting is nlog(n) operation fopen() and fclose() aren't the fast things to do.
Comparison could use strcasecmp() so the windir.txt would be last in my test case. And the real solution would be give the index for this program and sort it once and after that just use it. After that the program could be dropped from memory and the buffers would be freed. The index which parent allocated would still stay in memory.
Code: Select all
VS1010>nex* 2 d:test/*
D 1: .
D 2: ..
3: 01_second_file.txt
4: 02_third_file.txt
5: 03_first_file.txt
6: mylongfile3.txt
7: mylongfile2.txt
8: mylongfile1.txt
9: WINDIR.TXT
9 file(s) found.
0 (2): 01_second_file.txt
1 (3): 02_third_file.txt
2 (4): 03_first_file.txt<--
3 (8): WINDIR.TXT
4 (7): mylongfile1.txt
5 (6): mylongfile2.txt
6 (5): mylongfile3.txt
returning 4
VS1010>
- Attachments
-
- nextlongfilename.zip
- PoC for sorting long file names.
- (72.04 KiB) Downloaded 27 times
-
- User
- Posts: 10
- Joined: Tue 2021-04-13 12:29
Re: Sorting of mp3 file
Thank you for the answer!
I made some other tests but I did not verified the sorting by short name. I attached some file to explain:
- sd_from_pc is what I see when open the SD card from PC folder
- sd_from_pc_cmd is the dir /x command on the folder
- sd_from_VS1010 is the dir command on the VS1010
As you can see the sorting by short name is not always verified.
For BG-ALERT-TTE.mp3(BG-ALE~1.MP3) and BG-ALERT-TTE - a.mp3(BG-ALE~3.MP3) is verified, instead for EN-EVAC-BP.mp3(EN-EVA~1.MP3) and EN-EVAC-COM.mp3(EN-EVA~2.MP3) is not: the VS1010 sort EN-EVAC-COM.mp3(EN-EVA~2.MP3) before EN-EVAC-BP.mp3(EN-EVA~1.MP3).
Can you help me to find I stable rule of file sorting?
I cannot use additional software/scripts. I can use PC to manipulate SD card and the serial from my micro to the VS1010.
Thank you very much
I made some other tests but I did not verified the sorting by short name. I attached some file to explain:
- sd_from_pc is what I see when open the SD card from PC folder
- sd_from_pc_cmd is the dir /x command on the folder
- sd_from_VS1010 is the dir command on the VS1010
As you can see the sorting by short name is not always verified.
For BG-ALERT-TTE.mp3(BG-ALE~1.MP3) and BG-ALERT-TTE - a.mp3(BG-ALE~3.MP3) is verified, instead for EN-EVAC-BP.mp3(EN-EVA~1.MP3) and EN-EVAC-COM.mp3(EN-EVA~2.MP3) is not: the VS1010 sort EN-EVAC-COM.mp3(EN-EVA~2.MP3) before EN-EVAC-BP.mp3(EN-EVA~1.MP3).
Can you help me to find I stable rule of file sorting?
I cannot use additional software/scripts. I can use PC to manipulate SD card and the serial from my micro to the VS1010.
Thank you very much
- Attachments
-
- sd_from_VS1010.JPG (53.75 KiB) Viewed 784 times
-
- sd_from_pc_cmd.JPG (92.02 KiB) Viewed 784 times
-
- sd_from_pc.JPG (56.6 KiB) Viewed 784 times
Re: Sorting of mp3 file
I believe I have more understanding of the ROM file open.
The less than 30 files rule applies.
The sortable items are u_int32 integers which are build in filename[0] << 16 | filename[1]
The items are quicksort()ed
That gives: sort by first two letters, and if they are same, order is undefined (quicksort() isn't a stable sort)
And yes. I was also surprised how this really works. but it is enough for tracks of single album where naming is artis/album/nn-song.mp3
The less than 30 files rule applies.
The sortable items are u_int32 integers which are build in filename[0] << 16 | filename[1]
The items are quicksort()ed
That gives: sort by first two letters, and if they are same, order is undefined (quicksort() isn't a stable sort)
And yes. I was also surprised how this really works. but it is enough for tracks of single album where naming is artis/album/nn-song.mp3
-
- User
- Posts: 10
- Joined: Tue 2021-04-13 12:29
Re: Sorting of mp3 file
Ok thank you.
If it is a safe way I will force production department to add the 2 letter number before title track ("nn-song.mp3").
I have one last question. In case of more than 30 file which is the sorting behaviour?
Putting 2 letter number before title will save me for strange sorting behaviour?
Thank you
If it is a safe way I will force production department to add the 2 letter number before title track ("nn-song.mp3").
I have one last question. In case of more than 30 file which is the sorting behaviour?
Putting 2 letter number before title will save me for strange sorting behaviour?
Thank you
Re: Sorting of mp3 file
As far as I understood the ROM code, the two letter sort applies on less than 30 songs. Also my limited testing supports it.
Beyond 30 files order is undefined in my understanding.
Is this production final test problem? So far I have been solving general player problem. Using dir as test application checks only that there is the file entry in the directory structure available. The data isn't checked and it probably doesn't even detect if the cluster allocation chain is broken. This happens if USB connection is broken before PC has written all data to it.
What I suggest is to have a small program which is run on the final test. It could check pin connections that there are no shorts and stuff like that if wanted. But the power comes when it reads all media, calculates CRC32 for the files, and compares results with known values. With that approach filenames and orders become irrelevant and test coverage is much higher. The program consumes some clusters of the mass media and if the disk isn't ever again written, the data is correct until the disk degrades in next 50 years or something like that.
Beyond 30 files order is undefined in my understanding.
Is this production final test problem? So far I have been solving general player problem. Using dir as test application checks only that there is the file entry in the directory structure available. The data isn't checked and it probably doesn't even detect if the cluster allocation chain is broken. This happens if USB connection is broken before PC has written all data to it.
What I suggest is to have a small program which is run on the final test. It could check pin connections that there are no shorts and stuff like that if wanted. But the power comes when it reads all media, calculates CRC32 for the files, and compares results with known values. With that approach filenames and orders become irrelevant and test coverage is much higher. The program consumes some clusters of the mass media and if the disk isn't ever again written, the data is correct until the disk degrades in next 50 years or something like that.