1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
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 /* "helper functions" common to all codecs */
32 unsigned char* mp3buf
; // The actual MP3 buffer from Rockbox
33 unsigned char* mallocbuf
; // 512K from the start of MP3 buffer
34 unsigned char* filebuf
; // The rest of the MP3 buffer
39 mallocbuf
= (unsigned char *)ci
->codec_get_buffer((size_t *)&bufsize
);
44 void codec_set_replaygain(struct mp3entry
* id3
)
46 ci
->configure(DSP_SET_TRACK_GAIN
, id3
->track_gain
);
47 ci
->configure(DSP_SET_ALBUM_GAIN
, id3
->album_gain
);
48 ci
->configure(DSP_SET_TRACK_PEAK
, id3
->track_peak
);
49 ci
->configure(DSP_SET_ALBUM_PEAK
, id3
->album_peak
);
52 /* Various "helper functions" common to all the xxx2wav decoder plugins */
55 void* codec_malloc(size_t size
)
59 if (mem_ptr
+ (long)size
> bufsize
)
62 x
=&mallocbuf
[mem_ptr
];
63 mem_ptr
+=(size
+3)&~3; /* Keep memory 32-bit aligned */
68 void* codec_calloc(size_t nmemb
, size_t size
)
71 x
= codec_malloc(nmemb
*size
);
74 ci
->memset(x
,0,nmemb
*size
);
78 void codec_free(void* ptr
) {
82 void* codec_realloc(void* ptr
, size_t size
)
86 x
= codec_malloc(size
);
90 size_t strlen(const char *s
)
92 return(ci
->strlen(s
));
95 char *strcpy(char *dest
, const char *src
)
97 return(ci
->strcpy(dest
,src
));
100 char *strcat(char *dest
, const char *src
)
102 return(ci
->strcat(dest
,src
));
105 int strcmp(const char *s1
, const char *s2
)
107 return(ci
->strcmp(s1
,s2
));
110 void *memcpy(void *dest
, const void *src
, size_t n
)
112 return(ci
->memcpy(dest
,src
,n
));
115 void *memset(void *s
, int c
, size_t n
)
117 return(ci
->memset(s
,c
,n
));
120 int memcmp(const void *s1
, const void *s2
, size_t n
)
122 return(ci
->memcmp(s1
,s2
,n
));
125 void* memchr(const void *s
, int c
, size_t n
)
127 return(ci
->memchr(s
,c
,n
));
130 void *memmove(void *dest
, const void *src
, size_t n
)
132 return(ci
->memmove(dest
,src
,n
));
135 void qsort(void *base
, size_t nmemb
, size_t size
,
136 int(*compar
)(const void *, const void *))
138 ci
->qsort(base
,nmemb
,size
,compar
);
142 void __cyg_profile_func_enter(void *this_fn
, void *call_site
) {
145 ci
->profile_func_enter(this_fn
, __builtin_return_address(1));
147 ci
->profile_func_enter(this_fn
, call_site
);
151 void __cyg_profile_func_exit(void *this_fn
, void *call_site
) {
152 ci
->profile_func_exit(this_fn
,call_site
);