Changing the length of an array
science_geek
Posts: 247
I am working on my mp3 player at the moment and was wondering if it were possible to be able to create an object that has an array that gets declared after the length is passed into it, this is for the track list, i plan on finding the names for the songs off of the sd card and then store that in an array, but i dont know the number of songs because it could change depending on sd card. Is something like this even possible with spin, I know with java we use an arraylist that will declare an array with the capacity of 10 and then when the size of the array needs to be something greater than 10 we add another array of 10. I have tried some basic experimenting but nothing works. Any answers out there?
Comments
-Phil
You need additional information? Then create a file which contains all tracks of the SD-card plus the additional info (for example if the track is selected / length ...) Once you change the SD-card you first create this file - maybe supported by a checksum to avoid recreation when nothing has been changed.
Basically the trick is: only keep in memory what you immediately need (for example for display ..).
So ... that's what I would do:
1. Change the SD card driver a bit. You need access to the sectors. So, basically you need to create a function in the FAT-driver (fsrw), that allows you to call the readblock function in the low level driver (sdspi...).
2. Format the SD card.
3. Say you want a playlist of max. 1MB. So, create a 1MB file on the PC and copy it to SD card.
4. Find out which sector is the first sector of your file. (Either you can change the driver again, or you can use PC-tools for that - WinHex for example)
Having the SD card formatted before means that the 1MB file will occupy all the sectors in a row. A sector is 512 bytes in size. So, if you want to want to access 'virtual memory adress' 5120 you simply load sector "first sector + 5120/512" there you find your data.
If you now choose the size of one entry of your playlist to a fraction that divides 512 without a rest, you always find full entries in your sector. For example entry size = 32 . Then you have 512 / 32 = 16 playlist entries per sector.
So, if your command says play song 54, you simply can calculate in which sector you can find this entry and load it with the readblock function.
PS:
If you have access to readblock you could also have the player play an open file while you access the playlist, because the FAT driver keeps it's own variables. You only need to synchronize the access. For example having a buffer for the player and give the buffer load a higher prio. So, if the play-pointer reaches the end of a safe-zone, you don't access the SD-card for playlist access.
Hope I pointed out clear enough what I mean ;o)
Post Edited (MagIO2) : 11/13/2009 9:49:28 PM GMT
pub readblock(number, buffer)
sdspi.readblock(number, buffer)
in FSRW.
Gigabytes of virtual memory ...·cool ·;o)
Post Edited (MagIO2) : 11/13/2009 11:24:28 PM GMT
If not I might help. Just modified the SD-card driver to work as virtual memory. You can have a look at thread "Virtual Memory" to get a feeling.
Since that I added some more functions to copy data into virtual memory (like filenames for example) and back to HUB-RAM. So, in my usecase I first scan the directory for .BMP files and copy their names into the list of BMP-files. Later on I get the filenames from this list instead of from directory. Files can still be open while using virtual memory.
Of course you could also add more data to the table like a selection-flag or some information of the MP3 itself - e.g. full name and runtime ... whatever
I have not had a chance to test it yet, we are just finishing up the semester and starting finals week, Im going home this week so hopefully next weekend i can have a chance to try what you have given me, i think it should do what i want it to though, Thank You Very Much!