2005-11-11 19:45:36 +00:00
|
|
|
/***************************************************************************
|
|
|
|
* __________ __ ___.
|
|
|
|
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
|
|
|
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
|
|
|
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
|
|
|
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
|
|
|
* \/ \/ \/ \/ \/
|
|
|
|
* $Id:
|
|
|
|
*
|
|
|
|
* Copyright (C) 2005 Mark Arigo
|
|
|
|
*
|
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-11-11 19:45:36 +00:00
|
|
|
*
|
|
|
|
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
|
|
|
* KIND, either express or implied.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include "codeclib.h"
|
|
|
|
#include <codecs/libffmpegFLAC/shndec.h>
|
|
|
|
|
2006-01-18 00:05:14 +00:00
|
|
|
CODEC_HEADER
|
|
|
|
|
2006-11-26 18:31:41 +00:00
|
|
|
#ifndef IBSS_ATTR_SHORTEN_DECODED0
|
|
|
|
#define IBSS_ATTR_SHORTEN_DECODED0 IBSS_ATTR
|
2005-11-11 19:45:36 +00:00
|
|
|
#endif
|
|
|
|
|
2006-11-09 21:59:27 +00:00
|
|
|
int32_t decoded0[MAX_DECODE_SIZE] IBSS_ATTR_SHORTEN_DECODED0;
|
2006-02-07 22:16:35 +00:00
|
|
|
int32_t decoded1[MAX_DECODE_SIZE] IBSS_ATTR;
|
2005-11-11 19:45:36 +00:00
|
|
|
|
2006-02-07 22:16:35 +00:00
|
|
|
int32_t offset0[MAX_OFFSET_SIZE] IBSS_ATTR;
|
|
|
|
int32_t offset1[MAX_OFFSET_SIZE] IBSS_ATTR;
|
|
|
|
|
|
|
|
int8_t ibuf[MAX_BUFFER_SIZE] IBSS_ATTR;
|
2005-11-11 19:45:36 +00:00
|
|
|
|
|
|
|
/* this is the codec entry point */
|
2006-11-26 18:31:41 +00:00
|
|
|
enum codec_status codec_main(void)
|
2005-11-11 19:45:36 +00:00
|
|
|
{
|
|
|
|
ShortenContext sc;
|
|
|
|
uint32_t samplesdone;
|
|
|
|
uint32_t elapsedtime;
|
|
|
|
int8_t *buf;
|
2006-02-07 22:16:35 +00:00
|
|
|
int consumed, res, nsamples;
|
2006-03-24 14:02:27 +00:00
|
|
|
size_t bytesleft;
|
2005-11-11 19:45:36 +00:00
|
|
|
|
|
|
|
/* Generic codec initialisation */
|
2007-02-10 16:34:16 +00:00
|
|
|
ci->configure(DSP_SET_STEREO_MODE, STEREO_NONINTERLEAVED);
|
|
|
|
ci->configure(DSP_SET_SAMPLE_DEPTH, SHN_OUTPUT_DEPTH-1);
|
2005-11-11 19:45:36 +00:00
|
|
|
|
|
|
|
next_track:
|
|
|
|
/* Codec initialization */
|
2006-11-26 18:31:41 +00:00
|
|
|
if (codec_init()) {
|
2006-02-07 22:16:35 +00:00
|
|
|
LOGF("Shorten: codec_init error\n");
|
|
|
|
return CODEC_ERROR;
|
2005-11-11 19:45:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
while (!*ci->taginfo_ready)
|
|
|
|
ci->yield();
|
|
|
|
|
2007-02-26 17:15:04 +00:00
|
|
|
codec_set_replaygain(ci->id3);
|
|
|
|
|
2005-11-11 19:45:36 +00:00
|
|
|
/* Shorten decoder initialization */
|
|
|
|
ci->memset(&sc, 0, sizeof(ShortenContext));
|
|
|
|
|
2005-11-13 11:04:02 +00:00
|
|
|
/* Skip id3v2 tags */
|
2007-11-05 18:16:13 +00:00
|
|
|
ci->seek_buffer(ci->id3->first_frame_offset);
|
2005-11-13 11:04:02 +00:00
|
|
|
|
2005-11-11 19:45:36 +00:00
|
|
|
/* Read the shorten & wave headers */
|
2006-02-07 22:16:35 +00:00
|
|
|
buf = ci->request_buffer(&bytesleft, MAX_HEADER_SIZE);
|
2005-12-02 08:42:48 +00:00
|
|
|
res = shorten_init(&sc, (unsigned char *)buf, bytesleft);
|
2005-11-11 19:45:36 +00:00
|
|
|
if (res < 0) {
|
2006-02-07 22:16:35 +00:00
|
|
|
LOGF("Shorten: shorten_init error: %d\n", res);
|
|
|
|
return CODEC_ERROR;
|
2005-11-11 19:45:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ci->id3->frequency = sc.sample_rate;
|
2007-02-10 16:34:16 +00:00
|
|
|
ci->configure(DSP_SWITCH_FREQUENCY, sc.sample_rate);
|
2005-11-13 11:04:02 +00:00
|
|
|
|
|
|
|
if (sc.sample_rate) {
|
|
|
|
ci->id3->length = (sc.totalsamples / sc.sample_rate) * 1000;
|
|
|
|
} else {
|
|
|
|
ci->id3->length = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ci->id3->length) {
|
|
|
|
ci->id3->bitrate = (ci->id3->filesize * 8) / ci->id3->length;
|
|
|
|
}
|
2005-11-11 19:45:36 +00:00
|
|
|
|
|
|
|
consumed = sc.gb.index/8;
|
|
|
|
ci->advance_buffer(consumed);
|
|
|
|
sc.bitindex = sc.gb.index - 8*consumed;
|
|
|
|
|
|
|
|
seek_start:
|
|
|
|
/* The main decoding loop */
|
2006-02-07 22:16:35 +00:00
|
|
|
ci->memset(&decoded0, 0, sizeof(int32_t)*MAX_DECODE_SIZE);
|
|
|
|
ci->memset(&decoded1, 0, sizeof(int32_t)*MAX_DECODE_SIZE);
|
|
|
|
ci->memset(&offset0, 0, sizeof(int32_t)*MAX_OFFSET_SIZE);
|
|
|
|
ci->memset(&offset1, 0, sizeof(int32_t)*MAX_OFFSET_SIZE);
|
2005-11-11 19:45:36 +00:00
|
|
|
|
|
|
|
samplesdone = 0;
|
2006-02-07 22:16:35 +00:00
|
|
|
buf = ci->request_buffer(&bytesleft, MAX_BUFFER_SIZE);
|
2005-11-11 19:45:36 +00:00
|
|
|
while (bytesleft) {
|
|
|
|
ci->yield();
|
2006-04-15 02:03:11 +00:00
|
|
|
if (ci->stop_codec || ci->new_track) {
|
2005-11-11 19:45:36 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Seek to start of track */
|
|
|
|
if (ci->seek_time == 1) {
|
2005-11-13 11:04:02 +00:00
|
|
|
if (ci->seek_buffer(sc.header_bits/8 + ci->id3->first_frame_offset)) {
|
2005-11-11 19:45:36 +00:00
|
|
|
sc.bitindex = sc.header_bits - 8*(sc.header_bits/8);
|
|
|
|
ci->set_elapsed(0);
|
|
|
|
ci->seek_complete();
|
|
|
|
goto seek_start;
|
|
|
|
}
|
|
|
|
ci->seek_complete();
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Decode a frame */
|
2006-02-07 22:16:35 +00:00
|
|
|
ci->memcpy(ibuf, buf, bytesleft); /* copy buf to iram */
|
|
|
|
res = shorten_decode_frames(&sc, &nsamples, decoded0, decoded1,
|
|
|
|
offset0, offset1, (unsigned char *)ibuf,
|
|
|
|
bytesleft, ci->yield);
|
|
|
|
|
|
|
|
if (res == FN_ERROR) {
|
2010-05-15 01:57:32 +00:00
|
|
|
LOGF("Shorten: shorten_decode_frames error (%lu)\n",
|
|
|
|
(unsigned long)samplesdone);
|
2006-04-22 14:40:13 +00:00
|
|
|
break;
|
2005-11-11 19:45:36 +00:00
|
|
|
} else {
|
|
|
|
/* Insert decoded samples in pcmbuf */
|
2006-02-07 22:16:35 +00:00
|
|
|
if (nsamples) {
|
2005-11-11 19:45:36 +00:00
|
|
|
ci->yield();
|
2007-02-07 00:51:50 +00:00
|
|
|
ci->pcmbuf_insert(decoded0 + sc.nwrap, decoded1 + sc.nwrap,
|
|
|
|
nsamples);
|
2006-02-07 22:16:35 +00:00
|
|
|
|
|
|
|
/* Update the elapsed-time indicator */
|
|
|
|
samplesdone += nsamples;
|
|
|
|
elapsedtime = (samplesdone*10) / (sc.sample_rate/100);
|
|
|
|
ci->set_elapsed(elapsedtime);
|
2005-11-11 19:45:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* End of shorten stream...go to next track */
|
2006-02-07 22:16:35 +00:00
|
|
|
if (res == FN_QUIT)
|
|
|
|
break;
|
2005-11-11 19:45:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
consumed = sc.gb.index/8;
|
|
|
|
ci->advance_buffer(consumed);
|
2006-02-07 22:16:35 +00:00
|
|
|
buf = ci->request_buffer(&bytesleft, MAX_BUFFER_SIZE);
|
2005-11-11 19:45:36 +00:00
|
|
|
sc.bitindex = sc.gb.index - 8*consumed;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ci->request_next_track())
|
|
|
|
goto next_track;
|
|
|
|
|
2006-02-07 22:16:35 +00:00
|
|
|
return CODEC_OK;
|
2005-11-11 19:45:36 +00:00
|
|
|
}
|