C Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesC Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old July 26th, 2003, 03:10 PM
movEAX_444's Avatar
movEAX_444 movEAX_444 is offline
Cast down
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2003
Location: Sweden
Posts: 321 movEAX_444 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 5 h 56 m 35 sec
Reputation Power: 6
Reading mp3 id3, something wrong with genre/year

Something is wrong with the Genre/Year of this.. Genre is 1 less than it's supposed to be, and If there is a comment, it shows up with the year, ("1999COMMENT HERE"):

Code:

#include <stdio.h> 
#include <stdlib.h> 

typedef struct _id3tag
{
	char title[30]; 
	char artist[30]; 
	char album[30]; 
	char year[4]; 
	char comment[30];
	unsigned char track; 
	unsigned char genre; 
} id3tag; 

int ReadID3(const char* Filename, id3tag *ID3Tag); //0==error, 1==sucess 

int main(int argc, char **argv)
{
	id3tag ID3; 
	if(!ReadID3("C:\\g.mp3",&ID3))
		printf("error!\n"); 
	
	printf("Genre %d\nYear %s\n",ID3.genre,ID3.year); 
	return 0; 
}


int ReadID3(const char* Filename, id3tag *ID3Tag)
{
	FILE *fp=fopen(Filename,"rb"); 
	char buffer[128]; 
	int x; 

	fseek(fp,-128,SEEK_END); 
	fread(buffer,sizeof(char),sizeof(buffer),fp); 

	if(!(buffer[0]=='T' && buffer[1] == 'A' && buffer[2] == 'G'))
	{
		return 0; 
	}
	
	//Found id3 tag, let's fill out our id3tag struct 
	for(x=0;x<30;x++)
		ID3Tag->title[x] = buffer[x+3]; //take 3 off cause of TAG 
		ID3Tag->title[30] = '\0'; 

	for(x=0;x<30;x++)
		ID3Tag->artist[x] = buffer[x+33]; //33 = TAG + title 
		ID3Tag->artist[30] = '\0'; 

	for(x=0;x<30;x++)
		ID3Tag->album[x] = buffer[x+63]; //TAG + title + artist 
		ID3Tag->album[30] = '\0'; 

	for(x=0;x<4;x++)
		ID3Tag->year[x] = buffer[x+93]; //TAG + title + artist + album 
		ID3Tag->year[4] = '\0'; 
		
	for(x=0;x<30;x++)
		ID3Tag->comment[x] = buffer[x+97]; //TAG + title + artist + album + year 
		ID3Tag->comment[30] = '\0'; 

	if(buffer[127] > 0 && buffer[127] < 256)
		ID3Tag->genre = buffer[127]; //If its between 1-255, put it 
	else 
		ID3Tag->genre = 255; //255 means unused 

	//ID3 1.1 compatibility (Track field) 
	if(ID3Tag->comment[28] == '\0')
		ID3Tag->track = ID3Tag->comment[29]; //If comment ends at 28.. then 29 is the track 
	else
		ID3Tag->track = 0; //0 mean's unknown track 
	return 1; 
}

Last edited by movEAX_444 : July 27th, 2003 at 12:00 AM.

Reply With Quote
  #2  
Old July 26th, 2003, 07:10 PM
dwise1_aol's Avatar
dwise1_aol dwise1_aol is offline
Contributing User
Dev Shed Expert (3500 - 3999 posts)
 
Join Date: Jan 2003
Location: USA
Posts: 3,977 dwise1_aol User rank is Colonel (50000 - 60000 Reputation Level)dwise1_aol User rank is Colonel (50000 - 60000 Reputation Level)dwise1_aol User rank is Colonel (50000 - 60000 Reputation Level)dwise1_aol User rank is Colonel (50000 - 60000 Reputation Level)dwise1_aol User rank is Colonel (50000 - 60000 Reputation Level)dwise1_aol User rank is Colonel (50000 - 60000 Reputation Level)dwise1_aol User rank is Colonel (50000 - 60000 Reputation Level)dwise1_aol User rank is Colonel (50000 - 60000 Reputation Level)dwise1_aol User rank is Colonel (50000 - 60000 Reputation Level)dwise1_aol User rank is Colonel (50000 - 60000 Reputation Level)dwise1_aol User rank is Colonel (50000 - 60000 Reputation Level)dwise1_aol User rank is Colonel (50000 - 60000 Reputation Level) 
Time spent in forums: 1 Month 4 Days 5 h 26 m 2 sec
Reputation Power: 558
Re: Binary I/O functions in C, to read mp3 id3

Quote:
Originally posted by movEAX_444
How would I read bytes in a file? Like ID3 tags in a mp3.
This is what I have so far, I want to read the last 128 bytes (the first 3 of those 128 determines if it's an ID3 tag)

Code:
	FILE *fp=fopen("C:\\whatever.mp3","rb"); 
	fseek(fp,128,SEEK_END); 
	fclose(fp); 

I haven't actually played with it, but wouldn't you want to make that a negative offset from the end? E.g.:
Code:
	FILE *fp=fopen("C:\\whatever.mp3","rb"); 
	fseek(fp,-128,SEEK_END); 
	fclose(fp); 

Reply With Quote
  #3  
Old July 26th, 2003, 07:58 PM
movEAX_444's Avatar
movEAX_444 movEAX_444 is offline
Cast down
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2003
Location: Sweden
Posts: 321 movEAX_444 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 5 h 56 m 35 sec
Reputation Power: 6
SEEK_END read's backwards 128 bytes (or whatever you want it to), -128 doesn't work I get an error. Another way to do it is just to start reading from filesize - 128.

Reply With Quote
  #4  
Old July 26th, 2003, 09:01 PM
movEAX_444's Avatar
movEAX_444 movEAX_444 is offline
Cast down
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2003
Location: Sweden
Posts: 321 movEAX_444 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 5 h 56 m 35 sec
Reputation Power: 6
Ok I think SEEK_END is with a negative, I got it to work with no error. You were right. I am getting closer to getting at least something working.


haha it wasn't working because the mp3 didn't have an id3 tag.

Last edited by movEAX_444 : July 26th, 2003 at 09:03 PM.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesC Programming > Binary I/O functions in C, to read mp3 id3


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway
Stay green...Green IT