Christian Schmiljun / mp3tag
Committer:
christi_s
Date:
Wed Jan 26 17:53:29 2011 +0000
Revision:
2:f07a503ce8fe
Parent:
1:432c333ddb3a
add \"bool mp3tag_readTagFF(FIL* openFile, Id3V1Tag* tag)\"

Who changed what in which revision?

UserRevisionLine numberNew contents of line
christi_s 0:93fe329984c8 1 /* mbed library for reading ID3v1 tags in mp3 files
christi_s 0:93fe329984c8 2 * Copyright (c) 2010 Christian Schmiljun
christi_s 0:93fe329984c8 3 *
christi_s 0:93fe329984c8 4 * Permission is hereby granted, free of charge, to any person obtaining a copy
christi_s 0:93fe329984c8 5 * of this software and associated documentation files (the "Software"), to deal
christi_s 0:93fe329984c8 6 * in the Software without restriction, including without limitation the rights
christi_s 0:93fe329984c8 7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
christi_s 0:93fe329984c8 8 * copies of the Software, and to permit persons to whom the Software is
christi_s 0:93fe329984c8 9 * furnished to do so, subject to the following conditions:
christi_s 0:93fe329984c8 10 *
christi_s 0:93fe329984c8 11 * The above copyright notice and this permission notice shall be included in
christi_s 0:93fe329984c8 12 * all copies or substantial portions of the Software.
christi_s 0:93fe329984c8 13 *
christi_s 0:93fe329984c8 14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
christi_s 0:93fe329984c8 15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
christi_s 0:93fe329984c8 16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
christi_s 0:93fe329984c8 17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
christi_s 0:93fe329984c8 18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
christi_s 0:93fe329984c8 19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
christi_s 0:93fe329984c8 20 * THE SOFTWARE.
christi_s 0:93fe329984c8 21 */
christi_s 0:93fe329984c8 22
christi_s 0:93fe329984c8 23 #include "mp3tag.h"
christi_s 0:93fe329984c8 24
christi_s 0:93fe329984c8 25 // see http://www.multimediasoft.com/amp3dj/help/index.html?amp3dj_00003e.htm
christi_s 1:432c333ddb3a 26 const char* const mp3tag_genres[MP3_ID3_GENRES] = {
christi_s 0:93fe329984c8 27 "Blues", "Classic Rock", "Country", "Dance",
christi_s 0:93fe329984c8 28 "Disco", "Funk", "Grunge", "Hip-Hop",
christi_s 0:93fe329984c8 29 "Jazz", "Metal", "New Age", "Oldies",
christi_s 0:93fe329984c8 30 "Other", "Pop", "R&B", "Rap",
christi_s 0:93fe329984c8 31 "Reggae", "Rock", "Techno", "Industrial",
christi_s 0:93fe329984c8 32 "Alternative", "Ska", "Death Metal", "Pranks",
christi_s 0:93fe329984c8 33 "Soundtrack", "Euro-Techno", "Ambient", "Trip-Hop",
christi_s 0:93fe329984c8 34 "Vocal", "Jazz+Funk", "Fusion", "Trance",
christi_s 0:93fe329984c8 35 "Classical", "Instrumental", "Acid", "House",
christi_s 0:93fe329984c8 36 "Game", "Sound Clip", "Gospel", "Noise",
christi_s 0:93fe329984c8 37 "AlternRock", "Bass", "Soul", "Punk",
christi_s 0:93fe329984c8 38 "Space", "Meditative", "Instrumental Pop", "Instrumental Rock",
christi_s 0:93fe329984c8 39 "Ethnic", "Gothic", "Darkwave", "Techno-Industrial",
christi_s 0:93fe329984c8 40 "Electronic", "Pop-Folk", "Eurodance", "Dream",
christi_s 0:93fe329984c8 41 "Southern Rock", "Comedy", "Cult", "Gangsta",
christi_s 0:93fe329984c8 42 "Top 40", "Christian Rap", "Pop/Funk", "Jungle",
christi_s 0:93fe329984c8 43 "Native American", "Cabaret", "New Wave", "Psychadelic",
christi_s 0:93fe329984c8 44 "Rave", "Showtunes", "Trailer", "Lo-Fi",
christi_s 0:93fe329984c8 45 "Tribal", "Acid Punk", "Acid Jazz", "Polka",
christi_s 0:93fe329984c8 46 "Retro", "Musical", "Rock & Roll", "Hard Rock",
christi_s 0:93fe329984c8 47 "Folk", "Folk/Rock", "National folk", "Swing",
christi_s 0:93fe329984c8 48 "Fast-fusion", "Bebob", "Latin", "Revival",
christi_s 0:93fe329984c8 49 "Celtic", "Bluegrass", "Avantgarde", "Gothic Rock",
christi_s 0:93fe329984c8 50 "Progressive Rock", "Psychedelic Rock", "Symphonic Rock", "Slow Rock",
christi_s 0:93fe329984c8 51 "Big Band", "Chorus", "Easy Listening", "Acoustic",
christi_s 0:93fe329984c8 52 "Humour", "Speech", "Chanson", "Opera",
christi_s 0:93fe329984c8 53 "Chamber Music", "Sonata", "Symphony", "Booty Bass",
christi_s 0:93fe329984c8 54 "Primus", "Porn Groove", "Satire", "Slow Jam",
christi_s 0:93fe329984c8 55 "Club", "Tango", "Samba", "Folklore",
christi_s 0:93fe329984c8 56 "Ballad", "Powder Ballad", "Rhythmic Soul", "Freestyle",
christi_s 0:93fe329984c8 57 "Duet", "Punk Rock", "Drum Solo", "A Capella",
christi_s 0:93fe329984c8 58 "Euro-House", "Dance Hall", "Goa", "Drum & Bass",
christi_s 0:93fe329984c8 59 "Club House", "Hardcore", "Terror", "Indie",
christi_s 0:93fe329984c8 60 "BritPop", "NegerPunk", "Polsk Punk", "Beat",
christi_s 0:93fe329984c8 61 "Christian Gangsta", "Heavy Metal", "Black Metal", "Crossover",
christi_s 0:93fe329984c8 62 "Contemporary C", "Christian Rock", "Merengue", "Salsa",
christi_s 0:93fe329984c8 63 "Thrash Metal", "Anime", "JPop", "SynthPop"
christi_s 0:93fe329984c8 64 };
christi_s 0:93fe329984c8 65
christi_s 0:93fe329984c8 66 bool mp3tag_readTag(FILE* openFile, Id3V1Tag* tag)
christi_s 0:93fe329984c8 67 {
christi_s 0:93fe329984c8 68 if (!openFile)
christi_s 0:93fe329984c8 69 {
christi_s 0:93fe329984c8 70 DEBUGOUT("MP3Tag: File not open.\r\n");
christi_s 0:93fe329984c8 71 return false;
christi_s 0:93fe329984c8 72 }
christi_s 0:93fe329984c8 73 // backup stream position
christi_s 0:93fe329984c8 74 fpos_t pos;
christi_s 0:93fe329984c8 75 fgetpos (openFile, &pos);
christi_s 0:93fe329984c8 76 if (fseek(openFile, -128, SEEK_END) || fread(tag, 1, 128, openFile) != 128)
christi_s 0:93fe329984c8 77 {
christi_s 0:93fe329984c8 78 DEBUGOUT("MP3Tag: Couldn't jump/read in file.\r\n");
christi_s 0:93fe329984c8 79 // restore stream position
christi_s 0:93fe329984c8 80 fsetpos (openFile, &pos);
christi_s 0:93fe329984c8 81 return false;
christi_s 0:93fe329984c8 82 }
christi_s 0:93fe329984c8 83 // restore stream position
christi_s 0:93fe329984c8 84 fsetpos (openFile, &pos);
christi_s 0:93fe329984c8 85 if (strncmp(tag->tag, "TAG", 3))
christi_s 0:93fe329984c8 86 {
christi_s 0:93fe329984c8 87 DEBUGOUT("MP3Tag: File doesn't have an ID3 tag.\r\n");
christi_s 0:93fe329984c8 88 return false;
christi_s 1:432c333ddb3a 89 }
christi_s 1:432c333ddb3a 90 DEBUGOUT("MP3Tag: GenreID %i.\r\n", tag->genre);
christi_s 0:93fe329984c8 91 DEBUGOUT("MP3Tag: Tags readed.\r\n");
christi_s 0:93fe329984c8 92 return true;
christi_s 0:93fe329984c8 93 }
christi_s 0:93fe329984c8 94
christi_s 2:f07a503ce8fe 95 bool mp3tag_readTagFF(FIL* openFile, Id3V1Tag* tag)
christi_s 2:f07a503ce8fe 96 {
christi_s 2:f07a503ce8fe 97 if (!openFile)
christi_s 2:f07a503ce8fe 98 {
christi_s 2:f07a503ce8fe 99 DEBUGOUT("MP3Tag: File not open.\r\n");
christi_s 2:f07a503ce8fe 100 return false;
christi_s 2:f07a503ce8fe 101 }
christi_s 2:f07a503ce8fe 102 // backup stream position
christi_s 2:f07a503ce8fe 103 DWORD pos = openFile->fptr;
christi_s 2:f07a503ce8fe 104 unsigned int n;
christi_s 2:f07a503ce8fe 105 if ( (f_lseek(openFile, openFile->fsize - 128) != FR_OK)
christi_s 2:f07a503ce8fe 106 || (f_read(openFile, tag, 128, &n) != FR_OK)
christi_s 2:f07a503ce8fe 107 || n != 128)
christi_s 2:f07a503ce8fe 108 {
christi_s 2:f07a503ce8fe 109 DEBUGOUT("MP3Tag: Couldn't jump/read in file.\r\n");
christi_s 2:f07a503ce8fe 110 // restore stream position
christi_s 2:f07a503ce8fe 111 f_lseek(openFile, pos);
christi_s 2:f07a503ce8fe 112 return false;
christi_s 2:f07a503ce8fe 113 }
christi_s 2:f07a503ce8fe 114
christi_s 2:f07a503ce8fe 115 // restore stream position
christi_s 2:f07a503ce8fe 116 f_lseek(openFile, pos);
christi_s 2:f07a503ce8fe 117 if (strncmp(tag->tag, "TAG", 3))
christi_s 2:f07a503ce8fe 118 {
christi_s 2:f07a503ce8fe 119 DEBUGOUT("MP3Tag: File doesn't have an ID3 tag.\r\n");
christi_s 2:f07a503ce8fe 120 return false;
christi_s 2:f07a503ce8fe 121 }
christi_s 2:f07a503ce8fe 122 DEBUGOUT("MP3Tag: GenreID %i.\r\n", tag->genre);
christi_s 2:f07a503ce8fe 123 DEBUGOUT("MP3Tag: Tags readed.\r\n");
christi_s 2:f07a503ce8fe 124 return true;
christi_s 2:f07a503ce8fe 125 }
christi_s 2:f07a503ce8fe 126
christi_s 0:93fe329984c8 127 char mp3tag_getTrackNumber(Id3V1Tag* tag)
christi_s 0:93fe329984c8 128 {
christi_s 0:93fe329984c8 129 if (tag->comment[28] == 0x00 && tag->comment[29] != 0x00)
christi_s 0:93fe329984c8 130 {
christi_s 0:93fe329984c8 131 DEBUGOUT("MP3Tag: Tag has track number: %i.\r\n", tag->comment[29]);
christi_s 0:93fe329984c8 132 return tag->comment[29];
christi_s 0:93fe329984c8 133 }
christi_s 0:93fe329984c8 134 DEBUGOUT("MP3Tag: Tag has no track number.\r\n");
christi_s 0:93fe329984c8 135 return 0x00;
christi_s 0:93fe329984c8 136 }
christi_s 0:93fe329984c8 137