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

📄 id3.c

📁 ESS3890+SL原代码(1*16内存)
💻 C
字号:
/* Copyright 1997, ESS Technology, Inc.					*//* SCCSID @(#)id3.c	4.1 11/05/02 *//* * $Log$  */#ifdef ID3#include "common.h"#include "memmap.h"#include "buffer.h"#include "id3.h"/************************************************************************  Function: Getting ID3 information and skip ID3-V2.x data at beginning	of MP3 files.  Description: Since most of VCD3.0 targets are low on DRAM and/or ROM 	space, we have an option to enable "USE_ID3_INFO". *************************************************************************//************************************************************************** * global variables  **************************************************************************/int ID3_ABV_offset = 0;#ifdef USE_ID3_INFOID3_INFO *ID3_info;#endif USE_ID3_INFO/************************************************************************** *local variables  **************************************************************************/#ifdef USE_ID3_INFOstatic struct {    char *name[3];    char *artist[3];    char *album[3];    char *year[3];    char *content[3];} frame_id= {{"TT2","TIT2","TIT2"}, {"TP1","TPE1","TPE1"}, {"TAL","TALB","TALB"}, {"TYE","TYER", "TYER"}, {"TCO","TCON","TCON"}};#endif USE_ID3_INFO/************************************************************************** *local functions **************************************************************************/#ifdef USE_ID3_INFOstatic int frame_id_match(char *, int);static int get_frame_size(char *, int);#endif USE_ID3_INFOstatic int get_tag_size(char *);#ifdef USE_ID3_INFOstatic int frame_id_match(char *s, int version){    int id=0, len=4, k=version-2;    if (version==2) len = 3;    if (strncmp(s, frame_id.name[k], len) == 0) {        id = 1;    } else if (strncmp(s, frame_id.artist[k], len) == 0) {        id = 2;    } else if (strncmp(s, frame_id.album[k], len) == 0) {        id = 3;    } else if (strncmp(s, frame_id.year[k], len) == 0) {        id = 4;    } else if (strncmp(s, frame_id.content[k], len) == 0) {        id = 5;    }    if (s[0]==0&&s[1]==0&&s[2]==0) id=-1;     return id;}static int get_frame_size(char *s, int version){    int size = ((s[0]&0x7f)<<14)+((s[1]&0x7f)<<7)+(s[2]&0x7f);    if (version>2) size=(size<<7)+(s[3]&0x7f);    return size;}#endif USE_ID3_INFOstatic int get_tag_size(char *s){    int size = ((s[0]&0x7f)<<21)+((s[1]&0x7f)<<14)+((s[2]&0x7f)<<7)+                (s[3]&0x7f);    return (size);}int ID3_detect(int start, int end, int sec_size){    char *p, *s, *info[6];    int i=0, k, id, offset, sector, version, tag_size=0, len, min, lang=0;    int size, factor, header_size=10;#ifdef USE_ID3_INFO    ID3_info = (ID3_INFO *) dram_cached(ABV_end);    p = (unsigned char *)ID3_info;    info[0] = p+3;    info[1] = info[0]+ MAX_ID3_STRING;    info[2] = info[1] + MAX_ID3_STRING;    info[3] = info[2] + MAX_ID3_STRING;    info[4] = info[3] + 4;    for(i=0; i<2407; i++) p[i] = 0;    for(i=0; i<2; i++){        ID3_info->str_len[i] = 0;        ID3_info->position[i] = 0;    }    id3_str_index = 0;    ID3_info->cur_timer = 0;    ID3_info->cur_track = -1;#endif USE_ID3_INFO    /* get ID3 data */    sector = start;    if (getSectors(start,1,2048) != 1) return 0;    s = (char *)dram(GETSECTOR_DATA_START);    if (strncmp(s, "ID3", 3) == 0) { /* ID3 V2.x */#ifdef USE_ID3_INFO	p[0] = 'I'; p[1] = version = s[3]; p[2] = s[4]; #endif         tag_size = get_tag_size(s+6);	if (s[5]&0x10) header_size = 20; /* header+footer */	tag_size += header_size; #ifdef USE_ID3_INFO        s+=header_size;	i = header_size;	offset = sec_size;	while (i < tag_size){            id = frame_id_match(s, version);            if (id<0) break;	    len=(version>2)?4:3;            s+=len; i+=len;            size = get_frame_size(s, version);            len=(version>2)?6:3;            s+=len; i+=len;            if (id) {		/* For Text information frames the first byte 		 * describes text encoding type...		 *     0x00: ascii (ISO-8859-1)		 *     0x01: Unicode (ISO/IEC 10646-1:1993, UCS-2)		 * 		 * NOTE: we don't really handle Unicode data(16bits)..		 * we are just copying the lower bytes, in case they 		 * are ascii characters.		 */		factor = (*s) ? 2 : 1;                /*Just for now, we didn't handle DBCC*/                if(factor == 2) return 0;		min = (size > MAX_ID3_STRING*factor) ?		    (MAX_ID3_STRING*factor) : size;						/* adjust for 1st byte */                 p = s+factor; min--; 		id--; /* index of ID3 text buffer */ 		if (*p) lang++;		                for (k=0; k<min; k+=factor) 		    *info[id]++ = p[k];            }	    if (lang >= MAX_ID3_ITEMS) break;            s+=size; i+=size;            if (i >= offset) {                sector = adjCDtime(sector, 1, 1);                if (getSectors(sector, 1, 2048)!=1)                    return 0;		s = (char *)dram(GETSECTOR_DATA_START);		offset += sec_size;            }        }         if (!lang) return (tag_size);	/* no such case for ID3 	if (size<128) return 0;*/#endif USE_ID3_INFO    } else { /* ID3 V1.x */	tag_size = 0; /* for prepended ID3 tags only */	#ifdef USE_ID3_INFO	/* ID3 is in the last 2 sectors of MP3 file (last 128 Bytes) */	end = adjCDtime(end, 2, -1);		if(getSectors(end,2, 2048) != 1) return 0;	/* Find "TAG" starting from end of file */	s = (char *)dram(GETSECTOR_DATA_START + 1024); /* point to end */	for(i=MAX_ID3V1_SEARCH;i>0;i--,s--) 	{   	    if (*s == 'T') {		if (strncmp(s, "TAG", 3) == 0) { 		    #if 0		    /* we found ID3V1 info */                    p = (unsigned char *) ID3_info;		    for(i = 0; i < 127; i++) *p++ = *s++;#else                    for(i=0; i<3; i++) ID3_info->TAG[i] = *s++;                    for(i=0; i<30; i++) ID3_info->song_title[i] = *s++;                    for(i=0; i<30; i++) ID3_info->artist[i] = *s++;                    for(i=0; i<30; i++) ID3_info->album[i] = *s++;                    for(i=0; i<4; i++) ID3_info->year[i] = *s++;                    for(i=0; i<30; i++) ID3_info->type[i] = *s++;#endif		    return (0); /* success */		}	    }    	}	#endif USE_ID3_INFO    }    return (tag_size); }#endif ID3

⌨️ 快捷键说明

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