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