2006-02-01 16:42:02 +00:00
|
|
|
/***************************************************************************
|
|
|
|
* __________ __ ___.
|
|
|
|
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
|
|
|
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
|
|
|
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
|
|
|
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
|
|
|
* \/ \/ \/ \/ \/
|
|
|
|
* $Id$
|
|
|
|
*
|
|
|
|
* Copyright (c) 2005 Jvo Studer
|
2010-01-27 17:25:10 +00:00
|
|
|
* Copyright (c) 2009 Yoshihisa Uchida
|
2006-02-01 16:42:02 +00:00
|
|
|
*
|
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.
|
2006-02-01 16:42:02 +00:00
|
|
|
*
|
|
|
|
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
|
|
|
* KIND, either express or implied.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include "codeclib.h"
|
2010-01-27 17:25:10 +00:00
|
|
|
#include "codecs/libpcm/support_formats.h"
|
2006-02-01 16:42:02 +00:00
|
|
|
|
|
|
|
CODEC_HEADER
|
|
|
|
|
2010-01-27 17:25:10 +00:00
|
|
|
#define FOURCC(c1, c2, c3, c4) \
|
|
|
|
((((uint32_t)c1)<<24)|(((uint32_t)c2)<<16)|(((uint32_t)c3)<<8)|((uint32_t)c4))
|
2006-03-20 20:19:40 +00:00
|
|
|
|
2010-01-27 17:25:10 +00:00
|
|
|
/* This codec supports the following AIFC compressionType formats */
|
|
|
|
enum {
|
|
|
|
AIFC_FORMAT_PCM = FOURCC('N', 'O', 'N', 'E'), /* AIFC PCM Format (big endian) */
|
|
|
|
AIFC_FORMAT_ALAW = FOURCC('a', 'l', 'a', 'w'), /* AIFC ALaw compressed */
|
|
|
|
AIFC_FORMAT_MULAW = FOURCC('u', 'l', 'a', 'w'), /* AIFC uLaw compressed */
|
2010-01-27 18:10:08 +00:00
|
|
|
AIFC_FORMAT_IEEE_FLOAT32 = FOURCC('f', 'l', '3', '2'), /* AIFC IEEE float 32 bit */
|
|
|
|
AIFC_FORMAT_IEEE_FLOAT64 = FOURCC('f', 'l', '6', '4'), /* AIFC IEEE float 64 bit */
|
2010-02-20 02:04:56 +00:00
|
|
|
AIFC_FORMAT_QT_IMA_ADPCM = FOURCC('i', 'm', 'a', '4'), /* AIFC QuickTime IMA ADPCM */
|
2010-01-27 17:25:10 +00:00
|
|
|
};
|
2006-02-01 16:42:02 +00:00
|
|
|
|
2010-01-27 17:25:10 +00:00
|
|
|
static const struct pcm_entry pcm_codecs[] = {
|
|
|
|
{ AIFC_FORMAT_PCM, get_linear_pcm_codec },
|
|
|
|
{ AIFC_FORMAT_ALAW, get_itut_g711_alaw_codec },
|
|
|
|
{ AIFC_FORMAT_MULAW, get_itut_g711_mulaw_codec },
|
2010-01-27 18:10:08 +00:00
|
|
|
{ AIFC_FORMAT_IEEE_FLOAT32, get_ieee_float_codec },
|
|
|
|
{ AIFC_FORMAT_IEEE_FLOAT64, get_ieee_float_codec },
|
2010-02-20 02:04:56 +00:00
|
|
|
{ AIFC_FORMAT_QT_IMA_ADPCM, get_qt_ima_adpcm_codec },
|
2006-02-01 16:42:02 +00:00
|
|
|
};
|
|
|
|
|
2010-02-24 11:30:16 +00:00
|
|
|
#define PCM_SAMPLE_SIZE (1024*2)
|
|
|
|
|
|
|
|
static int32_t samples[PCM_SAMPLE_SIZE] IBSS_ATTR;
|
2010-01-27 17:25:10 +00:00
|
|
|
|
|
|
|
static const struct pcm_codec *get_codec(uint32_t formattag)
|
|
|
|
{
|
2010-07-26 08:59:21 +00:00
|
|
|
unsigned i;
|
|
|
|
for (i = 0; i < sizeof(pcm_codecs)/sizeof(pcm_codecs[0]); i++)
|
2010-01-27 17:25:10 +00:00
|
|
|
if (pcm_codecs[i].format_tag == formattag)
|
2010-07-26 08:59:21 +00:00
|
|
|
return pcm_codecs[i].get_codec();
|
|
|
|
|
|
|
|
return NULL;
|
2010-01-27 17:25:10 +00:00
|
|
|
}
|
2006-02-01 16:42:02 +00:00
|
|
|
|
2011-04-27 03:08:23 +00:00
|
|
|
/* this is the codec entry point */
|
|
|
|
enum codec_status codec_main(enum codec_entry_call_reason reason)
|
|
|
|
{
|
|
|
|
if (reason == CODEC_LOAD) {
|
|
|
|
/* Generic codec initialisation */
|
|
|
|
ci->configure(DSP_SET_SAMPLE_DEPTH, PCM_OUTPUT_DEPTH-1);
|
|
|
|
}
|
|
|
|
|
|
|
|
return CODEC_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* this is called for each file to process */
|
|
|
|
enum codec_status codec_run(void)
|
2006-02-01 16:42:02 +00:00
|
|
|
{
|
2010-01-27 17:25:10 +00:00
|
|
|
struct pcm_format format;
|
2010-02-20 02:04:56 +00:00
|
|
|
uint32_t bytesdone, decodedsamples;
|
2011-05-01 11:42:41 +00:00
|
|
|
/* rockbox: comment 'set but unused' variables
|
2006-03-20 20:19:40 +00:00
|
|
|
uint32_t num_sample_frames = 0;
|
2011-05-01 11:42:41 +00:00
|
|
|
*/
|
2007-02-07 00:51:50 +00:00
|
|
|
size_t n;
|
|
|
|
int bufcount;
|
2006-03-20 20:19:40 +00:00
|
|
|
int endofstream;
|
|
|
|
unsigned char *buf;
|
|
|
|
uint8_t *aifbuf;
|
|
|
|
uint32_t offset2snd = 0;
|
|
|
|
off_t firstblockposn; /* position of the first block in file */
|
2010-01-27 17:25:10 +00:00
|
|
|
bool is_aifc = false;
|
|
|
|
const struct pcm_codec *codec;
|
2010-03-07 07:15:21 +00:00
|
|
|
uint32_t size;
|
2011-04-27 03:08:23 +00:00
|
|
|
intptr_t param;
|
2011-02-20 15:27:10 +00:00
|
|
|
|
2006-11-26 18:31:41 +00:00
|
|
|
if (codec_init()) {
|
2011-04-27 03:08:23 +00:00
|
|
|
return CODEC_ERROR;
|
2006-03-20 20:19:40 +00:00
|
|
|
}
|
2006-02-01 16:42:02 +00:00
|
|
|
|
2007-02-26 17:15:04 +00:00
|
|
|
codec_set_replaygain(ci->id3);
|
2006-02-01 16:42:02 +00:00
|
|
|
|
2010-03-22 10:02:05 +00:00
|
|
|
/* Need to save offset for later use (cleared indirectly by advance_buffer) */
|
2013-07-14 11:59:39 +00:00
|
|
|
param = ci->id3->elapsed;
|
2010-03-22 10:02:05 +00:00
|
|
|
bytesdone = ci->id3->offset;
|
|
|
|
|
2006-03-20 20:19:40 +00:00
|
|
|
/* assume the AIFF header is less than 1024 bytes */
|
2011-04-27 03:08:23 +00:00
|
|
|
ci->seek_buffer(0);
|
2006-03-24 14:02:27 +00:00
|
|
|
buf = ci->request_buffer(&n, 1024);
|
2006-11-25 21:27:46 +00:00
|
|
|
if (n < 54) {
|
2011-04-27 03:08:23 +00:00
|
|
|
return CODEC_ERROR;
|
2006-03-20 20:19:40 +00:00
|
|
|
}
|
2010-01-27 17:25:10 +00:00
|
|
|
|
|
|
|
if (memcmp(buf, "FORM", 4) != 0)
|
|
|
|
{
|
2010-07-26 08:59:21 +00:00
|
|
|
DEBUGF("CODEC_ERROR: does not aiff format %4.4s\n", (char*)&buf[0]);
|
2011-04-27 03:08:23 +00:00
|
|
|
return CODEC_ERROR;
|
2010-01-27 17:25:10 +00:00
|
|
|
}
|
|
|
|
if (memcmp(&buf[8], "AIFF", 4) == 0)
|
|
|
|
is_aifc = false;
|
|
|
|
else if (memcmp(&buf[8], "AIFC", 4) == 0)
|
|
|
|
is_aifc = true;
|
|
|
|
else
|
|
|
|
{
|
2010-07-26 08:59:21 +00:00
|
|
|
DEBUGF("CODEC_ERROR: does not aiff format %4.4s\n", (char*)&buf[8]);
|
2011-04-27 03:08:23 +00:00
|
|
|
return CODEC_ERROR;
|
2006-02-01 16:42:02 +00:00
|
|
|
}
|
|
|
|
|
2006-03-20 20:19:40 +00:00
|
|
|
buf += 12;
|
|
|
|
n -= 12;
|
2010-01-27 17:25:10 +00:00
|
|
|
|
|
|
|
ci->memset(&format, 0, sizeof(struct pcm_format));
|
|
|
|
format.is_signed = true;
|
|
|
|
format.is_little_endian = false;
|
|
|
|
|
2010-02-20 02:04:56 +00:00
|
|
|
decodedsamples = 0;
|
2010-01-27 17:25:10 +00:00
|
|
|
codec = 0;
|
2006-03-20 20:19:40 +00:00
|
|
|
|
|
|
|
/* read until 'SSND' chunk, which typically is last */
|
2010-01-27 17:25:10 +00:00
|
|
|
while (format.numbytes == 0 && n >= 8)
|
|
|
|
{
|
2006-03-20 20:19:40 +00:00
|
|
|
/* chunkSize */
|
2010-03-07 07:15:21 +00:00
|
|
|
size = ((buf[4]<<24)|(buf[5]<<16)|(buf[6]<<8)|buf[7]);
|
2006-03-20 20:19:40 +00:00
|
|
|
if (memcmp(buf, "COMM", 4) == 0) {
|
2010-03-07 07:15:21 +00:00
|
|
|
if ((!is_aifc && size < 18) || (is_aifc && size < 22))
|
2010-01-27 17:25:10 +00:00
|
|
|
{
|
|
|
|
DEBUGF("CODEC_ERROR: 'COMM' chunk size=%lu < %d\n",
|
2010-03-07 07:15:21 +00:00
|
|
|
(unsigned long)size, (is_aifc)?22:18);
|
2011-04-27 03:08:23 +00:00
|
|
|
return CODEC_ERROR;
|
2006-03-20 20:19:40 +00:00
|
|
|
}
|
|
|
|
/* num_channels */
|
2010-01-27 17:25:10 +00:00
|
|
|
format.channels = ((buf[8]<<8)|buf[9]);
|
2006-03-20 20:19:40 +00:00
|
|
|
/* num_sample_frames */
|
2011-05-01 11:42:41 +00:00
|
|
|
/*
|
2006-03-20 20:19:40 +00:00
|
|
|
num_sample_frames = ((buf[10]<<24)|(buf[11]<<16)|(buf[12]<<8)
|
|
|
|
|buf[13]);
|
2011-05-01 11:42:41 +00:00
|
|
|
*/
|
|
|
|
|
2006-03-20 20:19:40 +00:00
|
|
|
/* sample_size */
|
2010-01-27 17:25:10 +00:00
|
|
|
format.bitspersample = ((buf[14]<<8)|buf[15]);
|
2006-03-20 20:19:40 +00:00
|
|
|
/* sample_rate (don't use last 4 bytes, only integer fs) */
|
|
|
|
if (buf[16] != 0x40) {
|
2007-03-17 09:54:28 +00:00
|
|
|
DEBUGF("CODEC_ERROR: weird sampling rate (no @)\n");
|
2011-04-27 03:08:23 +00:00
|
|
|
return CODEC_ERROR;
|
2006-03-20 20:19:40 +00:00
|
|
|
}
|
2010-01-27 17:25:10 +00:00
|
|
|
format.samplespersec = ((buf[18]<<24)|(buf[19]<<16)|(buf[20]<<8)|buf[21])+1;
|
|
|
|
format.samplespersec >>= (16 + 14 - buf[17]);
|
|
|
|
/* compressionType (AIFC only) */
|
|
|
|
if (is_aifc)
|
|
|
|
{
|
|
|
|
format.formattag = (buf[26]<<24)|(buf[27]<<16)|(buf[28]<<8)|buf[29];
|
|
|
|
|
|
|
|
/*
|
|
|
|
* aiff's sample_size is uncompressed sound data size.
|
|
|
|
* But format.bitspersample is compressed sound data size.
|
|
|
|
*/
|
2010-02-20 02:04:56 +00:00
|
|
|
if (format.formattag == AIFC_FORMAT_ALAW ||
|
|
|
|
format.formattag == AIFC_FORMAT_MULAW)
|
2010-01-27 17:25:10 +00:00
|
|
|
format.bitspersample = 8;
|
2010-02-20 02:04:56 +00:00
|
|
|
else if (format.formattag == AIFC_FORMAT_QT_IMA_ADPCM)
|
|
|
|
format.bitspersample = 4;
|
2010-01-27 17:25:10 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
format.formattag = AIFC_FORMAT_PCM;
|
2006-03-20 20:19:40 +00:00
|
|
|
/* calc average bytes per second */
|
2010-01-27 17:25:10 +00:00
|
|
|
format.avgbytespersec = format.samplespersec*format.channels*format.bitspersample/8;
|
2006-03-20 20:19:40 +00:00
|
|
|
} else if (memcmp(buf, "SSND", 4)==0) {
|
2010-01-27 17:25:10 +00:00
|
|
|
if (format.bitspersample == 0) {
|
2006-03-20 20:19:40 +00:00
|
|
|
DEBUGF("CODEC_ERROR: unsupported chunk order\n");
|
2011-04-27 03:08:23 +00:00
|
|
|
return CODEC_ERROR;
|
2006-03-20 20:19:40 +00:00
|
|
|
}
|
|
|
|
/* offset2snd */
|
2006-11-25 21:27:46 +00:00
|
|
|
offset2snd = (buf[8]<<24)|(buf[9]<<16)|(buf[10]<<8)|buf[11];
|
2006-03-20 20:19:40 +00:00
|
|
|
/* block_size */
|
2010-02-20 02:04:56 +00:00
|
|
|
format.blockalign = ((buf[12]<<24)|(buf[13]<<16)|(buf[14]<<8)|buf[15]) >> 3;
|
2010-01-27 17:25:10 +00:00
|
|
|
if (format.blockalign == 0)
|
2010-02-20 02:04:56 +00:00
|
|
|
format.blockalign = format.channels * format.bitspersample >> 3;
|
2010-03-07 07:15:21 +00:00
|
|
|
format.numbytes = size - 8 - offset2snd;
|
|
|
|
size = 8 + offset2snd; /* advance to the beginning of data */
|
2010-01-27 17:25:10 +00:00
|
|
|
} else if (is_aifc && (memcmp(buf, "FVER", 4)==0)) {
|
|
|
|
/* Format Version Chunk (AIFC only chunk) */
|
|
|
|
/* skip this chunk */
|
2006-03-20 20:19:40 +00:00
|
|
|
} else {
|
|
|
|
DEBUGF("unsupported AIFF chunk: '%c%c%c%c', size=%lu\n",
|
2010-03-07 07:15:21 +00:00
|
|
|
buf[0], buf[1], buf[2], buf[3], (unsigned long)size);
|
2006-03-20 20:19:40 +00:00
|
|
|
}
|
2006-02-01 16:42:02 +00:00
|
|
|
|
2010-03-07 07:15:21 +00:00
|
|
|
size += 8 + (size & 0x01); /* odd chunk sizes must be padded */
|
|
|
|
|
|
|
|
buf += size;
|
|
|
|
if (n < size) {
|
2006-03-20 20:19:40 +00:00
|
|
|
DEBUGF("CODEC_ERROR: AIFF header size > 1024\n");
|
2011-04-27 03:08:23 +00:00
|
|
|
return CODEC_ERROR;
|
2006-02-01 16:42:02 +00:00
|
|
|
}
|
2010-03-07 07:15:21 +00:00
|
|
|
n -= size;
|
2006-03-20 20:19:40 +00:00
|
|
|
} /* while 'SSND' */
|
|
|
|
|
2010-01-27 17:25:10 +00:00
|
|
|
if (format.channels == 0) {
|
2006-03-20 20:19:40 +00:00
|
|
|
DEBUGF("CODEC_ERROR: 'COMM' chunk not found or 0-channels file\n");
|
2011-04-27 03:08:23 +00:00
|
|
|
return CODEC_ERROR;
|
2006-02-01 16:42:02 +00:00
|
|
|
}
|
2010-01-27 17:25:10 +00:00
|
|
|
if (format.numbytes == 0) {
|
2006-03-20 20:19:40 +00:00
|
|
|
DEBUGF("CODEC_ERROR: 'SSND' chunk not found or has zero length\n");
|
2011-04-27 03:08:23 +00:00
|
|
|
return CODEC_ERROR;
|
2006-03-20 20:19:40 +00:00
|
|
|
}
|
2010-01-27 17:25:10 +00:00
|
|
|
|
|
|
|
codec = get_codec(format.formattag);
|
|
|
|
if (codec == 0)
|
|
|
|
{
|
2010-01-27 18:05:28 +00:00
|
|
|
DEBUGF("CODEC_ERROR: AIFC does not support compressionType: 0x%x\n",
|
|
|
|
(unsigned int)format.formattag);
|
2011-04-27 03:08:23 +00:00
|
|
|
return CODEC_ERROR;
|
2010-01-27 17:25:10 +00:00
|
|
|
}
|
|
|
|
|
2010-02-20 02:04:56 +00:00
|
|
|
if (!codec->set_format(&format))
|
2010-01-27 17:25:10 +00:00
|
|
|
{
|
2011-04-27 03:08:23 +00:00
|
|
|
return CODEC_ERROR;
|
2006-03-20 20:19:40 +00:00
|
|
|
}
|
|
|
|
|
2013-05-05 04:48:40 +00:00
|
|
|
ci->configure(DSP_SET_FREQUENCY, ci->id3->frequency);
|
2006-02-01 16:42:02 +00:00
|
|
|
|
2010-01-27 17:25:10 +00:00
|
|
|
if (format.channels == 2) {
|
2007-02-10 16:34:16 +00:00
|
|
|
ci->configure(DSP_SET_STEREO_MODE, STEREO_INTERLEAVED);
|
2010-01-27 17:25:10 +00:00
|
|
|
} else if (format.channels == 1) {
|
2007-02-10 16:34:16 +00:00
|
|
|
ci->configure(DSP_SET_STEREO_MODE, STEREO_MONO);
|
2006-03-20 20:19:40 +00:00
|
|
|
} else {
|
|
|
|
DEBUGF("CODEC_ERROR: more than 2 channels unsupported\n");
|
2011-04-27 03:08:23 +00:00
|
|
|
return CODEC_ERROR;
|
2006-03-20 20:19:40 +00:00
|
|
|
}
|
2006-02-01 16:42:02 +00:00
|
|
|
|
2010-02-20 02:04:56 +00:00
|
|
|
if (format.samplesperblock == 0)
|
|
|
|
{
|
|
|
|
DEBUGF("CODEC_ERROR: samplesperblock is 0\n");
|
2011-04-27 03:08:23 +00:00
|
|
|
return CODEC_ERROR;
|
2010-02-20 02:04:56 +00:00
|
|
|
}
|
|
|
|
if (format.blockalign == 0)
|
|
|
|
{
|
|
|
|
DEBUGF("CODEC_ERROR: blockalign is 0\n");
|
2011-04-27 03:08:23 +00:00
|
|
|
return CODEC_ERROR;
|
2010-02-20 02:04:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* check chunksize */
|
|
|
|
if ((format.chunksize / format.blockalign) * format.samplesperblock * format.channels
|
2010-02-24 11:30:16 +00:00
|
|
|
> PCM_SAMPLE_SIZE)
|
|
|
|
format.chunksize = (PCM_SAMPLE_SIZE / format.blockalign) * format.blockalign;
|
2010-02-20 02:04:56 +00:00
|
|
|
if (format.chunksize == 0)
|
|
|
|
{
|
|
|
|
DEBUGF("CODEC_ERROR: chunksize is 0\n");
|
2011-04-27 03:08:23 +00:00
|
|
|
return CODEC_ERROR;
|
2010-02-20 02:04:56 +00:00
|
|
|
}
|
|
|
|
|
2006-03-20 20:19:40 +00:00
|
|
|
firstblockposn = 1024 - n;
|
|
|
|
ci->advance_buffer(firstblockposn);
|
|
|
|
|
2010-03-22 10:02:05 +00:00
|
|
|
/* make sure we're at the correct offset */
|
2013-07-14 11:59:39 +00:00
|
|
|
if (bytesdone > (uint32_t) firstblockposn || param) {
|
|
|
|
uint32_t seek_val;
|
|
|
|
int seek_mode;
|
|
|
|
|
|
|
|
if (bytesdone) {
|
|
|
|
seek_val = bytesdone - MIN((uint32_t) firstblockposn, bytesdone);
|
|
|
|
seek_mode = PCM_SEEK_POS;
|
|
|
|
} else {
|
|
|
|
seek_val = param;
|
|
|
|
seek_mode = PCM_SEEK_TIME;
|
|
|
|
}
|
|
|
|
|
2010-03-22 10:02:05 +00:00
|
|
|
/* Round down to previous block */
|
2013-07-14 11:59:39 +00:00
|
|
|
struct pcm_pos *newpos = codec->get_seek_pos(seek_val, seek_mode, NULL);
|
2010-03-22 10:02:05 +00:00
|
|
|
|
|
|
|
if (newpos->pos > format.numbytes)
|
2011-04-27 03:08:23 +00:00
|
|
|
return CODEC_OK;
|
|
|
|
|
2010-03-22 10:02:05 +00:00
|
|
|
if (ci->seek_buffer(firstblockposn + newpos->pos))
|
|
|
|
{
|
|
|
|
bytesdone = newpos->pos;
|
|
|
|
decodedsamples = newpos->samples;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/* already where we need to be */
|
|
|
|
bytesdone = 0;
|
|
|
|
}
|
|
|
|
|
2011-08-28 07:45:35 +00:00
|
|
|
ci->set_elapsed(decodedsamples*1000LL/ci->id3->frequency);
|
|
|
|
|
2006-03-20 20:19:40 +00:00
|
|
|
/* The main decoder loop */
|
|
|
|
endofstream = 0;
|
2006-02-01 16:42:02 +00:00
|
|
|
|
2006-03-20 20:19:40 +00:00
|
|
|
while (!endofstream) {
|
2011-04-27 03:08:23 +00:00
|
|
|
enum codec_command_action action = ci->get_command(¶m);
|
|
|
|
|
|
|
|
if (action == CODEC_ACTION_HALT)
|
2006-03-20 20:19:40 +00:00
|
|
|
break;
|
2006-02-01 16:42:02 +00:00
|
|
|
|
2011-04-27 03:08:23 +00:00
|
|
|
if (action == CODEC_ACTION_SEEK_TIME) {
|
2010-03-22 10:02:05 +00:00
|
|
|
/* 3rd args(read_buffer) is unnecessary in the format which AIFF supports. */
|
2011-04-27 03:08:23 +00:00
|
|
|
struct pcm_pos *newpos = codec->get_seek_pos(param, PCM_SEEK_TIME, NULL);
|
2010-02-20 02:04:56 +00:00
|
|
|
|
|
|
|
if (newpos->pos > format.numbytes)
|
2011-04-27 03:08:23 +00:00
|
|
|
{
|
|
|
|
ci->set_elapsed(ci->id3->length);
|
|
|
|
ci->seek_complete();
|
2006-03-20 20:19:40 +00:00
|
|
|
break;
|
2011-04-27 03:08:23 +00:00
|
|
|
}
|
|
|
|
|
2010-02-20 02:04:56 +00:00
|
|
|
if (ci->seek_buffer(firstblockposn + newpos->pos))
|
2010-03-06 08:13:56 +00:00
|
|
|
{
|
|
|
|
bytesdone = newpos->pos;
|
|
|
|
decodedsamples = newpos->samples;
|
|
|
|
}
|
2011-04-27 03:08:23 +00:00
|
|
|
|
|
|
|
ci->set_elapsed(decodedsamples*1000LL/ci->id3->frequency);
|
2006-03-20 20:19:40 +00:00
|
|
|
ci->seek_complete();
|
2006-02-01 16:42:02 +00:00
|
|
|
}
|
2010-01-27 17:25:10 +00:00
|
|
|
aifbuf = (uint8_t *)ci->request_buffer(&n, format.chunksize);
|
2006-03-20 20:19:40 +00:00
|
|
|
|
|
|
|
if (n == 0)
|
|
|
|
break; /* End of stream */
|
|
|
|
|
2010-01-27 17:25:10 +00:00
|
|
|
if (bytesdone + n > format.numbytes) {
|
|
|
|
n = format.numbytes - bytesdone;
|
2006-03-20 20:19:40 +00:00
|
|
|
endofstream = 1;
|
2006-02-01 16:42:02 +00:00
|
|
|
}
|
2006-03-20 20:19:40 +00:00
|
|
|
|
2011-04-27 03:08:23 +00:00
|
|
|
if (codec->decode(aifbuf, n, samples, &bufcount) == CODEC_ERROR)
|
2010-01-27 17:25:10 +00:00
|
|
|
{
|
|
|
|
DEBUGF("codec error\n");
|
2011-04-27 03:08:23 +00:00
|
|
|
return CODEC_ERROR;
|
2006-02-01 16:42:02 +00:00
|
|
|
}
|
|
|
|
|
2007-02-07 00:51:50 +00:00
|
|
|
ci->pcmbuf_insert(samples, NULL, bufcount);
|
2006-02-01 16:42:02 +00:00
|
|
|
|
2006-03-20 20:19:40 +00:00
|
|
|
ci->advance_buffer(n);
|
|
|
|
bytesdone += n;
|
2010-02-20 02:04:56 +00:00
|
|
|
decodedsamples += bufcount;
|
2010-01-27 17:25:10 +00:00
|
|
|
if (bytesdone >= format.numbytes)
|
2006-03-20 20:19:40 +00:00
|
|
|
endofstream = 1;
|
2006-02-01 16:42:02 +00:00
|
|
|
|
2010-02-20 02:04:56 +00:00
|
|
|
ci->set_elapsed(decodedsamples*1000LL/ci->id3->frequency);
|
2006-03-20 20:19:40 +00:00
|
|
|
}
|
2006-02-01 16:42:02 +00:00
|
|
|
|
2011-04-27 03:08:23 +00:00
|
|
|
return CODEC_OK;
|
2006-02-01 16:42:02 +00:00
|
|
|
}
|