1 /*                                                     -*- linux-c -*-
2     Copyright (C) 2004 Tom Szilagyi
3 
4     This program is free software; you can redistribute it and/or modify
5     it under the terms of the GNU General Public License as published by
6     the Free Software Foundation; either version 2 of the License, or
7     (at your option) any later version.
8 
9     This program is distributed in the hope that it will be useful,
10     but WITHOUT ANY WARRANTY; without even the implied warranty of
11     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12     GNU General Public License for more details.
13 
14     You should have received a copy of the GNU General Public License
15     along with this program; if not, write to the Free Software
16     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17 
18     $Id: file_decoder.h 1245 2012-02-04 10:33:30Z assworth $
19 */
20 
21 #ifndef AQUALUNG_FILE_DECODER_H
22 #define AQUALUNG_FILE_DECODER_H
23 
24 #include <math.h>
25 
26 #include "../common.h"
27 #include "../metadata.h"
28 
29 
30 #ifdef __cplusplus
31 extern "C" {
32 #endif
33 
34 /* input libs */
35 #define NULL_LIB    0
36 #define CDDA_LIB    1
37 #define SNDFILE_LIB 2
38 #define FLAC_LIB    3
39 #define VORBIS_LIB  4
40 #define SPEEX_LIB   5
41 #define MPC_LIB     6
42 #define MAD_LIB     7
43 #define MOD_LIB     8
44 #define MAC_LIB     9
45 #define LAVC_LIB    10
46 #define WAVPACK_LIB 11
47 
48 
49 /* format_flags */
50 #define FORMAT_VBR 0x0001
51 #define FORMAT_UBR 0x0002
52 
53 typedef struct _fileinfo_t {
54         unsigned long long total_samples;
55         unsigned long sample_rate;
56 	int channels;
57         int is_mono;
58         int bps;
59 	char * format_str; /* buffer allocated in pdec */
60 	int format_flags;
61 } fileinfo_t;
62 
63 
64 typedef struct _file_decoder_t {
65 
66 	/* public */
67 	char * filename;
68 	int file_open;
69 	int file_lib;
70 	fileinfo_t fileinfo;
71 	unsigned long long sample_pos; /* used w/unknown length files only */
72 	unsigned long long samples_left;
73 	float voladj_db;
74 	float voladj_lin;
75 	int is_stream;
76 
77 	/* Note that the metadata block sent by meta_cb is still owned by
78 	   the file_decoder instance and should not be freed externally.
79 	   However, it can be modified and 'if (meta->writable)', it can be
80 	   written back to file by calling meta_write().
81 	*/
82 	metadata_t * meta;
83 	void (* meta_cb)(metadata_t *, void *);
84 	void * meta_cbdata;
85 	/* meta_write() returns one of META_ERROR_*, defined in metadata_api.h */
86 	int (* meta_write)(struct _file_decoder_t *, metadata_t *);
87 
88 	/* private */
89 	void * pdec; /* actually, it's (decoder_t *) */
90 
91 } file_decoder_t;
92 
93 
94 typedef struct _decoder_t {
95 
96 	file_decoder_t * fdec;
97 	void * pdata; /* opaque pointer to decoder-dependent struct */
98 
99 	struct _decoder_t * (* init)(file_decoder_t * fdec);
100 	void (* destroy)(struct _decoder_t * dec);
101 	int (* open)(struct _decoder_t * dec, char * filename);
102 	void (* send_metadata)(struct _decoder_t * dec);
103 	void (* set_rva)(struct _decoder_t * dec, float voladj);
104 	void (* close)(struct _decoder_t * dec);
105 	unsigned int (* read)(struct _decoder_t * dec, float * dest, int num);
106 	void (* seek)(struct _decoder_t * dec, unsigned long long seek_to_pos);
107 
108 	/* optional callbacks for stream decoders */
109 	void (* pause)(struct _decoder_t * dec);
110 	void (* resume)(struct _decoder_t * dec);
111 
112 	char format_str[MAXLEN];
113 	int format_flags;
114 } decoder_t;
115 
116 
117 /* return values from decoder_t.open() -- see dec_null.c for explanation */
118 #define DECODER_OPEN_SUCCESS 0
119 #define DECODER_OPEN_BADLIB  1
120 #define DECODER_OPEN_FERROR  2
121 
122 
123 int is_valid_extension(char ** valid_extensions, char * filename, int module);
124 
125 void file_decoder_init(void);
126 
127 file_decoder_t * file_decoder_new(void);
128 void file_decoder_delete(file_decoder_t * fdec);
129 
130 int file_decoder_open(file_decoder_t * fdec, char * filename);
131 void file_decoder_send_metadata(file_decoder_t * fdec);
132 void file_decoder_set_rva(file_decoder_t * fdec, float voladj);
133 void file_decoder_set_meta_cb(file_decoder_t * fdec,
134 			      void (* meta_cb)(metadata_t * meta, void * data),
135 			      void * data);
136 void file_decoder_close(file_decoder_t * fdec);
137 unsigned int file_decoder_read(file_decoder_t * fdec, float * dest, int num);
138 void file_decoder_seek(file_decoder_t * fdec, unsigned long long seek_to_pos);
139 
140 void file_decoder_pause(file_decoder_t * fdec);
141 void file_decoder_resume(file_decoder_t * fdec);
142 
143 float get_file_duration(char * file);
144 
145 int bigendianp(void);
146 
147 #define db2lin(x) ((x) > -90.0f ? powf(10.0f, (x) * 0.05f) : 0.0f)
148 
149 
150 #ifdef __cplusplus
151 } /* extern "C" */
152 #endif
153 
154 #endif /* AQUALUNG_FILE_DECODER_H */
155 
156 // vim: shiftwidth=8:tabstop=8:softtabstop=8 :
157 
158