include/ax_resource/ax_mp3info.h

Go to the documentation of this file.
00001 
00002 // Name:        ax_mp3info.h
00003 // Purpose:     MP3 info class
00004 // Author:      Roman Nurik, Julian Smart
00005 // Modified by:
00006 // Created:     2009-01-03
00007 // RCS-ID:      $Id$
00008 // Copyright:   (c) Roman Nurik, Julian Smart
00009 //              Released under the New BSD License
00010 //              with kind permission from Roman Nurik.
00011 // Licence:     New BSD License
00020 
00021 #ifndef _AX_MP3INFO_H_
00022 #define _AX_MP3INFO_H_
00023 
00024 // list of genres
00025 static char* g_arrMP3Genre[] = {
00026         "Blues","Classic Rock","Country","Dance","Disco","Funk","Grunge","Hip-Hop",
00027         "Jazz","Metal","New Age","Oldies","Other","Pop","R&B","Rap","Reggae","Rock",
00028         "Techno","Industrial","Alternative","Ska","Death Metal","Pranks","Soundtrack",
00029         "Euro-Techno","Ambient","Trip Hop","Vocal","Jazz Funk","Fusion","Trance",
00030         "Classical","Instrumental","Acid","House","Game","Sound Clip","Gospel","Noise",
00031         "Alternative Rock","Bass","Soul","Punk","Space","Meditative","Instrumental Pop",
00032         "Instrumental Rock","Ethnic","Gothic","Darkwave","Techno-Industrial","Electronic",
00033         "Pop Folk","Eurodance","Dream","Southern Rock","Comedy","Cult","Gangsta","Top 40",
00034         "Christian Rap","Pop Funk","Jungle","Native American","Cabaret","New Wave",
00035         "Psychadelic","Rave","ShowTunes","Trailer","Lo-Fi","Tribal","Acid Punk","Acid Jazz",
00036         "Polka","Retro","Musical","Rock & Roll","Hard Rock","Folk","Folk Rock",
00037         "National Folk","Swing","Fast Fusion","Bebob","Latin","Revival","Celtic",
00038         "Bluegrass","Avantgarde","Gothic Rock","Progressive Rock","Psychedelic Rock",
00039         "Symphonic Rock","Slow Rock","Big Band","Chorus","Easy Listening","Acoustic",
00040         "Humour","Speech","Chanson","Opera","Chamber Music","Sonata","Symphony","Booty Bass",
00041         "Primus","Porn Groove","Satire","Slow Jam","Club","Tango","Samba","Folklore","Ballad",
00042         "Power Ballad","Rhytmic Soul","Freestyle","Duet","Punk Rock","Drum Solo","A Capella",
00043         "Euro House","Dance Hall","Goa","Drum & Bass","Club House","Hardcore","Terror",
00044         "Indie","BritPop","Negerpunk","Polsk Punk","Beat","Christian Gangsta Rap",
00045         "Heavy Metal","Black Metal","Crossover","Contemporary Christian","Christian Rock",
00046         "Merengue","Salsa","Trash Metal","Anime","JPop","SynthPop"
00047 };
00048 
00049 static int g_nMP3GenreCount = 148;
00050 
00051 // matrix of bitrates [based on MPEG version data][bitrate index]
00052 static int g_nMP3BitRate[6][16] = {
00053         {0,32,64,96,128,160,192,224,256,288,320,352,384,416,448,-1},
00054         {0,32,48,56, 64, 80, 96,112,128,160,192,224,256,320,384,-1},
00055         {0,32,40,48, 56, 64, 80, 96,112,128,160,192,224,256,320,-1},
00056         {0,32,48,56, 64, 80, 96,112,128,144,160,176,192,224,256,-1},
00057         {0, 8,16,24, 32, 40, 48, 56, 64, 80, 96,112,128,144,160,-1},
00058         {0, 8,16,24, 32, 64, 80, 56, 64,128,160,112,128,256,320,-1},
00059 };
00060 
00061 // MP3FRAMEHEADER structure
00062 struct MP3FRAMEHEADER
00063 {
00064         unsigned emphasis : 2;                  // M
00065         unsigned original : 1;                  // L
00066         unsigned copyright : 1;                 // K
00067         unsigned modeext : 2;                   // J
00068         unsigned chanmode : 2;                  // I
00069         unsigned privbit : 1;                   // H
00070         unsigned padding : 1;                   // G
00071         unsigned samplerate : 2;                // F
00072         unsigned bitrate : 4;                   // E
00073         unsigned hascrc : 1;                    // D
00074         unsigned mpeglayer : 2;                 // C
00075         unsigned mpegver : 2;                   // B
00076         unsigned framesync : 11;                // A
00077 };
00078 
00079 // MP3ID3V1TAG structure
00080 struct MP3ID3V1TAG
00081 {
00082         char ident[3]; // TAG
00083         char title[30];
00084         char artist[30];
00085         char album[30];
00086         char year[4];
00087         char comment[28];
00088         wxByte reserved;
00089         wxByte tracknum;
00090         wxByte genre;
00091 };
00092 
00093 // ENMPEGVER enumeration
00094 enum ENMPEGVER
00095 {
00096         MPEGVER_NA,             // reserved, N/A
00097         MPEGVER_25,             // 2.5
00098         MPEGVER_2,              // 2.0 (ISO/IEC 13818-3)
00099         MPEGVER_1               // 1.0 (ISO/IEC 11172-3)
00100 };
00101 
00102 // ENCHANNELMODE enumeration
00103 enum ENCHANNELMODE
00104 {
00105         MP3CM_STEREO,
00106         MP3CM_JOINT_STEREO,
00107         MP3CM_DUAL_CHANNEL,
00108         MP3CM_SINGLE_CHANNEL
00109 };
00110 
00111 // ENEMPHASIS enumeration
00112 enum ENEMPHASIS
00113 {
00114         MP3EM_NONE,
00115         MP3EM_50_15_MS,         // 50/15 ms
00116         MP3EM_RESERVED,
00117         MP3EM_CCIT_J17          // CCIT J.17
00118 };
00119 
00120 // bitmask of validity of files
00121 #define MP3VLD_INVALID                  0x0000
00122 #define MP3VLD_ID3V1_VALID              0x0001
00123 #define MP3VLD_DATA_VALID               0x0002
00124 
00125 // AxMP3Info class
00126 class AxMP3Info
00127 {
00128 private:
00129         wxString m_strFile;
00130         wxUint32 m_dwValidity;
00131 
00132         // ID3V1 information
00133         wxString m_strArtist;
00134         wxString m_strTitle;
00135         wxString m_strAlbum;
00136         wxString m_strComment;
00137         wxString m_strYear;
00138         int m_nTrack;
00139         int m_nGenre;
00140 
00141         // MP3 frame information
00142         int m_nFrames;
00143         int m_nLength;                                  // in seconds
00144         ENMPEGVER m_enMPEGVersion;
00145         int m_nMPEGLayer;
00146         bool m_bHasCRC;
00147         int m_nBitRate;                                 // average if VBR, 0 if "free"
00148         int m_nSampleRate;
00149         ENCHANNELMODE m_enChannelMode;
00150         ENEMPHASIS m_enEmphasis;
00151         bool m_bCopyrighted;
00152         bool m_bOriginal;
00153 
00154 public:
00155         AxMP3Info(wxString strFile = wxEmptyString);
00156         virtual ~AxMP3Info();
00157 
00158 // operations
00159         bool Open(wxString strFile);
00160         // bool WriteID3V1(wxString strDestFile = wxEmptyString, bool bClear = FALSE); // defaults to current file
00161         void Clear();
00162 
00163         void SetArtist(wxString strArtist){ m_strArtist = strArtist; }
00164         void SetTitle(wxString strTitle){ m_strTitle = strTitle; }
00165         void SetAlbum(wxString strAlbum){ m_strAlbum = strAlbum; }
00166         void SetComment(wxString strComment){ m_strComment = strComment; }
00167         void SetYear(wxString strYear){ m_strYear = strYear; }
00168         void SetTrack(int nTrack){ m_nTrack = nTrack; }
00169         void SetGenreIndex(int nGenre){ m_nGenre = nGenre; }
00170 
00171 // attributes
00172         wxString GetFileName() const { return m_strFile; }
00173         wxUint32 GetValidity() const { return m_dwValidity; }
00174 
00175         wxString GetArtist() const { return m_strArtist; }
00176         wxString GetTitle() const { return m_strTitle; }
00177         wxString GetAlbum() const { return m_strAlbum; }
00178         wxString GetComment() const { return m_strComment; }
00179         wxString GetYear() const { return m_strYear; }
00180         int GetTrack() const { return m_nTrack; }
00181         int GetGenreIndex() const { return m_nGenre; }
00182 
00183         int GetNumFrames() const { return m_nFrames; }
00184         int GetLength() const { return m_nLength; }
00185         ENMPEGVER GetMPEGVersion() const { return m_enMPEGVersion; }
00186         int GetMPEGLayer() const { return m_nMPEGLayer; }
00187         bool HasCRC() const { return m_bHasCRC; }
00188         int GetBitRate() const { return m_nBitRate; }
00189         int GetSampleRate() const { return m_nSampleRate; }
00190         ENCHANNELMODE GetChannelMode() const { return m_enChannelMode; }
00191         ENEMPHASIS GetEmphasis() const { return m_enEmphasis; }
00192         bool IsCopyrighted() const { return m_bCopyrighted; }
00193         bool IsOriginal() const { return m_bOriginal; }
00194 
00195 // functions
00196         static wxString GetGenreString(int nIndex);
00197         static wxString GetLengthString(int nSeconds);
00198 
00199 private:
00200 // helper functions
00201         bool GetNextFrameHeader(FILE* hFile, MP3FRAMEHEADER* pHeader, int nPassBytes = 0);
00202         void ChangeEndian(void* pBuffer, int nBufSize);
00203 };
00204 
00205 #endif
00206     // _AX_MP3INFO_H_

Generated on Wed May 6 19:20:18 2009 for AxTk by  doxygen 1.5.1