Jump to content
  • Advertisement
Sign in to follow this  
00dave

trouble with opening and loading a file

This topic is 4481 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm trying to make a program that loads the IDv3 tag of an Mp3 file, but I can't find any information regarding the offsets and bytes of the information (name, artist, etc) If I did find it, would the best way to go about changing the name be to find the offset where the name begins, go to that point, load in however many bytes the name is, change it, then write it from the same place I loaded it? Thanks

Share this post


Link to post
Share on other sites
Advertisement
Use the IOStream Library - it's usually the easiest thing to use when working with files that implement random-access data (jumping to offsets and locations in the file).

Share this post


Link to post
Share on other sites
Here's a link on wotsit for the .mp3 format.

The approach would depend on the method used in the file. If they used NULL terminated strings, you would need to insert the characters of the new name followed by the null terminator. If they use pascal-style strings, you'll have to find where they store the string length, which will tell you how many bytes to load.

Once you know the offset, you can load it in like you said. Don't just overwrite it though, unless it's the same number of characters.

It will be easy to find if you use a hex editor. Just search the ASCII output until you find the text. If it's NULL terminated, you know what to do. If it's not, I'd look to see if there's a 32-bit variable directly before it that happens to contain a value which is the same number of bytes as the string. If it's not, you'll have to use that file format info to find the offset to the string length.

Share this post


Link to post
Share on other sites
I opened up a few different files with a hex editor, and all of them at the beginning where I think the ID3v tag is is different, very different :/

Share this post


Link to post
Share on other sites
Where? I had found those at wotsit before, nothing helped... the one file was a dead link that looked promising :(

Share this post


Link to post
Share on other sites
Click on the one that says: "Mpeg 1.0/2.0 LayersI, II and III header and trailer formats [Laurent Clevy]"

It has all the information you need.

Oh, and it's easier than I thought. Here's the info on the artist, etc.


* TRAILER

at end of file - 128 bytes

offset type len name
--------------------------------------------
0 char 3 "TAG"
3 char 30 title
33 char 30 artist
63 char 30 album
93 char 4 year
97 char 30 comments
127 byte 1 genre
--------------------------------------------

- genre :

0 "Blues"
1 "Classic Rock"
2 "Country"
3 "Dance"
4 "Disco"
5 "Funk"
6 "Grunge"
7 "Hip-Hop"
8 "Jazz"
9 "Metal"
10 "New Age"
11 "Oldies"
12 "Other"
13 "Pop"
14 "R&B"
15 "Rap"
16 "Reggae"
17 "Rock"
18 "Techno"
19 "Industrial"
20 "Alternative"
21 "Ska"
22 "Death Metal"
23 "Pranks"
24 "Soundtrack"
25 "Euro-Techno"
26 "Ambient"
27 "Trip-Hop"
28 "Vocal"
29 "Jazz+Funk"
30 "Fusion"
31 "Trance"
32 "Classical"
33 "Instrumental"
34 "Acid"
35 "House"
36 "Game"
37 "Sound Clip"
38 "Gospel"
39 "Noise"
40 "AlternRock"
41 "Bass"
42 "Soul"
43 "Punk"
44 "Space"
45 "Meditative"
46 "Instrumental Pop"
47 "Instrumental Rock"
48 "Ethnic"
49 "Gothic"
50 "Darkwave"
51 "Techno-Industrial"
52 "Electronic"
53 "Pop-Folk"
54 "Eurodance"
55 "Dream"
56 "Southern Rock"
57 "Comedy"
58 "Cult"
59 "Gangsta"
60 "Top 40"
61 "Christian Rap"
62 "Pop/Funk"
63 "Jungle"
64 "Native American"
65 "Cabaret"
66 "New Wave"
67 "Psychadelic"
68 "Rave"
69 "Showtunes"
70 "Trailer"
71 "Lo-Fi"
72 "Tribal"
73 "Acid Punk"
74 "Acid Jazz"
75 "Polka"
76 "Retro"
77 "Musical"
78 "Rock & Roll"
79 "Hard Rock"
80 "Unknown"







So you CAN just overwrite it, since the sizes are fixed. How odd that genre is actually a number instead of a string. Guess they were really fixed on getting it into 128 bytes.

Note: The offsets are from the end of the file.

Share this post


Link to post
Share on other sites
yeah.. from the end? so would I use the fseek function with SEEK_END? That makes sence to me.

Thanks :)

Share this post


Link to post
Share on other sites
Actually, how can the offset be 0 from the end? and 3 and 30 and so on? I tested them and they return garbage too. :/ Would the way to seek 128 bytes from the end of the file be

Well, I read the information correctly, one hurdle :)

But when I try to edit it and write it back... nothing changes, when I know that the char's in the array change, I tested that.


int main()
{
FILE *file;
int r;
char c[128];

file = fopen("song.mp3","rb");

fseek (file,0,SEEK_END);

long place = ftell(file);

place = place - 128;

fseek (file, place, SEEK_SET);

for(int x = 0; x < 128; x++)
{
fread (&c[x],sizeof(char),1,file);
if(c[x] == '_')
c[x] = ' ';
}
fseek (file, place, SEEK_SET);

fwrite (c,sizeof(char),128,file);

fflush(file); //
fclose (file);// not sure which of these is neccessary, or both

}



[Edited by - 00dave on March 14, 2006 6:43:17 PM]

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!