Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

MP3 when the file ends ?

Xenon02

Full Member level 3
Joined
Nov 12, 2022
Messages
157
Helped
0
Reputation
0
Reaction score
0
Trophy points
16
Activity points
2,205
Hello !

I've acquired the DFPlayer for my STM32 Nucleo, and I've been wondering how it works a little bit (not that detailed), and I've read a bit how the mp3 file structure looked like, and I wondered how does the DFPlayer or any MP3 devices knows where the file starts and where the file ends ? If for example the file was mixed with other files that are not MP3 then DFPlayer has to know which files are which and where to start reading.

First of all I've tried to find this information and I found out that usually people are searching for the sync bytes that are usually the same and repeats in every frame so if it's in first frame and in the second frame etc it is then considered as mp3 file. So maybe the DFPlayer searches for the first sync byte or something like that, but how does he know how many frames have been sent in total ? If there is no EOF in mp3 file structure.

Second thing why I'm asking this is because when I want to change the music while the actual music is in the middle of playing he has to know how long is the music and skips the rest of the frames to go to next music and it's first frame. I wondered what is the algorythm of finding the mp3 file from all the data that is stored in the microSD card and from that he know how long is one music. I really wonder how it works.
 
Usually the file system operations are handled by a library. Usually you don't have to worry about looking for each part of a file, you have very standard operations such as read, write, open, close, create, delete and rename. All you have to do is specify the name(s) and the library functions do the rest.
Normally, you don't have to search for the root folder, because it is in a fixed location in memory (or on disk). What you might have to do is define an area where data read from the file is stored while you are using it. Again, it is normal for the filing system to read large files in manageable chunks, for example you declare 1K of memory and the FS loads 10K of file into it 10 times as you request the next chunk until all the file is read.

If you really want to delve into how filing systems work, i would suggest you first learn about how "linked lists" work as the principle is core to how FAT structures operate.

Brian.
 
If you really want to delve into how filing systems work, i would suggest you first learn about how "linked lists" work as the principle is core to how FAT structures operate.


I've read what linked list is and it works on nodes that it has data and direction to next node.

So FAT has info of which cluster to take data and it comes back to see what cluster to go next.

Usually the file system operations are handled by a library. Usually you don't have to worry about looking for each part of a file, you have very standard operations such as read, write, open, close, create, delete and rename. All you have to do is specify the name(s) and the library functions do the rest.
Normally, you don't have to search for the root folder, because it is in a fixed location in memory (or on disk). What you might have to do is define an area where data read from the file is stored while you are using it. Again, it is normal for the filing system to read large files in manageable chunks, for example you declare 1K of memory and the FS loads 10K of file into it 10 times as you request the next chunk until all the file is read.

So if I have 3 files :
- text.txt
- image.img
- music.mp3

I want to open image.img (read the data to put it on screen)

1701337116550.png


So the root directory or rather it's start is in FAT sector and the rest of root directory is in Data sector. So what is saved in FAT sector in the starting root directory that is specific to that file . I understood that there are now 3 starting root directory for each file so it has to distinguish which is which.

Aside of that I understand that no one is making the reading from SD or any disk code ? Everyone uses the libraries and mp3 decoder also uses this library as I understand. So the microcontroller in mp3 just executes the Read () file etc.
I though that I have to make sure what I read from that SD card.
Still it makes me think what is the algorithm in the libraries that when I write read(text.txt) it finds correct starting root which after that I understand how he reads.

I just also know that in Data section it saves files in a random free space so they can be scattered so I also assumed that starting root directory that is stored in FAT section can also be scattered through directories to the clusters. So scanning whole FAT section to find a byte or many bytes that is unique only for root directory and not just a cluster directory data and the info it contains Is also unique to the data user is looking for must mean that starting root directory must have some value that is saying this is starting root and not cluster direction data and another info (another value) that says this is starting root for this and this file and not this and this file.

I just realized that this is pretty complex and it might be to much. But couldn't find the tutorials and just basing my knowledge on overall concept and how it works, I thought that it didn't say allot how it is implemented if you know what I mean. Like ok I know a thing how FAT32 works now I want to make a microcontroller that reads data from disk, I just put library premade into it and put algorithm that after he gets starting signal he reads from that file. It's just that easy ? I saw some mp3 documentation how it is implemented and the algorithm are crazy, so I thought that maybe that are not using pre made libraries that uses function read but they somehow scans the SDcards and tried to read data with a specific numeration like in the Datasheet. So for the future that maybe someone asks me to do something like read data I tried to learn it maybe here but If it's a bad idea then maybe someone has some good links ?
 
All you need is the filing system library and something like this:
Code:
FILE MyImageFile;    // create a file structure called "MyImageFile"
MyImageFile = fopen("image.img","mode to open the file in");    // open "image.img" and load its details into the structure
Then you use "fread() to get it's contents.

The specifics of the parameters will depend on the compiler you are using.

Brian.
 
All you need is the filing system library and something like this:
Code:
FILE MyImageFile;    // create a file structure called "MyImageFile"
MyImageFile = fopen("image.img","mode to open the file in");    // open "image.img" and load its details into the structure
Then you use "fread() to get it's contents.

The specifics of the parameters will depend on the compiler you are using.

Brian.
Simple devices like DFPlayer microcontroller also has this library I assume ?
 
DFPlayer surely uses a FAT file library internally. The specific point is that you have no direct access to the SD card, there's a number of play and information commands through serial interface. Apparently usage of file names is limited, at least with commonly used DFPlayer mini library.

Limitations of DFPlayer software have nothing to do with general FAT operation.
 
Hi,

let´s step back. Please forget about microcontroller, OS, software and so on.
1) You say "I plug in SD Card". So who puts the files onto the SD Card?
2) Are there directories involved, why?

and
3) how is the MP3 player controlled? Manually by user? What display? What input device? (touch, QWheel, pushbuttons, ...)

--> In many cases there is no need to do a filename search at all.

Klaus
 
Looking at this: https://www.dfrobot.com/product-1121.html
there are clearly no controls on the device at all so it requires external connections. The specification states it can play several audio in several formats and merely playing mp3 requires considerable programming power so I would say yes, it certainly has its own fully or partially compliant filing system. It does quote FAT16 or FAT32 is required.

Brian.
 
Hi,

let´s step back. Please forget about microcontroller, OS, software and so on.
1) You say "I plug in SD Card". So who puts the files onto the SD Card?
2) Are there directories involved, why?

and
3) how is the MP3 player controlled? Manually by user? What display? What input device? (touch, QWheel, pushbuttons, ...)

--> In many cases there is no need to do a filename search at all.

Klaus

1) Or rather what if it already has filles in it and I put SD Card into a player or device that has to use already storaged card.
About putting files, I imagined it the way that formating the SD card or rather formating USB sticks there were the options of picking file system to the reserved part is changing and filled by OS I believe.

2) Directories ? Hmmmm that's the thing the directory so far in FAT system file is dictated by the Root Directory. While browsing the internet I've found this :
and here it pretty much says how Directory works which amazed me a bit (unfortunatelly it says only about FAT12)
1701430746241.png


Which was intuitive with the directory, I knew then that first 11 bytes represents always the name of the file (fixed number so the name could only have 11 characters), and so 1 file takes only 32 bytes each. So if the name didn't match what I was looking for then I skipped the rest of the bytes and read again 11 bytes. Which was intuitive. Like searching for test :

1701431065365.png

Then adding an offset to get to the Directory table I just read first 11 bytes and then ship them if it's not a file I am looking for.

To bad there was nothing about FAT32 but I'll try searching.

3) how is the MP3 player controlled? Manually by user? What display? What input device? (touch, QWheel, pushbuttons, ...)

It can be controlled with command but it only work as a Start command or change music command or pause etc. It can be also controller by buttons only.
But the ones making the library needed to know how to get into SD Card am I right ?
 
1) Or rather what if it already has filles in it and I put SD Card into a player or device that has to use already storaged card.
About putting files, I imagined it the way that formating the SD card or rather formating USB sticks there were the options of picking file system to the reserved part is changing and filled by OS I believe.
Sorry, I guess I was not clear. I meant the MP3 files.

2) Here I also meant sub directories for the MP3 files.

It can be controlled with command
So by voice recognition?I was not expecting this.

Klaus
 
Sorry, I guess I was not clear. I meant the MP3 files.
1) You say "I plug in SD Card". So who puts the files onto the SD Card?

I guess OS ? Or something that has a library about a specific FAT that will know which bytes are reserved and which are free for specific information like Directory to a file and other stuff.

The whole mp3 data is stored under the label that the user gives to the specific file like the mp3 file.
2) Here I also meant sub directories for the MP3 files.
That's a good question, because I don't know how folders work in FAT. So yea what it reads first folders or files and info that the file is stored in folder.
This is what I don't know.

So by voice recognition?I was not expecting this.
commands from microcontroller to the mp3 player, that's what I thought.
 
Hi,

I wanted you to forget about OS, microcontroller and so on ...
(but you still refer to OS, microcontroller, FAT... )

So when I asked about "who" then I expected something like You only, your family, your emplyees, random users ....

and for the "control" I gave examples ... like pushbutton...

So I guess I can´t express myself clear enough.

Klaus
 
I wanted you to forget about OS, microcontroller and so on ...
(but you still refer to OS, microcontroller, FAT... )

So when I asked about "who" then I expected something like You only, your family, your emplyees, random users ....

and for the "control" I gave examples ... like pushbutton...

So I guess I can´t express myself clear enough.

Ayyy sorry I thought that it was more of a what device or so. But yea you mentioned to forget about OS and microcontrollers my bad for forgetting it in a heat of writing ;>

Then let's say that someone putted data into this card and I want to read what is inside of it somehow.

And it is controlled by pushbuttons ? It's the simplest form or by using switches

My bad here. Although I want to see what you're trying to tell me with those questions :>
 
Hi,

I did not want to tell something. I tried to get informations hot is meant to work. But failed to get what I wanted to know..

Good luck.

Klaus
 
Hi,

I did not want to tell something. I tried to get informations hot is meant to work. But failed to get what I wanted to know..

Good luck.

Klaus

Oh okey, I'll try to solve it. Looking at this video :
made me realize a bit how it could work, although reading the code is not making it clearer how people access something, I imagined it that way that I create a variable that is an offsets to the specific Areas.

Like two "for" statements one that reads the FAT table and the other one to read the data inside the Data area. Although I see it used the FILE i don't know exactly what it is. To open a file but that's weird because the FAT32 the author is implementing is to store the data and then open what is inside of it but maybe it's just me that it's weird.

Just looking at it is pretty complex, and making the FAT32 from scratch seems difficult, author here is implementing the FAT12 but yea. I got a bit lost, from just a curiosity and thinking that it might be easy to implement (some say it is easy) to the point where I see it is not.

Maybe this vision is a bit disturbed by the fact that making libraries from scratch to OLED or small modules that didn't require reading from SD card or other disks, was easier from the fact that I didn't have to read from memory. Also I thought that making a module will require for me to make own libraries because that's what I heard from my friends that programmers usually make own libraries for devices. So I thought accessing data from SD Card or other disk is by searching the data inside the disk like the disk returns data to microcontroller and it scans the data it receives because microcontroller itself cannot access the whole memory I guess or it may send which part of memory he want to read dunno and the SD Card also has some processor that controlls what is requested from him from the outside.

Welp still a lot to learn but thanks for the help, I'll try to learn just how FAT32 works in the context of only Root Directory and I will stop at this point because this is unintuitive in FAT12 it was intuitive because the name of a file was there and the size was fixed.

Thanks Klaus and everybody here.
 

LaTeX Commands Quick-Menu:

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top