Add Sun Audio codec. (FS#10433)
[kugel-rb.git] / apps / metadata.h
blobf5ca99eeffc2ff02655e5106f6a25ef7d0531311
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
10 * Copyright (C) 2005 Dave Chapman
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 ****************************************************************************/
22 #ifndef _METADATA_H
23 #define _METADATA_H
25 #include <stdbool.h>
26 #include "file.h"
27 #include "config.h"
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_MP4_ALAC, /* Apple Lossless Audio Codec */
53 AFMT_MP4_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 AFMT_SAP, /* Atari 8Bit SAP Format */
64 AFMT_RM_COOK, /* Cook in RM/RA */
65 AFMT_RM_AAC, /* AAC in RM/RA */
66 AFMT_RM_AC3, /* AC3 in RM/RA */
67 AFMT_RM_ATRAC3, /* ATRAC3 in RM/RA */
68 AFMT_CMC, /* Atari 8bit cmc format */
69 AFMT_CM3, /* Atari 8bit cm3 format */
70 AFMT_CMR, /* Atari 8bit cmr format */
71 AFMT_CMS, /* Atari 8bit cms format */
72 AFMT_DMC, /* Atari 8bit dmc format */
73 AFMT_DLT, /* Atari 8bit dlt format */
74 AFMT_MPT, /* Atari 8bit mpt format */
75 AFMT_MPD, /* Atari 8bit mpd format */
76 AFMT_RMT, /* Atari 8bit rmt format */
77 AFMT_TMC, /* Atari 8bit tmc format */
78 AFMT_TM8, /* Atari 8bit tm8 format */
79 AFMT_TM2, /* Atari 8bit tm2 format */
80 AFMT_OMA_ATRAC3, /* Atrac3 in Sony OMA container */
81 AFMT_SMAF, /* SMAF */
82 AFMT_AU, /* Sun Audio file */
83 #endif
85 /* add new formats at any index above this line to have a sensible order -
86 specified array index inits are used */
87 /* format arrays defined in id3.c */
89 AFMT_NUM_CODECS,
91 #if CONFIG_CODEC == SWCODEC && defined(HAVE_RECORDING)
92 /* masks to decompose parts */
93 CODEC_AFMT_MASK = 0x0fff,
94 CODEC_TYPE_MASK = 0x7000,
96 /* switch for specifying codec type when requesting a filename */
97 CODEC_TYPE_DECODER = (0 << 12), /* default */
98 CODEC_TYPE_ENCODER = (1 << 12),
99 #endif /* CONFIG_CODEC == SWCODEC && defined(HAVE_RECORDING) */
102 #if CONFIG_CODEC == SWCODEC
103 #define CODEC_EXTENSION "codec"
105 #ifdef HAVE_RECORDING
106 #define ENCODER_SUFFIX "_enc"
107 enum rec_format_indexes
109 __REC_FORMAT_START_INDEX = -1,
111 /* start formats */
113 REC_FORMAT_PCM_WAV,
114 REC_FORMAT_AIFF,
115 REC_FORMAT_WAVPACK,
116 REC_FORMAT_MPA_L3,
118 /* add new formats at any index above this line to have a sensible order -
119 specified array index inits are used
120 REC_FORMAT_CFG_NUM_BITS should allocate enough bits to hold the range
121 REC_FORMAT_CFG_VALUE_LIST should be in same order as indexes
124 REC_NUM_FORMATS,
126 REC_FORMAT_DEFAULT = REC_FORMAT_PCM_WAV,
127 REC_FORMAT_CFG_NUM_BITS = 2
130 #define REC_FORMAT_CFG_VAL_LIST "wave,aiff,wvpk,mpa3"
132 /* get REC_FORMAT_* corresponding AFMT_* */
133 extern const int rec_format_afmt[REC_NUM_FORMATS];
134 /* get AFMT_* corresponding REC_FORMAT_* */
135 extern const int afmt_rec_format[AFMT_NUM_CODECS];
137 #define AFMT_ENTRY(label, root_fname, enc_root_fname, ext_list) \
138 { label, root_fname, enc_root_fname, ext_list }
139 #else /* !HAVE_RECORDING */
140 #define AFMT_ENTRY(label, root_fname, enc_root_fname, ext_list) \
141 { label, root_fname, ext_list }
142 #endif /* HAVE_RECORDING */
144 #else /* !SWCODEC */
146 #define AFMT_ENTRY(label, root_fname, enc_root_fname, ext_list) \
147 { label, ext_list }
148 #endif /* CONFIG_CODEC == SWCODEC */
150 /** Database of audio formats **/
151 /* record describing the audio format */
152 struct afmt_entry
154 char label[8]; /* format label */
155 #if CONFIG_CODEC == SWCODEC
156 char *codec_root_fn; /* root codec filename (sans _enc and .codec) */
157 #ifdef HAVE_RECORDING
158 char *codec_enc_root_fn; /* filename of encoder codec */
159 #endif
160 #endif
161 char *ext_list; /* double NULL terminated extension
162 list for type with the first as
163 the default for recording */
166 /* database of labels and codecs. add formats per above enum */
167 extern const struct afmt_entry audio_formats[AFMT_NUM_CODECS];
169 #if MEMORYSIZE > 2
170 #define ID3V2_BUF_SIZE 900
171 #else
172 #define ID3V2_BUF_SIZE 300
173 #endif
175 enum {
176 ID3_VER_1_0 = 1,
177 ID3_VER_1_1,
178 ID3_VER_2_2,
179 ID3_VER_2_3,
180 ID3_VER_2_4
183 struct mp3entry {
184 char path[MAX_PATH];
185 char* title;
186 char* artist;
187 char* album;
188 char* genre_string;
189 char* disc_string;
190 char* track_string;
191 char* year_string;
192 char* composer;
193 char* comment;
194 char* albumartist;
195 char* grouping;
196 int discnum;
197 int tracknum;
198 int version;
199 int layer;
200 int year;
201 unsigned char id3version;
202 unsigned int codectype;
203 unsigned int bitrate;
204 unsigned long frequency;
205 unsigned long id3v2len;
206 unsigned long id3v1len;
207 unsigned long first_frame_offset; /* Byte offset to first real MP3 frame.
208 Used for skipping leading garbage to
209 avoid gaps between tracks. */
210 unsigned long vbr_header_pos;
211 unsigned long filesize; /* without headers; in bytes */
212 unsigned long length; /* song length in ms */
213 unsigned long elapsed; /* ms played */
215 int lead_trim; /* Number of samples to skip at the beginning */
216 int tail_trim; /* Number of samples to remove from the end */
218 /* Added for Vorbis */
219 unsigned long samples; /* number of samples in track */
221 /* MP3 stream specific info */
222 unsigned long frame_count; /* number of frames in the file (if VBR) */
224 /* Used for A52/AC3 */
225 unsigned long bytesperframe; /* number of bytes per frame (if CBR) */
227 /* Xing VBR fields */
228 bool vbr;
229 bool has_toc; /* True if there is a VBR header in the file */
230 unsigned char toc[100]; /* table of contents */
232 /* Added for ATRAC3 */
233 unsigned int channels; /* Number of channels in the stream */
234 unsigned int extradata_size; /* Size (in bytes) of the codec's extradata from the container */
235 /* these following two fields are used for local buffering */
236 char id3v2buf[ID3V2_BUF_SIZE];
237 char id3v1buf[4][92];
239 /* resume related */
240 unsigned long offset; /* bytes played */
241 int index; /* playlist index */
243 /* runtime database fields */
244 long tagcache_idx; /* 0=invalid, otherwise idx+1 */
245 int rating;
246 int score;
247 long playcount;
248 long lastplayed;
249 long playtime;
251 /* replaygain support */
253 #if CONFIG_CODEC == SWCODEC
254 char* track_gain_string;
255 char* album_gain_string;
256 long track_gain; /* 7.24 signed fixed point. 0 for no gain. */
257 long album_gain;
258 long track_peak; /* 7.24 signed fixed point. 0 for no peak. */
259 long album_peak;
260 #endif
262 /* Cuesheet support */
263 struct cuesheet *cuesheet;
265 /* Musicbrainz Track ID */
266 char* mb_track_id;
269 unsigned int probe_file_format(const char *filename);
270 bool get_metadata(struct mp3entry* id3, int fd, const char* trackname);
271 bool mp3info(struct mp3entry *entry, const char *filename);
272 void adjust_mp3entry(struct mp3entry *entry, void *dest, const void *orig);
273 void copy_mp3entry(struct mp3entry *dest, const struct mp3entry *orig);
274 #if CONFIG_CODEC == SWCODEC
275 void strip_tags(int handle_id);
276 #endif
278 #endif