2005-06-05 23:05:10 +00:00
|
|
|
/***************************************************************************
|
|
|
|
* __________ __ ___.
|
|
|
|
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
|
|
|
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
|
|
|
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
|
|
|
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
|
|
|
* \/ \/ \/ \/ \/
|
|
|
|
* $Id$
|
|
|
|
*
|
|
|
|
* Copyright (C) 2005 Dave Chapman
|
|
|
|
*
|
2008-06-28 18:10:04 +00:00
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
2005-06-05 23:05:10 +00:00
|
|
|
*
|
|
|
|
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
|
|
|
* KIND, either express or implied.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2005-06-22 19:41:30 +00:00
|
|
|
/* "helper functions" common to all codecs */
|
2005-06-05 23:05:10 +00:00
|
|
|
|
2008-05-03 21:33:00 +00:00
|
|
|
#include <string.h>
|
2005-10-13 11:32:52 +00:00
|
|
|
#include "codecs.h"
|
2005-09-21 13:09:10 +00:00
|
|
|
#include "dsp.h"
|
2005-06-05 23:05:10 +00:00
|
|
|
#include "codeclib.h"
|
2008-10-15 06:38:51 +00:00
|
|
|
#include "metadata.h"
|
2005-06-05 23:05:10 +00:00
|
|
|
|
2011-05-08 10:34:05 +00:00
|
|
|
/* The following variables are used by codec_malloc() to make use of free RAM
|
|
|
|
* within the statically allocated codec buffer. */
|
2011-05-10 18:20:56 +00:00
|
|
|
static size_t mem_ptr = 0;
|
|
|
|
static size_t bufsize = 0;
|
|
|
|
static unsigned char* mallocbuf = NULL;
|
2005-10-13 11:32:52 +00:00
|
|
|
|
2006-11-26 18:31:41 +00:00
|
|
|
int codec_init(void)
|
2005-06-22 19:41:30 +00:00
|
|
|
{
|
2011-05-08 19:50:39 +00:00
|
|
|
/* codec_get_buffer() aligns the resulting point to CACHEALIGN_SIZE. */
|
2005-06-05 23:05:10 +00:00
|
|
|
mem_ptr = 0;
|
2008-10-19 12:35:53 +00:00
|
|
|
mallocbuf = (unsigned char *)ci->codec_get_buffer((size_t *)&bufsize);
|
2005-06-05 23:05:10 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2005-07-24 15:32:28 +00:00
|
|
|
|
2011-04-27 03:08:23 +00:00
|
|
|
void codec_set_replaygain(const struct mp3entry *id3)
|
2005-07-24 15:32:28 +00:00
|
|
|
{
|
2007-02-10 16:47:13 +00:00
|
|
|
ci->configure(DSP_SET_TRACK_GAIN, id3->track_gain);
|
|
|
|
ci->configure(DSP_SET_ALBUM_GAIN, id3->album_gain);
|
|
|
|
ci->configure(DSP_SET_TRACK_PEAK, id3->track_peak);
|
|
|
|
ci->configure(DSP_SET_ALBUM_PEAK, id3->album_peak);
|
2005-07-24 15:32:28 +00:00
|
|
|
}
|
2005-10-13 11:32:52 +00:00
|
|
|
|
|
|
|
/* Various "helper functions" common to all the xxx2wav decoder plugins */
|
|
|
|
|
|
|
|
|
|
|
|
void* codec_malloc(size_t size)
|
|
|
|
{
|
|
|
|
void* x;
|
|
|
|
|
2006-03-03 02:27:19 +00:00
|
|
|
if (mem_ptr + (long)size > bufsize)
|
2005-10-13 11:32:52 +00:00
|
|
|
return NULL;
|
|
|
|
|
|
|
|
x=&mallocbuf[mem_ptr];
|
2011-05-08 19:50:39 +00:00
|
|
|
|
|
|
|
/* Keep memory aligned to CACHEALIGN_SIZE. */
|
|
|
|
mem_ptr += (size + (CACHEALIGN_SIZE-1)) & ~(CACHEALIGN_SIZE-1);
|
2005-10-13 11:32:52 +00:00
|
|
|
|
|
|
|
return(x);
|
|
|
|
}
|
|
|
|
|
|
|
|
void* codec_calloc(size_t nmemb, size_t size)
|
|
|
|
{
|
|
|
|
void* x;
|
|
|
|
x = codec_malloc(nmemb*size);
|
|
|
|
if (x == NULL)
|
|
|
|
return NULL;
|
2006-11-26 18:31:41 +00:00
|
|
|
ci->memset(x,0,nmemb*size);
|
2005-10-13 11:32:52 +00:00
|
|
|
return(x);
|
|
|
|
}
|
|
|
|
|
|
|
|
void codec_free(void* ptr) {
|
|
|
|
(void)ptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
void* codec_realloc(void* ptr, size_t size)
|
|
|
|
{
|
|
|
|
void* x;
|
|
|
|
(void)ptr;
|
|
|
|
x = codec_malloc(size);
|
|
|
|
return(x);
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t strlen(const char *s)
|
|
|
|
{
|
2006-11-26 18:31:41 +00:00
|
|
|
return(ci->strlen(s));
|
2005-10-13 11:32:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
char *strcpy(char *dest, const char *src)
|
|
|
|
{
|
2006-11-26 18:31:41 +00:00
|
|
|
return(ci->strcpy(dest,src));
|
2005-10-13 11:32:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
char *strcat(char *dest, const char *src)
|
|
|
|
{
|
2006-11-26 18:31:41 +00:00
|
|
|
return(ci->strcat(dest,src));
|
2005-10-13 11:32:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int strcmp(const char *s1, const char *s2)
|
|
|
|
{
|
2006-11-26 18:31:41 +00:00
|
|
|
return(ci->strcmp(s1,s2));
|
2005-10-13 11:32:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void *memcpy(void *dest, const void *src, size_t n)
|
|
|
|
{
|
2006-11-26 18:31:41 +00:00
|
|
|
return(ci->memcpy(dest,src,n));
|
2005-10-13 11:32:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void *memset(void *s, int c, size_t n)
|
|
|
|
{
|
2006-11-26 18:31:41 +00:00
|
|
|
return(ci->memset(s,c,n));
|
2005-10-13 11:32:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int memcmp(const void *s1, const void *s2, size_t n)
|
|
|
|
{
|
2006-11-26 18:31:41 +00:00
|
|
|
return(ci->memcmp(s1,s2,n));
|
2005-10-13 11:32:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void* memchr(const void *s, int c, size_t n)
|
|
|
|
{
|
2006-11-26 18:31:41 +00:00
|
|
|
return(ci->memchr(s,c,n));
|
2005-10-13 11:32:52 +00:00
|
|
|
}
|
|
|
|
|
2006-02-06 16:04:01 +00:00
|
|
|
void *memmove(void *dest, const void *src, size_t n)
|
2005-10-13 11:32:52 +00:00
|
|
|
{
|
2006-11-26 18:31:41 +00:00
|
|
|
return(ci->memmove(dest,src,n));
|
2005-10-13 11:32:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void qsort(void *base, size_t nmemb, size_t size,
|
|
|
|
int(*compar)(const void *, const void *))
|
|
|
|
{
|
2006-11-26 18:31:41 +00:00
|
|
|
ci->qsort(base,nmemb,size,compar);
|
2005-10-13 11:32:52 +00:00
|
|
|
}
|
2006-01-18 20:54:13 +00:00
|
|
|
|
2009-12-05 16:47:43 +00:00
|
|
|
/* From ffmpeg - libavutil/common.h */
|
2009-12-09 02:24:45 +00:00
|
|
|
const uint8_t bs_log2_tab[256] ICONST_ATTR = {
|
2009-12-05 16:47:43 +00:00
|
|
|
0,0,1,1,2,2,2,2,3,3,3,3,3,3,3,3,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,
|
|
|
|
5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,
|
|
|
|
6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,
|
|
|
|
6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,
|
|
|
|
7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7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* This workaround is required for coldfire gcc 3.4 but is broken for 4.4
|
|
|
|
and 4.5, but for those the other way works. */
|
|
|
|
#if defined(CPU_COLDFIRE) && defined(__GNUC__) && __GNUC__ < 4
|
2006-01-18 20:54:13 +00:00
|
|
|
(void)call_site;
|
2006-11-26 18:31:41 +00:00
|
|
|
ci->profile_func_enter(this_fn, __builtin_return_address(1));
|
2006-03-09 01:37:52 +00:00
|
|
|
#else
|
2006-11-26 18:31:41 +00:00
|
|
|
ci->profile_func_enter(this_fn, call_site);
|
2006-03-09 01:37:52 +00:00
|
|
|
#endif
|
2006-01-18 20:54:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void __cyg_profile_func_exit(void *this_fn, void *call_site) {
|
2006-11-26 18:31:41 +00:00
|
|
|
ci->profile_func_exit(this_fn,call_site);
|
2006-01-18 20:54:13 +00:00
|
|
|
}
|
|
|
|
#endif
|