📄 id3.c
字号:
//++
//id3.c - MP3 Player Compact Flash Card functions
//
// Copyright (C) 2005 by Spare Time Gizmos. All rights reserved.
//
// This file is part of the Spare Time Gizmos' MP3 Player firmware.
//
// This firmware 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.
//
//DESCRIPTION:
//
//REFERENCES:
// http://en.wikipedia.org/wiki/ID3
//
//REVISION HISTORY:
// dd-mmm-yy who description
// 19-Oct-05 RLA Split off from fat.c
// Add STACKSLOCS hack to ReadID3Tag() for SDCC.
//--
// Include files...
#include <stdio.h> // needed so DBGOUT(()) can find printf!
#include <string.h> // strcpy(), etc...
#include "standard.h" // standard types - BYTE, WORD, BOOL, etc
#include "buffer.h" // Buffer management functions
#include "fat.h" // declarations for this module
#include "id3.h" // ID3 v1.1 definitions
// Public members...
PUBLIC XDATA char g_szArtistName[ID3_MAX_ARTIST_NAME];
PUBLIC XDATA char g_szTrackName[ID3_MAX_TRACK_NAME];
//++
// This routine will read the last 128 bytes of the specified file and then
// does some rudimentary checking of the ID3 tag signature to ensure that it's
// valid. If the file does contain a valid ID3 tag, then the artist and track
// names are stored in the XDATA globals g_szArtistName/g_szTrackName and TRUE
// is returned.
//
// Ideally we'd just like to return the entire ID3_TAG structure as a global,
// but that contains a lot of fields that we never use and takes up 128 bytes
// of XDATA RAM. The artist and track names alone, however, only take 60 bytes.
// It's not a problem on the P89C668, but with the '664 MCU XDATA is tight!
//
// Note that this requires a temporary buffer in which store the ID3 tag while
// we extract the artist and track names. One is easily allocated from the disk
// buffer pool, however we must be sure to release it before we return!
//--
PUBLIC BOOL ReadID3Tag (PXDIRENT pxDirEnt) STACKSLOCS
{
PIBCB pBCB; PXID3TAG pxTag;
memset(&g_szArtistName, 0, ID3_MAX_ARTIST_NAME);
memset(&g_szTrackName, 0, ID3_MAX_TRACK_NAME);
// Allocate a buffer and open the file...
ALLOCATE_BUFFER(pBCB);
if (pBCB == NULL) return FALSE;
pxTag = (ID3_TAG XDATA *) pBCB->pbBuffer;
OpenFile(pxDirEnt);
// Attempt to read the tag. If we fail (which can only happen in the case
// of a hardware error!) then just give up...
if (!ReadFileEnd((PXBYTE) pxTag, ID3_TAG_SIZE)) goto NOTAG;
// Ok, we've got _something_. Now do a few simple checks to see if it's
// really an ID3 tag or not.
if ( (pxTag->abID3[0] != 'T')
|| (pxTag->abID3[1] != 'A')
|| (pxTag->abID3[2] != 'G')) goto NOTAG;
if ((strlen(pxTag->szArtistName) == 0) && (strlen(pxTag->szTrackName) == 0)) goto NOTAG;
DBGOUT(("ReadID3Tag: artist=\"%.30s\", title=\"%.30s\"\n", pxTag->szArtistName, pxTag->szTrackName));
// Looks like a good tag - extract the artist and track names, and return TRUE.
strcpy(g_szArtistName, pxTag->szArtistName);
strcpy(g_szTrackName, pxTag->szTrackName);
CloseFile(); RELEASE_BUFFER(pBCB); return TRUE;
// Here if there is no tag. Close the file, release the buffer, and return FALSE.
NOTAG:
CloseFile(); RELEASE_BUFFER(pBCB); return FALSE;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -