Colour targets: Revert an optimisation from almost 18 months ago that actually turned...
[Rockbox.git] / firmware / export / id3.h
blob147d073ffe0a206d2818c74a9dd819b40f43b837
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
10 * Copyright (C) 2002 by Daniel Stenberg
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
20 ****************************************************************************/
21 #ifndef ID3_H
22 #define ID3_H
24 #include <stdbool.h>
25 #include "config.h"
26 #include "file.h"
28 #define ID3V2_BUF_SIZE 300
30 /* Audio file types. */
31 /* NOTE: The values of the AFMT_* items are used for the %fc tag in the WPS
32 - so new entries MUST be added to the end to maintain compatibility.
34 enum
36 AFMT_UNKNOWN = 0, /* Unknown file format */
38 /* start formats */
40 AFMT_MPA_L1, /* MPEG Audio layer 1 */
41 AFMT_MPA_L2, /* MPEG Audio layer 2 */
42 AFMT_MPA_L3, /* MPEG Audio layer 3 */
44 #if CONFIG_CODEC == SWCODEC
45 AFMT_AIFF, /* Audio Interchange File Format */
46 AFMT_PCM_WAV, /* Uncompressed PCM in a WAV file */
47 AFMT_OGG_VORBIS, /* Ogg Vorbis */
48 AFMT_FLAC, /* FLAC */
49 AFMT_MPC, /* Musepack */
50 AFMT_A52, /* A/52 (aka AC3) audio */
51 AFMT_WAVPACK, /* WavPack */
52 AFMT_ALAC, /* Apple Lossless Audio Codec */
53 AFMT_AAC, /* Advanced Audio Coding (AAC) in M4A container */
54 AFMT_SHN, /* Shorten */
55 AFMT_SID, /* SID File Format */
56 AFMT_ADX, /* ADX File Format */
57 AFMT_NSF, /* NESM (NES Sound Format) */
58 AFMT_SPEEX, /* Ogg Speex speech */
59 AFMT_SPC, /* SPC700 save state */
60 AFMT_APE, /* Monkey's Audio (APE) */
61 AFMT_WMA, /* WMAV1/V2 in ASF */
62 AFMT_MOD, /* Amiga MOD File Format */
63 #endif
65 /* add new formats at any index above this line to have a sensible order -
66 specified array index inits are used */
67 /* format arrays defined in id3.c */
69 AFMT_NUM_CODECS,
71 #if CONFIG_CODEC == SWCODEC && defined(HAVE_RECORDING)
72 /* masks to decompose parts */
73 CODEC_AFMT_MASK = 0x0fff,
74 CODEC_TYPE_MASK = 0x7000,
76 /* switch for specifying codec type when requesting a filename */
77 CODEC_TYPE_DECODER = (0 << 12), /* default */
78 CODEC_TYPE_ENCODER = (1 << 12),
79 #endif /* CONFIG_CODEC == SWCODEC && defined(HAVE_RECORDING) */
82 #if CONFIG_CODEC == SWCODEC
83 #define CODEC_EXTENSION "codec"
85 #ifdef HAVE_RECORDING
86 #define ENCODER_SUFFIX "_enc"
87 enum rec_format_indexes
89 __REC_FORMAT_START_INDEX = -1,
91 /* start formats */
93 REC_FORMAT_PCM_WAV,
94 REC_FORMAT_AIFF,
95 REC_FORMAT_WAVPACK,
96 REC_FORMAT_MPA_L3,
98 /* add new formats at any index above this line to have a sensible order -
99 specified array index inits are used
100 REC_FORMAT_CFG_NUM_BITS should allocate enough bits to hold the range
101 REC_FORMAT_CFG_VALUE_LIST should be in same order as indexes
104 REC_NUM_FORMATS,
106 REC_FORMAT_DEFAULT = REC_FORMAT_PCM_WAV,
107 REC_FORMAT_CFG_NUM_BITS = 2
110 #define REC_FORMAT_CFG_VAL_LIST "wave,aiff,wvpk,mpa3"
112 /* get REC_FORMAT_* corresponding AFMT_* */
113 extern const int rec_format_afmt[REC_NUM_FORMATS];
114 /* get AFMT_* corresponding REC_FORMAT_* */
115 extern const int afmt_rec_format[AFMT_NUM_CODECS];
117 #define AFMT_ENTRY(label, root_fname, enc_root_fname, ext_list) \
118 { label, root_fname, enc_root_fname, ext_list }
119 #else /* !HAVE_RECORDING */
120 #define AFMT_ENTRY(label, root_fname, enc_root_fname, ext_list) \
121 { label, root_fname, ext_list }
122 #endif /* HAVE_RECORDING */
123 #else /* !SWCODEC */
125 #define AFMT_ENTRY(label, root_fname, enc_root_fname, ext_list) \
126 { label, ext_list }
127 #endif /* CONFIG_CODEC == SWCODEC */
129 /* record describing the audio format */
130 struct afmt_entry
132 char label[8]; /* format label */
133 #if CONFIG_CODEC == SWCODEC
134 char *codec_root_fn; /* root codec filename (sans _enc and .codec) */
135 #ifdef HAVE_RECORDING
136 char *codec_enc_root_fn; /* filename of encoder codec */
137 #endif
138 #endif
139 char *ext_list; /* double NULL terminated extension
140 list for type with the first as
141 the default for recording */
144 /* database of labels and codecs. add formats per above enum */
145 extern const struct afmt_entry audio_formats[AFMT_NUM_CODECS];
147 struct mp3entry {
148 char path[MAX_PATH];
149 char* title;
150 char* artist;
151 char* album;
152 char* genre_string;
153 char* disc_string;
154 char* track_string;
155 char* year_string;
156 char* composer;
157 char* comment;
158 char* albumartist;
159 char* grouping;
160 int discnum;
161 int tracknum;
162 int version;
163 int layer;
164 int year;
165 unsigned char id3version;
166 unsigned int codectype;
167 unsigned int bitrate;
168 unsigned long frequency;
169 unsigned long id3v2len;
170 unsigned long id3v1len;
171 unsigned long first_frame_offset; /* Byte offset to first real MP3 frame.
172 Used for skipping leading garbage to
173 avoid gaps between tracks. */
174 unsigned long vbr_header_pos;
175 unsigned long filesize; /* without headers; in bytes */
176 unsigned long length; /* song length in ms */
177 unsigned long elapsed; /* ms played */
179 int lead_trim; /* Number of samples to skip at the beginning */
180 int tail_trim; /* Number of samples to remove from the end */
182 /* Added for Vorbis */
183 unsigned long samples; /* number of samples in track */
185 /* MP3 stream specific info */
186 unsigned long frame_count; /* number of frames in the file (if VBR) */
188 /* Used for A52/AC3 */
189 unsigned long bytesperframe; /* number of bytes per frame (if CBR) */
191 /* Xing VBR fields */
192 bool vbr;
193 bool has_toc; /* True if there is a VBR header in the file */
194 unsigned char toc[100]; /* table of contents */
196 /* these following two fields are used for local buffering */
197 char id3v2buf[ID3V2_BUF_SIZE];
198 char id3v1buf[4][92];
200 /* resume related */
201 unsigned long offset; /* bytes played */
202 int index; /* playlist index */
204 /* runtime database fields */
205 long tagcache_idx; /* 0=invalid, otherwise idx+1 */
206 int rating;
207 int score;
208 long playcount;
209 long lastplayed;
210 long playtime;
212 /* replaygain support */
214 #if CONFIG_CODEC == SWCODEC
215 char* track_gain_string;
216 char* album_gain_string;
217 long track_gain; /* 7.24 signed fixed point. 0 for no gain. */
218 long album_gain;
219 long track_peak; /* 7.24 signed fixed point. 0 for no peak. */
220 long album_peak;
221 #endif
223 /* Cuesheet support */
224 int cuesheet_type; /* 0: none, 1: external, 2: embedded */
227 enum {
228 ID3_VER_1_0 = 1,
229 ID3_VER_1_1,
230 ID3_VER_2_2,
231 ID3_VER_2_3,
232 ID3_VER_2_4
235 bool get_mp3_metadata(int fd, struct mp3entry *entry, const char *filename);
236 bool mp3info(struct mp3entry *entry, const char *filename);
237 char* id3_get_num_genre(unsigned int genre_num);
238 int getid3v2len(int fd);
239 void adjust_mp3entry(struct mp3entry *entry, void *dest, const void *orig);
240 void copy_mp3entry(struct mp3entry *dest, const struct mp3entry *orig);
242 #endif