📄 id3.c
字号:
/*============================================================================
Copyright (c) 2001 Sunplus Technology Co., Ltd.
Module Name: FileHeadNDID3.c
Abstract: Module related to main routine
Environment: Keil C51 Compiler
Revision History: 11/13/2002 XYQ created
=============================================================================*/
//=============================================================================
//=============Header file
#include "general.h"
#include "doslink.h"
#include "dosusr.h"
#include "cardimpt.h"
#include "ID3.H"
//=============================================================================
//extern variable
extern unsigned int xdata G_searchCluster;
extern unsigned int xdata G_CurrentFile_StartCluster;
//=============================================================================
#if (ID3Tag_OPTION==1)
//=========================================================================================
//local variable
//=========================================================================================
//add by XYQ 021120
void USR_ReadID3Frame(unsigned long *DATA_LogAddr,unsigned long *FilePoint,unsigned char *array,unsigned int arrayLength, bit FillArray)
{
unsigned int i,j;
if(!arrayLength) return;//不读就还回。
for((j=0,i=*FilePoint%K_DOS_SectorSize); (i<K_DOS_SectorSize && j<arrayLength); (j++,i++))
{
if(FillArray) array[j] = G_ucDataBuffer[i];
// DbgPrint("%c",G_ucDataBuffer[i]);
// DbgPrint("\nj1==%x\n",j);
}
while((j<arrayLength) || !((*FilePoint+j)%K_DOS_SectorSize))//!((*FilePoint+j)%K_DOS_SectorSize)意思是先把下一个sector读出来
{
if((*FilePoint+j)%G_DOS_ClusterSize)
{
*DATA_LogAddr = *DATA_LogAddr + 512;
}else{
G_searchCluster=DOS_GetNextCluster(G_searchCluster);
if(G_searchCluster==0) break;
*DATA_LogAddr = DOS_ClusterLogAddr(G_searchCluster);
}
DOS_ReadSector(K_DOS_DstSram, *DATA_LogAddr, 0);
for(i=0;(i<K_DOS_SectorSize && j<arrayLength); (i++,j++))
{
if(FillArray) array[j] = G_ucDataBuffer[i];
// DbgPrint("%c",G_ucDataBuffer[i]);
}
// DbgPrint("\nj2==%x\n",j);
if(j>=arrayLength) break;
}
*FilePoint=*FilePoint+arrayLength;
// DbgPrint("=============\n");
}
//=========================================================================================
//add by XYQ 021118
unsigned int USR_File_Read(unsigned long FilePoint, unsigned int *FileCluster, unsigned long *DATA_LogAddr)
{
unsigned int CLUS_CNT;
CLUS_CNT=(FilePoint)/G_DOS_ClusterSize;
*FileCluster=G_CurrentFile_StartCluster;
while(CLUS_CNT!=0)
{
*FileCluster=DOS_GetNextCluster(*FileCluster);
CLUS_CNT--;
}
*DATA_LogAddr = DOS_ClusterLogAddr(*FileCluster) + (FilePoint)%G_DOS_ClusterSize;
DOS_ReadSector(K_DOS_DstSram, *DATA_LogAddr, 0);
return (unsigned int)((FilePoint)%K_DOS_SectorSize);
}
//=========================================================================================
//add by XYQ 021122
unsigned long X_Get_ID3V2_3_Frame(unsigned long FrameName,unsigned char *FrameBuff,unsigned char FrameBuffSize)
{
unsigned long ID3V2_3_Size;
union
{
unsigned char ID3V2Frame[10];
struct
{
unsigned long ID;
unsigned long Size;
unsigned int Flags;
}ID3V2Frames;
}U_Lable;
unsigned long DATA_LogAddr;
unsigned long FilePoint;
bit SuccessFinish;
SuccessFinish=0;
USR_File_Read(0, &G_searchCluster,&DATA_LogAddr);
if(G_ucDataBuffer[0]=='I' && G_ucDataBuffer[1]=='D' && G_ucDataBuffer[2]=='3')
{
//printf("found ID3 V2......\n");
if(G_ucDataBuffer[3]==0x03 && G_ucDataBuffer[4]==0x00 && G_ucDataBuffer[5]==0x00)
{//V2.3
ID3V2_3_Size = ((unsigned long)G_ucDataBuffer[6]&0x7F)<<21 | \
((unsigned long)G_ucDataBuffer[7]&0x7F)<<14 | \
((unsigned long)G_ucDataBuffer[8]&0x7F)<<7 | (G_ucDataBuffer[9]&0x7F);
FilePoint=10;
while(FilePoint < ID3V2_3_Size+10)
{
if(SuccessFinish)
{
return U_Lable.ID3V2Frames.Size;//找完了
}
USR_ReadID3Frame(&DATA_LogAddr, &FilePoint, U_Lable.ID3V2Frame, 10, 1);
if(U_Lable.ID3V2Frames.ID==FrameName)
{
SuccessFinish=1;
}
/*
switch(U_Lable.ID3V2Frames.ID)
{
case 0x54495432://"TIT2"歌曲名
// USR_ReadID3Frame(&DATA_LogAddr, &FilePoint, *FrameBuff,(U_Lable.ID3V2Frames.Size>=MaxID3BufferNum)?MaxID3BufferNum:U_Lable.ID3V2Frames.Size, 1);//读歌名,仅读前30 BYTE
// USR_ReadID3Frame(&DATA_LogAddr, &FilePoint, *FrameBuff,(U_Lable.ID3V2Frames.Size>MaxID3BufferNum)?(U_Lable.ID3V2Frames.Size-MaxID3BufferNum):0, 0);//空读操作,不填到数组里
SuccessFinish=ID3V2_3_SongName;
break;
case 0x54504531://"TPE1"歌手名
// USR_ReadID3Frame(&DATA_LogAddr, &FilePoint, *FrameBuff,(U_Lable.ID3V2Frames.Size>=30)?30:U_Lable.ID3V2Frames.Size, 1);//读歌名,仅读前30 BYTE
// USR_ReadID3Frame(&DATA_LogAddr, &FilePoint, *FrameBuff,(U_Lable.ID3V2Frames.Size>MaxID3BufferNum)?(U_Lable.ID3V2Frames.Size-MaxID3BufferNum):0, 0);//空读操作,不填到数组里
SuccessFinish=ID3V2_3_SingerName;
break;
default:
// USR_ReadID3Frame(&DATA_LogAddr, &FilePoint, SongNameNDSingerName,U_Lable.ID3V2Frames.Size, 0);//空读操作,不填到数组里
break;
}
*/
USR_ReadID3Frame(&DATA_LogAddr, &FilePoint, FrameBuff,(U_Lable.ID3V2Frames.Size>=FrameBuffSize)?FrameBuffSize:U_Lable.ID3V2Frames.Size, 1);//读FrameBuffZize
USR_ReadID3Frame(&DATA_LogAddr, &FilePoint, FrameBuff,(U_Lable.ID3V2Frames.Size>FrameBuffSize)?(U_Lable.ID3V2Frames.Size-FrameBuffSize):0, 0);//空读操作,不填到数组里
}
}
}
return 0;//没找到
}
//=========================================================================================
bit X_Get_ID3V2_3()
{
unsigned long DATA_LogAddr;
USR_File_Read(0, &G_searchCluster,&DATA_LogAddr);
if(G_ucDataBuffer[0]=='I' && G_ucDataBuffer[1]=='D' && G_ucDataBuffer[2]=='3')
{
DbgPrint("found ID3 V2......\n");
if(G_ucDataBuffer[3]==0x03 && G_ucDataBuffer[4]==0x00 && G_ucDataBuffer[5]==0x00)
{//V2.3
return 1;
}
}
else
DbgPrint("Cannot found ID3 V2......\n");
return 0;
}
//=========================================================================================
//add by XYQ 021122
bit X_Get_ID3V1_Info(unsigned char *FrameBuff,unsigned char FrameBuffSize)
{
union
{
unsigned char V1TAG[4];
unsigned long V1TAGValue;
}U_Lable;
unsigned long DATA_LogAddr;
unsigned long FilePoint;
// ID3V1
// DbgPrint("Try found ID3 V1......\n");
FilePoint=G_DOS_FileSize-128;
USR_File_Read(FilePoint, &G_searchCluster,&DATA_LogAddr);
USR_ReadID3Frame(&DATA_LogAddr, &FilePoint, U_Lable.V1TAG, 3, 1);
if((U_Lable.V1TAGValue&0xffffff00)==0x54414700)//found 'TAG'
{
USR_ReadID3Frame(&DATA_LogAddr,&FilePoint,FrameBuff,FrameBuffSize, 1);
return 1;//找到了
}
return 0;//没找到
}
//====================================================================================
unsigned char X_Get_LongFileName(unsigned char *FDB,unsigned char *FrameBuff,unsigned char FrameBuffSize)
{
unsigned char X_Continue;
unsigned char code UnicodeOffset[26]={2,1,4,3,6,5,8,7,10,9,15,14,17,16,19,18,21,20,23,22,25,24,29,28,31,30};
X_Continue=0;
if (FDB[0] != 0xe5 && FDB[0] != 0x00)
{
if (FDB[11] == 0x0F && FDB[12] == 0x00)
{
// long file name fdb
if (FDB[0] & 0x40)
{//the last fdb
X_Continue=1;//long file name fdb over
}else{
X_Continue = 2;
}
#if 1
{
unsigned char mm;
for(mm=0;mm<26;mm++)
{
FrameBuff[mm]=FDB[UnicodeOffset[mm]];
// DbgPrint("%c",FrameBuff[mm]);
}
}
#endif
}
else
{
//not long file name fdb
}
}
//not long file name fdb
return X_Continue;
}
#endif// End of ID3 Tag Supported
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -