1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
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 ****************************************************************************/
25 #include <timefuncs.h>
42 #include "mp3_playback.h"
44 #include "backlight.h"
48 #include "powermgmt.h"
55 #if CONFIG_CODEC == SWCODEC
56 unsigned char codecbuf
[CODEC_SIZE
];
58 void *sim_codec_load_ram(char* codecptr
, int size
,
59 void* ptr2
, int bufwrap
, void **pd
);
60 void sim_codec_close(void *pd
);
62 #define sim_codec_close(x)
63 extern unsigned char codecbuf
[];
66 extern void* plugin_get_audio_buffer(size_t *buffer_size
);
68 struct codec_api ci_voice
;
70 struct codec_api ci
= {
75 NULL
, /* taginfo_ready */
76 false, /* stop_codec */
79 NULL
, /* get_codec_memory */
80 NULL
, /* pcmbuf_insert */
81 NULL
, /* set_elapsed */
82 NULL
, /* read_filebuf */
83 NULL
, /* request_buffer */
84 NULL
, /* advance_buffer */
85 NULL
, /* advance_buffer_loc */
86 NULL
, /* seek_buffer */
87 NULL
, /* seek_complete */
88 NULL
, /* mp3_get_filepos */
89 NULL
, /* request_next_track */
90 NULL
, /* discard_codec */
91 NULL
, /* set_offset */
98 /* strings and memory */
110 #if defined(DEBUG) || defined(SIMULATOR)
113 #ifdef ROCKBOX_HAS_LOGF
127 #if defined(HAVE_RECORDING) && !defined(SIMULATOR)
128 false, /* stop_encoder */
129 0, /* enc_codec_loaded */
134 enc_pcm_buf_near_empty
,
139 (open_func
)PREFIX(open
),
145 #ifdef HAVE_ADJUSTABLE_CPU_FREQ
146 #ifdef CPU_BOOST_LOGGING
153 round_value_to_list32
,
157 /* new stuff at the end, sort into place next time
158 the API gets incompatible */
160 #ifdef CACHE_FUNCTIONS_AS_CALL
166 void codec_get_full_path(char *path
, const char *codec_root_fn
)
168 snprintf(path
, MAX_PATH
-1, CODECS_DIR
"/%s." CODEC_EXTENSION
,
172 int codec_load_ram(char* codecptr
, int size
, void* ptr2
, int bufwrap
,
173 struct codec_api
*api
)
175 struct codec_header
*hdr
;
180 if ((char *)&codecbuf
[0] != codecptr
) {
181 size
= MIN(size
, CODEC_SIZE
);
182 copy_n
= MIN(size
, bufwrap
);
183 memcpy(codecbuf
, codecptr
, copy_n
);
184 if (size
- copy_n
> 0) {
185 memcpy(&codecbuf
[copy_n
], ptr2
, size
- copy_n
);
187 api
->discard_codec();
189 hdr
= (struct codec_header
*)codecbuf
;
191 if (size
<= (signed)sizeof(struct codec_header
)
192 || (hdr
->magic
!= CODEC_MAGIC
193 #ifdef HAVE_RECORDING
194 && hdr
->magic
!= CODEC_ENC_MAGIC
197 || hdr
->target_id
!= TARGET_ID
198 || hdr
->load_addr
!= codecbuf
199 || hdr
->end_addr
> codecbuf
+ CODEC_SIZE
)
201 logf("codec header error");
204 #else /* SIMULATOR */
207 hdr
= sim_codec_load_ram(codecptr
, size
, ptr2
, bufwrap
, &pd
);
208 api
->discard_codec();
214 || hdr
->magic
!= CODEC_MAGIC
215 || hdr
->target_id
!= TARGET_ID
) {
219 #endif /* SIMULATOR */
220 if (hdr
->api_version
> CODEC_API_VERSION
221 || hdr
->api_version
< CODEC_MIN_API_VERSION
) {
227 status
= hdr
->entry_point(api
);
234 int codec_load_file(const char *plugin
, struct codec_api
*api
)
241 codec_get_full_path(path
, plugin
);
243 fd
= open(path
, O_RDONLY
);
245 snprintf(msgbuf
, sizeof(msgbuf
)-1, "Couldn't load codec: %s", path
);
246 logf("Codec load error:%d", fd
);
247 gui_syncsplash(HZ
*2, msgbuf
);
251 rc
= read(fd
, &codecbuf
[0], CODEC_SIZE
);
254 logf("Codec read error");
258 return codec_load_ram(codecbuf
, (size_t)rc
, NULL
, 0, api
);