2005-06-13 06:15:05 +00:00
|
|
|
/***************************************************************************
|
|
|
|
* __________ __ ___.
|
|
|
|
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
|
|
|
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
|
|
|
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
|
|
|
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
|
|
|
* \/ \/ \/ \/ \/
|
|
|
|
* $Id$
|
|
|
|
*
|
|
|
|
* Copyright (C) 2005 David Bryant
|
|
|
|
*
|
|
|
|
* All files in this archive are subject to the GNU General Public License.
|
|
|
|
* See the file COPYING in the source tree root for full license agreement.
|
|
|
|
*
|
|
|
|
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
|
|
|
* KIND, either express or implied.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2005-10-13 11:32:52 +00:00
|
|
|
#include "codeclib.h"
|
|
|
|
#include "libwavpack/wavpack.h"
|
2005-06-13 06:15:05 +00:00
|
|
|
|
2006-01-18 00:05:14 +00:00
|
|
|
CODEC_HEADER
|
|
|
|
|
2005-06-13 06:15:05 +00:00
|
|
|
static struct codec_api *ci;
|
|
|
|
|
|
|
|
#define BUFFER_SIZE 4096
|
|
|
|
|
2005-10-27 11:32:02 +00:00
|
|
|
static long temp_buffer [BUFFER_SIZE] IBSS_ATTR;
|
2005-06-13 06:15:05 +00:00
|
|
|
|
|
|
|
static long read_callback (void *buffer, long bytes)
|
|
|
|
{
|
2005-06-30 06:09:59 +00:00
|
|
|
long retval = ci->read_filebuf (buffer, bytes);
|
|
|
|
ci->id3->offset = ci->curpos;
|
|
|
|
return retval;
|
2005-06-13 06:15:05 +00:00
|
|
|
}
|
|
|
|
|
2005-09-23 00:12:02 +00:00
|
|
|
#ifdef USE_IRAM
|
2005-06-13 06:15:05 +00:00
|
|
|
extern char iramcopy[];
|
|
|
|
extern char iramstart[];
|
|
|
|
extern char iramend[];
|
2006-01-08 22:50:14 +00:00
|
|
|
extern char iedata[];
|
|
|
|
extern char iend[];
|
2005-06-13 06:15:05 +00:00
|
|
|
#endif
|
|
|
|
|
2005-06-22 19:41:30 +00:00
|
|
|
/* this is the codec entry point */
|
2005-06-22 19:55:09 +00:00
|
|
|
enum codec_status codec_start(struct codec_api* api)
|
2005-06-13 06:15:05 +00:00
|
|
|
{
|
|
|
|
WavpackContext *wpc;
|
|
|
|
char error [80];
|
2005-06-27 00:12:40 +00:00
|
|
|
int bps, nchans, sr_100;
|
2006-01-18 20:22:03 +00:00
|
|
|
int retval;
|
2005-06-13 06:15:05 +00:00
|
|
|
|
2005-06-22 19:41:30 +00:00
|
|
|
/* Generic codec initialisation */
|
|
|
|
ci = api;
|
2005-06-13 06:15:05 +00:00
|
|
|
|
2005-09-23 00:12:02 +00:00
|
|
|
#ifdef USE_IRAM
|
|
|
|
ci->memcpy(iramstart, iramcopy, iramend-iramstart);
|
2006-01-08 22:50:14 +00:00
|
|
|
ci->memset(iedata, 0, iend - iedata);
|
2005-06-13 06:15:05 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
ci->configure(CODEC_SET_FILEBUF_WATERMARK, (int *)(1024*512));
|
|
|
|
ci->configure(CODEC_SET_FILEBUF_CHUNKSIZE, (int *)(1024*128));
|
2005-06-26 19:41:29 +00:00
|
|
|
|
|
|
|
ci->configure(DSP_DITHER, (bool *)false);
|
2006-02-06 07:40:35 +00:00
|
|
|
ci->configure(DSP_SET_SAMPLE_DEPTH, (int *)(27)); // should be 28...
|
2005-06-13 06:15:05 +00:00
|
|
|
|
|
|
|
next_track:
|
|
|
|
|
2006-01-18 20:22:03 +00:00
|
|
|
if (codec_init(api)) {
|
|
|
|
retval = CODEC_ERROR;
|
|
|
|
goto exit;
|
|
|
|
}
|
2005-06-13 06:15:05 +00:00
|
|
|
|
2005-09-23 00:12:02 +00:00
|
|
|
while (!*ci->taginfo_ready && !ci->stop_codec)
|
2005-07-11 18:47:47 +00:00
|
|
|
ci->sleep(1);
|
2005-06-26 19:41:29 +00:00
|
|
|
|
2005-09-30 21:11:31 +00:00
|
|
|
ci->configure(CODEC_DSP_ENABLE, (bool *)true);
|
|
|
|
ci->configure(DSP_SET_FREQUENCY, (long *)(ci->id3->frequency));
|
|
|
|
codec_set_replaygain(ci->id3);
|
|
|
|
|
2005-06-13 06:15:05 +00:00
|
|
|
/* Create a decoder instance */
|
|
|
|
wpc = WavpackOpenFileInput (read_callback, error);
|
|
|
|
|
2006-01-18 20:22:03 +00:00
|
|
|
if (!wpc) {
|
|
|
|
retval = CODEC_ERROR;
|
|
|
|
goto exit;
|
|
|
|
}
|
2005-06-13 06:15:05 +00:00
|
|
|
|
|
|
|
bps = WavpackGetBytesPerSample (wpc);
|
|
|
|
nchans = WavpackGetReducedChannels (wpc);
|
2006-02-06 07:40:35 +00:00
|
|
|
ci->configure(DSP_SET_STEREO_MODE, nchans == 2 ? (int *)STEREO_INTERLEAVED : (int *)STEREO_MONO);
|
2005-06-27 00:12:40 +00:00
|
|
|
sr_100 = ci->id3->frequency / 100;
|
2005-06-13 06:15:05 +00:00
|
|
|
|
|
|
|
ci->set_elapsed (0);
|
|
|
|
|
|
|
|
/* The main decoder loop */
|
|
|
|
|
|
|
|
while (1) {
|
|
|
|
long nsamples;
|
|
|
|
|
|
|
|
if (ci->seek_time && ci->taginfo_ready && ci->id3->length) {
|
2005-11-06 19:18:04 +00:00
|
|
|
ci->seek_time--;
|
2005-06-27 00:12:40 +00:00
|
|
|
int curpos_ms = WavpackGetSampleIndex (wpc) / sr_100 * 10;
|
2005-06-13 06:15:05 +00:00
|
|
|
int n, d, skip;
|
|
|
|
|
|
|
|
if (ci->seek_time > curpos_ms) {
|
|
|
|
n = ci->seek_time - curpos_ms;
|
|
|
|
d = ci->id3->length - curpos_ms;
|
|
|
|
skip = (int)((long long)(ci->filesize - ci->curpos) * n / d);
|
|
|
|
ci->seek_buffer (ci->curpos + skip);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
n = curpos_ms - ci->seek_time;
|
|
|
|
d = curpos_ms;
|
|
|
|
skip = (int)((long long) ci->curpos * n / d);
|
|
|
|
ci->seek_buffer (ci->curpos - skip);
|
|
|
|
}
|
|
|
|
|
|
|
|
wpc = WavpackOpenFileInput (read_callback, error);
|
2005-11-02 00:09:42 +00:00
|
|
|
ci->seek_complete();
|
2005-06-13 06:15:05 +00:00
|
|
|
|
|
|
|
if (!wpc)
|
|
|
|
break;
|
|
|
|
|
2005-06-27 00:12:40 +00:00
|
|
|
ci->set_elapsed (WavpackGetSampleIndex (wpc) / sr_100 * 10);
|
2005-09-23 00:12:02 +00:00
|
|
|
ci->yield ();
|
2005-06-13 06:15:05 +00:00
|
|
|
}
|
|
|
|
|
2006-02-06 07:40:35 +00:00
|
|
|
nsamples = WavpackUnpackSamples (wpc, temp_buffer, BUFFER_SIZE / nchans);
|
2005-06-13 06:15:05 +00:00
|
|
|
|
|
|
|
if (!nsamples || ci->stop_codec || ci->reload_codec)
|
|
|
|
break;
|
|
|
|
|
2006-02-06 07:40:35 +00:00
|
|
|
ci->yield ();
|
2005-06-13 06:15:05 +00:00
|
|
|
|
|
|
|
if (ci->stop_codec || ci->reload_codec)
|
|
|
|
break;
|
|
|
|
|
2006-02-06 07:40:35 +00:00
|
|
|
while (!ci->pcmbuf_insert ((char *) temp_buffer, nsamples * nchans * 4))
|
2005-09-23 00:12:02 +00:00
|
|
|
ci->sleep (1);
|
2005-06-13 06:15:05 +00:00
|
|
|
|
2005-06-27 00:12:40 +00:00
|
|
|
ci->set_elapsed (WavpackGetSampleIndex (wpc) / sr_100 * 10);
|
2006-02-06 07:40:35 +00:00
|
|
|
ci->yield ();
|
2005-06-13 06:15:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (ci->request_next_track())
|
|
|
|
goto next_track;
|
|
|
|
|
2006-01-18 20:22:03 +00:00
|
|
|
retval = CODEC_OK;
|
|
|
|
exit:
|
|
|
|
return retval;
|
2005-06-13 06:15:05 +00:00
|
|
|
}
|