⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 id3.c

📁 一款MP3 Player Firmware 的原代码,非常有参考价值
💻 C
字号:
/* * MP3 Player, ID3 Tag Processing, http://www.pjrc.com/tech/mp3 * Copyright (c) 2000, PJRC.COM, LLC * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA. * * As a specific exception to the GPL, the executable object code built * from this source code may be combined with hardware configuration data * files.  A hardware configuration data file is a set of data that is * transmitted to an intergrated circuit that is not a general purpose * microprocessor or microcontroller, in order to establish its normal * operation.  The process of combining the executable ojbect code built * from the GPL licensed source code with the hardware configuration data * shall be considered an aggregation of another work not based on the * Program.  While the GPL does not restrict use of the program, any * use restriction associated with the hardware configuration data (for * example, that it only be used with particular hardware) shall apply * to the combined file which includes a copy of the hardware configuration * data. * * Contact: paul@pjrc.com */#include "as31glue.h"#include "printf.h"#include "display.h"#include "dirlist.h"#include "playlist.h"#include "stricmp.h"#include "id3.h"// TODO: someday make process_id3 read in just one 128 byte// file_read to fill this struct, and have display.c reference// the elements of this struct.  Write nulls at the 24th byte// of each string, and use %24s in display.c instead of doing// all this space padding stuff.// id3_tag_struct id3_tag; // Structure moved to display.h so we have// a prayer of making the above TODO come true... -ZSB 13-Aug-2001 2:41 PM// NOGCSE = No Common Global Subexpression Elimination // Turning this optimization off SOMETIMES results in less// DSEG usage... sometimes it makes things worse.  It can// be turned back on with a RESTORE pragma if you did a// SAVE pragma before turning it off.#pragma SAVE// #pragma NOGCSEvoid process_id3(char fd, unsigned long size)////	process_id3////	Capture id3 tag info from file//{	xdata char id3[11];	xdata unsigned long cur_pos;		/*unsigned char a;     file_read seems to return number of bytes read,                               not 0 or 1 as specified in drivers.asm??? */	if (size == 0xFFFFFFFF) return;	string_init(id3, ' ', sizeof(id3));	// fill id3 string with spaces	printf("##### Inside process_id3 for file %d of size %ld\r\n", (int)fd, (long)size);	// search for id3v1 tag at end of file	cur_pos=file_tell(fd);	file_seek(fd,size-128);		file_read(fd, (xdata char *)(id3_tag.id3), 3);	if(id3_tag.id3[0] == 'T' && id3_tag.id3[1] == 'A' && id3_tag.id3[2] == 'G') {		print("Found ID3v1 tag\r\n");		file_read(fd, (xdata char *)(id3_tag.title), 30);						file_read(fd, (xdata char *)(id3_tag.artist),30);				file_read(fd, (xdata char *)(id3_tag.album), 30);				file_read(fd, (xdata char *)(id3_tag.year), 4);				file_read(fd, (xdata char *)(id3_tag.comment), 30);		/* id3v1.1 specifies that if the last byte but one in the comment		  field is zero, the last byte is to be used to identify the track		  number - this is not implemented here, it's complicated ;) */		if(id3_tag.comment[28] == 0 && id3_tag.comment[29] != 0) {			id3_tag.track_number = id3_tag.comment[29];		} else {			id3_tag.track_number = 0;		}						lcd_display_id3_struct();#if 0		printf("Tag Value: [%s]\r\n", id3_tag.id3);				printf("Title:     [%s]\r\n", id3_tag.title);		printf("Artist:    [%s]\r\n", id3_tag.artist);		printf("Album:     [%s]\r\n", id3_tag.album);		printf("Comment:   [%s]\r\n", id3_tag.comment);#endif		// printf("Track #:   [%d]\r\n", track_number);	} else {		lcd_display_id3_none();	}	file_seek(fd,cur_pos);#if 0	// search for ID3v2 tag as specified at	// http://www.id3.org/id3v2.4.0-structure.txt and	// http://www.id3.org/id3v2.4.0-frames.txt	cur_pos=file_tell(fd);	file_seek(fd,0);	file_read(fd, id3, 10);	file_seek(fd,cur_pos);	//printf("*** Got %c,%c,%c,%c,%c and returning %d for id3v2\r\n",	//	(char)b[0], (char)b[1], (char)b[2], (char)b[3],	//	(char)b[4], (int)a);	if(id3[0] == 'I' && id3[1] == 'D' && id3[2] == '3') {	  // found ID3v2 tag at start of file, further ID3v2 tag locations          // can be determined from first one	  // header - 10 bytes	  //   identifier: "ID3"	  //   version:    $04 00	  //   flags:      %abcd0000	  //   size:   4 * %0xxxxxxx	  /*          printf("Found ID3v2 tag. version=%d %d flags=%d size=%x %x %x %x\r\n",                 (char)id3[3], (char)id3[4], (char)id3[5],                 (char)id3[6], (char)id3[7], (char)id3[8], (char)id3[9]);	  */	} else {	  // look for tag at end of file - BEFORE ID3v1 tag if present	  // tags at END of file, must have FOOTER part, format:	  //   identifier: "3DI"	  //   version:    $04 00	  //   flags:      %abcd0000	  //   size:   4 * %0xxxxxxx	}#endif}#pragma RESTORE

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -