2005-06-13 06:15:05 +00:00
|
|
|
/***************************************************************************
|
|
|
|
* __________ __ ___.
|
|
|
|
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
|
|
|
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
|
|
|
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
|
|
|
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
|
|
|
* \/ \/ \/ \/ \/
|
|
|
|
* $Id$
|
|
|
|
*
|
|
|
|
* Copyright (C) 2005 David Bryant
|
|
|
|
*
|
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-13 06:15:05 +00:00
|
|
|
*
|
|
|
|
* 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
|
|
|
#define BUFFER_SIZE 4096
|
|
|
|
|
2006-03-26 22:54:15 +00:00
|
|
|
static int32_t temp_buffer [BUFFER_SIZE] IBSS_ATTR;
|
2005-06-13 06:15:05 +00:00
|
|
|
|
2006-03-26 22:54:15 +00:00
|
|
|
static int32_t read_callback (void *buffer, int32_t bytes)
|
2005-06-13 06:15:05 +00:00
|
|
|
{
|
2006-03-26 22:54:15 +00:00
|
|
|
int32_t retval = ci->read_filebuf (buffer, bytes);
|
2011-04-27 03:08:23 +00:00
|
|
|
ci->set_offset(ci->curpos);
|
2005-06-30 06:09:59 +00:00
|
|
|
return retval;
|
2005-06-13 06:15:05 +00:00
|
|
|
}
|
|
|
|
|
2005-06-22 19:41:30 +00:00
|
|
|
/* this is the codec entry point */
|
2011-04-27 03:08:23 +00:00
|
|
|
enum codec_status codec_main(enum codec_entry_call_reason reason)
|
|
|
|
{
|
|
|
|
if (reason == CODEC_LOAD) {
|
|
|
|
/* Generic codec initialisation */
|
|
|
|
ci->configure(DSP_SET_SAMPLE_DEPTH, 28);
|
|
|
|
}
|
|
|
|
|
|
|
|
return CODEC_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* this is called for each file to process */
|
|
|
|
enum codec_status codec_run(void)
|
2005-06-13 06:15:05 +00:00
|
|
|
{
|
|
|
|
WavpackContext *wpc;
|
|
|
|
char error [80];
|
2011-05-01 11:42:41 +00:00
|
|
|
/* rockbox: comment 'set but unused' variables
|
|
|
|
int bps;
|
|
|
|
*/
|
|
|
|
int nchans, sr_100;
|
2013-07-14 11:59:39 +00:00
|
|
|
unsigned long offset;
|
2011-04-27 03:08:23 +00:00
|
|
|
intptr_t param;
|
2005-06-13 06:15:05 +00:00
|
|
|
|
2011-04-27 03:08:23 +00:00
|
|
|
if (codec_init())
|
|
|
|
return CODEC_ERROR;
|
2005-06-13 06:15:05 +00:00
|
|
|
|
2013-07-14 11:59:39 +00:00
|
|
|
param = ci->id3->elapsed;
|
|
|
|
offset = ci->id3->offset;
|
|
|
|
|
|
|
|
ci->seek_buffer (offset);
|
2005-06-13 06:15:05 +00:00
|
|
|
|
|
|
|
/* Create a decoder instance */
|
|
|
|
wpc = WavpackOpenFileInput (read_callback, error);
|
|
|
|
|
2011-04-27 03:08:23 +00:00
|
|
|
if (!wpc)
|
|
|
|
return CODEC_ERROR;
|
2005-06-13 06:15:05 +00:00
|
|
|
|
2013-05-05 04:48:40 +00:00
|
|
|
ci->configure(DSP_SET_FREQUENCY, WavpackGetSampleRate (wpc));
|
2007-08-12 06:36:06 +00:00
|
|
|
codec_set_replaygain(ci->id3);
|
2011-05-01 11:42:41 +00:00
|
|
|
/* bps = WavpackGetBytesPerSample (wpc); */
|
2005-06-13 06:15:05 +00:00
|
|
|
nchans = WavpackGetReducedChannels (wpc);
|
2007-02-10 16:34:16 +00:00
|
|
|
ci->configure(DSP_SET_STEREO_MODE, nchans == 2 ? STEREO_INTERLEAVED : STEREO_MONO);
|
2005-06-27 00:12:40 +00:00
|
|
|
sr_100 = ci->id3->frequency / 100;
|
2005-06-13 06:15:05 +00:00
|
|
|
|
2013-07-14 11:59:39 +00:00
|
|
|
if (!offset && param) {
|
|
|
|
goto resume_start; /* resume by elapsed */
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
ci->set_elapsed (WavpackGetSampleIndex (wpc) / sr_100 * 10);
|
|
|
|
}
|
2005-06-13 06:15:05 +00:00
|
|
|
|
|
|
|
/* The main decoder loop */
|
|
|
|
|
|
|
|
while (1) {
|
2011-04-27 03:08:23 +00:00
|
|
|
int32_t nsamples;
|
2017-12-07 18:21:57 +00:00
|
|
|
long action = ci->get_command(¶m);
|
2011-04-27 03:08:23 +00:00
|
|
|
|
|
|
|
if (action == CODEC_ACTION_HALT)
|
|
|
|
break;
|
2005-06-13 06:15:05 +00:00
|
|
|
|
2011-04-27 03:08:23 +00:00
|
|
|
if (action == CODEC_ACTION_SEEK_TIME) {
|
2013-07-14 11:59:39 +00:00
|
|
|
resume_start:;
|
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;
|
|
|
|
|
2011-04-27 03:08:23 +00:00
|
|
|
if (param > curpos_ms) {
|
|
|
|
n = param - curpos_ms;
|
2005-06-13 06:15:05 +00:00
|
|
|
d = ci->id3->length - curpos_ms;
|
2006-03-26 22:54:15 +00:00
|
|
|
skip = (int)((int64_t)(ci->filesize - ci->curpos) * n / d);
|
2005-06-13 06:15:05 +00:00
|
|
|
ci->seek_buffer (ci->curpos + skip);
|
|
|
|
}
|
2011-04-27 03:08:23 +00:00
|
|
|
else if (curpos_ms != 0) {
|
|
|
|
n = curpos_ms - param;
|
2005-06-13 06:15:05 +00:00
|
|
|
d = curpos_ms;
|
2006-03-26 22:54:15 +00:00
|
|
|
skip = (int)((int64_t) ci->curpos * n / d);
|
2005-06-13 06:15:05 +00:00
|
|
|
ci->seek_buffer (ci->curpos - skip);
|
|
|
|
}
|
|
|
|
|
|
|
|
wpc = WavpackOpenFileInput (read_callback, error);
|
|
|
|
if (!wpc)
|
2011-04-27 03:08:23 +00:00
|
|
|
{
|
|
|
|
ci->seek_complete();
|
2005-06-13 06:15:05 +00:00
|
|
|
break;
|
2011-04-27 03:08:23 +00:00
|
|
|
}
|
2005-06-13 06:15:05 +00:00
|
|
|
|
2005-06-27 00:12:40 +00:00
|
|
|
ci->set_elapsed (WavpackGetSampleIndex (wpc) / sr_100 * 10);
|
2011-04-27 03:08:23 +00:00
|
|
|
ci->seek_complete();
|
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
|
|
|
|
2011-04-27 03:08:23 +00:00
|
|
|
if (!nsamples)
|
2005-06-13 06:15:05 +00:00
|
|
|
break;
|
|
|
|
|
2007-02-07 00:51:50 +00:00
|
|
|
ci->pcmbuf_insert (temp_buffer, NULL, nsamples);
|
2005-06-27 00:12:40 +00:00
|
|
|
ci->set_elapsed (WavpackGetSampleIndex (wpc) / sr_100 * 10);
|
2005-06-13 06:15:05 +00:00
|
|
|
}
|
|
|
|
|
2011-04-27 03:08:23 +00:00
|
|
|
return CODEC_OK;
|
2005-06-13 06:15:05 +00:00
|
|
|
}
|