Mp3tag is a library for reading the meta-data of mp3 audio files. Currently it supports only ID3v1.
Embed:
(wiki syntax)
Show/hide line numbers
mp3tag.cpp
00001 /* mbed library for reading ID3v1 tags in mp3 files 00002 * Copyright (c) 2010 Christian Schmiljun 00003 * 00004 * Permission is hereby granted, free of charge, to any person obtaining a copy 00005 * of this software and associated documentation files (the "Software"), to deal 00006 * in the Software without restriction, including without limitation the rights 00007 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 00008 * copies of the Software, and to permit persons to whom the Software is 00009 * furnished to do so, subject to the following conditions: 00010 * 00011 * The above copyright notice and this permission notice shall be included in 00012 * all copies or substantial portions of the Software. 00013 * 00014 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 00015 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 00016 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 00017 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 00018 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 00019 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 00020 * THE SOFTWARE. 00021 */ 00022 00023 #include "mp3tag.h" 00024 00025 // see http://www.multimediasoft.com/amp3dj/help/index.html?amp3dj_00003e.htm 00026 const char* const mp3tag_genres[MP3_ID3_GENRES] = { 00027 "Blues", "Classic Rock", "Country", "Dance", 00028 "Disco", "Funk", "Grunge", "Hip-Hop", 00029 "Jazz", "Metal", "New Age", "Oldies", 00030 "Other", "Pop", "R&B", "Rap", 00031 "Reggae", "Rock", "Techno", "Industrial", 00032 "Alternative", "Ska", "Death Metal", "Pranks", 00033 "Soundtrack", "Euro-Techno", "Ambient", "Trip-Hop", 00034 "Vocal", "Jazz+Funk", "Fusion", "Trance", 00035 "Classical", "Instrumental", "Acid", "House", 00036 "Game", "Sound Clip", "Gospel", "Noise", 00037 "AlternRock", "Bass", "Soul", "Punk", 00038 "Space", "Meditative", "Instrumental Pop", "Instrumental Rock", 00039 "Ethnic", "Gothic", "Darkwave", "Techno-Industrial", 00040 "Electronic", "Pop-Folk", "Eurodance", "Dream", 00041 "Southern Rock", "Comedy", "Cult", "Gangsta", 00042 "Top 40", "Christian Rap", "Pop/Funk", "Jungle", 00043 "Native American", "Cabaret", "New Wave", "Psychadelic", 00044 "Rave", "Showtunes", "Trailer", "Lo-Fi", 00045 "Tribal", "Acid Punk", "Acid Jazz", "Polka", 00046 "Retro", "Musical", "Rock & Roll", "Hard Rock", 00047 "Folk", "Folk/Rock", "National folk", "Swing", 00048 "Fast-fusion", "Bebob", "Latin", "Revival", 00049 "Celtic", "Bluegrass", "Avantgarde", "Gothic Rock", 00050 "Progressive Rock", "Psychedelic Rock", "Symphonic Rock", "Slow Rock", 00051 "Big Band", "Chorus", "Easy Listening", "Acoustic", 00052 "Humour", "Speech", "Chanson", "Opera", 00053 "Chamber Music", "Sonata", "Symphony", "Booty Bass", 00054 "Primus", "Porn Groove", "Satire", "Slow Jam", 00055 "Club", "Tango", "Samba", "Folklore", 00056 "Ballad", "Powder Ballad", "Rhythmic Soul", "Freestyle", 00057 "Duet", "Punk Rock", "Drum Solo", "A Capella", 00058 "Euro-House", "Dance Hall", "Goa", "Drum & Bass", 00059 "Club House", "Hardcore", "Terror", "Indie", 00060 "BritPop", "NegerPunk", "Polsk Punk", "Beat", 00061 "Christian Gangsta", "Heavy Metal", "Black Metal", "Crossover", 00062 "Contemporary C", "Christian Rock", "Merengue", "Salsa", 00063 "Thrash Metal", "Anime", "JPop", "SynthPop" 00064 }; 00065 00066 bool mp3tag_readTag(FILE* openFile, Id3V1Tag* tag) 00067 { 00068 if (!openFile) 00069 { 00070 DEBUGOUT("MP3Tag: File not open.\r\n"); 00071 return false; 00072 } 00073 // backup stream position 00074 fpos_t pos; 00075 fgetpos (openFile, &pos); 00076 if (fseek(openFile, -128, SEEK_END) || fread(tag, 1, 128, openFile) != 128) 00077 { 00078 DEBUGOUT("MP3Tag: Couldn't jump/read in file.\r\n"); 00079 // restore stream position 00080 fsetpos (openFile, &pos); 00081 return false; 00082 } 00083 // restore stream position 00084 fsetpos (openFile, &pos); 00085 if (strncmp(tag->tag , "TAG", 3)) 00086 { 00087 DEBUGOUT("MP3Tag: File doesn't have an ID3 tag.\r\n"); 00088 return false; 00089 } 00090 DEBUGOUT("MP3Tag: GenreID %i.\r\n", tag->genre ); 00091 DEBUGOUT("MP3Tag: Tags readed.\r\n"); 00092 return true; 00093 } 00094 00095 bool mp3tag_readTagFF(FIL* openFile, Id3V1Tag* tag) 00096 { 00097 if (!openFile) 00098 { 00099 DEBUGOUT("MP3Tag: File not open.\r\n"); 00100 return false; 00101 } 00102 // backup stream position 00103 DWORD pos = openFile->fptr; 00104 unsigned int n; 00105 if ( (f_lseek(openFile, openFile->fsize - 128) != FR_OK) 00106 || (f_read(openFile, tag, 128, &n) != FR_OK) 00107 || n != 128) 00108 { 00109 DEBUGOUT("MP3Tag: Couldn't jump/read in file.\r\n"); 00110 // restore stream position 00111 f_lseek(openFile, pos); 00112 return false; 00113 } 00114 00115 // restore stream position 00116 f_lseek(openFile, pos); 00117 if (strncmp(tag->tag , "TAG", 3)) 00118 { 00119 DEBUGOUT("MP3Tag: File doesn't have an ID3 tag.\r\n"); 00120 return false; 00121 } 00122 DEBUGOUT("MP3Tag: GenreID %i.\r\n", tag->genre ); 00123 DEBUGOUT("MP3Tag: Tags readed.\r\n"); 00124 return true; 00125 } 00126 00127 char mp3tag_getTrackNumber(Id3V1Tag* tag) 00128 { 00129 if (tag->comment [28] == 0x00 && tag->comment [29] != 0x00) 00130 { 00131 DEBUGOUT("MP3Tag: Tag has track number: %i.\r\n", tag->comment [29]); 00132 return tag->comment [29]; 00133 } 00134 DEBUGOUT("MP3Tag: Tag has no track number.\r\n"); 00135 return 0x00; 00136 } 00137
Generated on Sun Jul 17 2022 03:42:55 by
1.7.2