Separate out voice options for .talk clips (FS #7249). This removes the assumptions...
[Rockbox.git] / apps / codecs.h
blob3823e7217772b66057b5591f49315c361fb8fd5a
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
10 * Copyright (C) 2002 Björn 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 _CODECS_H_
20 #define _CODECS_H_
22 /* instruct simulator code to not redefine any symbols when compiling codecs.
23 (the CODEC macro is defined in apps/codecs/Makefile) */
24 #ifdef CODEC
25 #define NO_REDEFINES_PLEASE
26 #endif
28 #ifndef MEM
29 #define MEM 2
30 #endif
32 #include <stdbool.h>
33 #include <stdlib.h>
34 #include "config.h"
35 #include "kernel.h"
36 #include "system.h"
37 #include "id3.h"
38 #include "audio.h"
39 #ifdef RB_PROFILE
40 #include "profile.h"
41 #include "thread.h"
42 #endif
43 #if (CONFIG_CODEC == SWCODEC)
44 #if !defined(SIMULATOR) && defined(HAVE_RECORDING)
45 #include "pcm_record.h"
46 #endif
47 #include "dsp.h"
48 #endif
49 #include "settings.h"
51 #ifdef CODEC
53 #if defined(DEBUG) || defined(SIMULATOR)
54 #undef DEBUGF
55 #define DEBUGF ci->debugf
56 #undef LDEBUGF
57 #define LDEBUGF ci->debugf
58 #else
59 #define DEBUGF(...)
60 #define LDEBUGF(...)
61 #endif
63 #ifdef ROCKBOX_HAS_LOGF
64 #undef LOGF
65 #define LOGF ci->logf
66 #else
67 #define LOGF(...)
68 #endif
70 #endif
72 #ifdef SIMULATOR
73 #define PREFIX(_x_) sim_ ## _x_
74 #else
75 #define PREFIX(_x_) _x_
76 #endif
78 /* magic for normal codecs */
79 #define CODEC_MAGIC 0x52434F44 /* RCOD */
80 /* magic for encoder codecs */
81 #define CODEC_ENC_MAGIC 0x52454E43 /* RENC */
83 /* increase this every time the api struct changes */
84 #define CODEC_API_VERSION 18
86 /* update this to latest version if a change to the api struct breaks
87 backwards compatibility (and please take the opportunity to sort in any
88 new function which are "waiting" at the end of the function table) */
89 #define CODEC_MIN_API_VERSION 18
91 /* codec return codes */
92 enum codec_status {
93 CODEC_OK = 0,
94 CODEC_USB_CONNECTED,
95 CODEC_ERROR = -1,
98 /* NOTE: To support backwards compatibility, only add new functions at
99 the end of the structure. Every time you add a new function,
100 remember to increase CODEC_API_VERSION. If you make changes to the
101 existing APIs then also update CODEC_MIN_API_VERSION to current
102 version
104 struct codec_api {
106 off_t filesize; /* Total file length */
107 off_t curpos; /* Current buffer position */
109 /* For gapless mp3 */
110 struct mp3entry *id3; /* TAG metadata pointer */
111 bool *taginfo_ready; /* Is metadata read */
113 /* Codec should periodically check if stop_codec is set to true.
114 In case it is, codec must return immediately */
115 bool stop_codec;
116 /* Codec should periodically check if new_track is non zero.
117 When it is, the codec should request a new track. */
118 int new_track;
119 /* If seek_time != 0, codec should seek to that song position (in ms)
120 if codec supports seeking. */
121 long seek_time;
123 /* Returns buffer to malloc array. Only codeclib should need this. */
124 void* (*get_codec_memory)(size_t *size);
125 /* Insert PCM data into audio buffer for playback. Playback will start
126 automatically. */
127 bool (*pcmbuf_insert)(const void *ch1, const void *ch2, int count);
128 /* Set song position in WPS (value in ms). */
129 void (*set_elapsed)(unsigned int value);
131 /* Read next <size> amount bytes from file buffer to <ptr>.
132 Will return number of bytes read or 0 if end of file. */
133 size_t (*read_filebuf)(void *ptr, size_t size);
134 /* Request pointer to file buffer which can be used to read
135 <realsize> amount of data. <reqsize> tells the buffer system
136 how much data it should try to allocate. If <realsize> is 0,
137 end of file is reached. */
138 void* (*request_buffer)(size_t *realsize, size_t reqsize);
139 /* Advance file buffer position by <amount> amount of bytes. */
140 void (*advance_buffer)(size_t amount);
141 /* Advance file buffer to a pointer location inside file buffer. */
142 void (*advance_buffer_loc)(void *ptr);
143 /* Seek file buffer to position <newpos> beginning of file. */
144 bool (*seek_buffer)(size_t newpos);
145 /* Codec should call this function when it has done the seeking. */
146 void (*seek_complete)(void);
147 /* Calculate mp3 seek position from given time data in ms. */
148 off_t (*mp3_get_filepos)(int newtime);
149 /* Request file change from file buffer. Returns true is next
150 track is available and changed. If return value is false,
151 codec should exit immediately with PLUGIN_OK status. */
152 bool (*request_next_track)(void);
153 /* Free the buffer area of the current codec after its loaded */
154 void (*discard_codec)(void);
156 void (*set_offset)(size_t value);
157 /* Configure different codec buffer parameters. */
158 void (*configure)(int setting, intptr_t value);
160 /* kernel/ system */
161 void (*PREFIX(sleep))(int ticks);
162 void (*yield)(void);
164 /* strings and memory */
165 char* (*strcpy)(char *dst, const char *src);
166 char* (*strncpy)(char *dst, const char *src, size_t length);
167 size_t (*strlen)(const char *str);
168 int (*strcmp)(const char *, const char *);
169 char *(*strcat)(char *s1, const char *s2);
170 void* (*memset)(void *dst, int c, size_t length);
171 void* (*memcpy)(void *out, const void *in, size_t n);
172 void* (*memmove)(void *out, const void *in, size_t n);
173 int (*memcmp)(const void *s1, const void *s2, size_t n);
174 void *(*memchr)(const void *s1, int c, size_t n);
176 #if defined(DEBUG) || defined(SIMULATOR)
177 void (*debugf)(const char *fmt, ...) ATTRIBUTE_PRINTF(1, 2);
178 #endif
179 #ifdef ROCKBOX_HAS_LOGF
180 void (*logf)(const char *fmt, ...) ATTRIBUTE_PRINTF(1, 2);
181 #endif
183 /* Tremor requires qsort */
184 void (*qsort)(void *base, size_t nmemb, size_t size,
185 int(*compar)(const void *, const void *));
187 /* The ADX codec accesses global_settings to test for REPEAT_ONE mode */
188 struct user_settings* global_settings;
190 #ifdef RB_PROFILE
191 void (*profile_thread)(void);
192 void (*profstop)(void);
193 void (*profile_func_enter)(void *this_fn, void *call_site);
194 void (*profile_func_exit)(void *this_fn, void *call_site);
195 #endif
197 #if defined(HAVE_RECORDING) && !defined(SIMULATOR)
198 volatile bool stop_encoder;
199 volatile int enc_codec_loaded; /* <0=error, 0=pending, >0=ok */
200 void (*enc_get_inputs)(struct enc_inputs *inputs);
201 void (*enc_set_parameters)(struct enc_parameters *params);
202 struct enc_chunk_hdr * (*enc_get_chunk)(void);
203 void (*enc_finish_chunk)(void);
204 int (*enc_pcm_buf_near_empty)(void);
205 unsigned char * (*enc_get_pcm_data)(size_t size);
206 size_t (*enc_unget_pcm_data)(size_t size);
208 /* file */
209 int (*PREFIX(open))(const char* pathname, int flags);
210 int (*close)(int fd);
211 ssize_t (*read)(int fd, void* buf, size_t count);
212 off_t (*PREFIX(lseek))(int fd, off_t offset, int whence);
213 ssize_t (*write)(int fd, const void* buf, size_t count);
215 /* Encoder codecs adjust CPU boost themselves */
216 #ifdef HAVE_ADJUSTABLE_CPU_FREQ
217 #ifdef CPU_BOOST_LOGGING
218 void (*cpu_boost_)(bool on_off,char*location,int line);
219 #else
220 void (*cpu_boost)(bool on_off);
221 #endif
222 #endif
224 int (*round_value_to_list32)(unsigned long value,
225 const unsigned long list[],
226 int count,
227 bool signd);
229 #endif
231 /* new stuff at the end, sort into place next time
232 the API gets incompatible */
236 /* codec header */
237 struct codec_header {
238 unsigned long magic; /* RCOD or RENC */
239 unsigned short target_id;
240 unsigned short api_version;
241 unsigned char *load_addr;
242 unsigned char *end_addr;
243 enum codec_status(*entry_point)(struct codec_api*);
246 #ifdef CODEC
247 #ifndef SIMULATOR
248 /* plugin_* is correct, codecs use the plugin linker script */
249 extern unsigned char plugin_start_addr[];
250 extern unsigned char plugin_end_addr[];
251 /* decoders */
252 #define CODEC_HEADER \
253 const struct codec_header __header \
254 __attribute__ ((section (".header")))= { \
255 CODEC_MAGIC, TARGET_ID, CODEC_API_VERSION, \
256 plugin_start_addr, plugin_end_addr, codec_start };
257 /* encoders */
258 #define CODEC_ENC_HEADER \
259 const struct codec_header __header \
260 __attribute__ ((section (".header")))= { \
261 CODEC_ENC_MAGIC, TARGET_ID, CODEC_API_VERSION, \
262 plugin_start_addr, plugin_end_addr, codec_start };
264 #else /* def SIMULATOR */
265 /* decoders */
266 #define CODEC_HEADER \
267 const struct codec_header __header = { \
268 CODEC_MAGIC, TARGET_ID, CODEC_API_VERSION, \
269 NULL, NULL, codec_start };
270 /* encoders */
271 #define CODEC_ENC_HEADER \
272 const struct codec_header __header = { \
273 CODEC_ENC_MAGIC, TARGET_ID, CODEC_API_VERSION, \
274 NULL, NULL, codec_start };
275 #endif /* SIMULATOR */
276 #endif /* CODEC */
278 /* create full codec path from root filenames in audio_formats[]
279 assumes buffer size is MAX_PATH */
280 void codec_get_full_path(char *path, const char *codec_root_fn);
282 /* defined by the codec loader (codec.c) */
283 int codec_load_ram(char* codecptr, int size, void* ptr2, int bufwrap,
284 struct codec_api *api);
285 int codec_load_file(const char* codec, struct codec_api *api);
287 /* defined by the codec */
288 enum codec_status codec_start(struct codec_api* rockbox);
290 #endif