1
0
Fork 0
forked from len0rd/rockbox

Patch #1352575 - Shorten codec from the ffmpeg project. Rockbox implementation by Mark Arigo.

git-svn-id: svn://svn.rockbox.org/rockbox/trunk@7814 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
Dave Chapman 2005-11-11 19:45:36 +00:00
parent 5592e37c63
commit 2bf9be1c02
14 changed files with 656 additions and 15 deletions

View file

@ -62,6 +62,7 @@ $(OBJDIR)/wav.elf: $(OBJDIR)/wav.o $(CODECDEPS)
$(OBJDIR)/wavpack.elf: $(OBJDIR)/wavpack.o $(CODECDEPS) $(BUILDDIR)/libwavpack.a $(OBJDIR)/wavpack.elf: $(OBJDIR)/wavpack.o $(CODECDEPS) $(BUILDDIR)/libwavpack.a
$(OBJDIR)/alac.elf: $(OBJDIR)/alac.o $(CODECDEPS) $(BUILDDIR)/libalac.a $(BUILDDIR)/libm4a.a $(OBJDIR)/alac.elf: $(OBJDIR)/alac.o $(CODECDEPS) $(BUILDDIR)/libalac.a $(BUILDDIR)/libm4a.a
$(OBJDIR)/aac.elf: $(OBJDIR)/aac.o $(CODECDEPS) $(BUILDDIR)/libfaad.a $(BUILDDIR)/libm4a.a $(OBJDIR)/aac.elf: $(OBJDIR)/aac.o $(CODECDEPS) $(BUILDDIR)/libfaad.a $(BUILDDIR)/libm4a.a
$(OBJDIR)/shorten.elf: $(OBJDIR)/shorten.o $(CODECDEPS) $(BUILDDIR)/libffmpegFLAC.a
$(OBJDIR)/%.elf: $(OBJDIR)/%.o $(CODECDEPS) $(OBJDIR)/%.elf: $(OBJDIR)/%.o $(CODECDEPS)
$(ELFIT) $(ELFIT)

View file

@ -8,4 +8,5 @@ mpc.c
wavpack.c wavpack.c
alac.c alac.c
aac.c aac.c
shorten.c
#endif #endif

View file

@ -1,5 +1,6 @@
bitstream.c bitstream.c
decoder.c decoder.c
shndec.c
#if defined(CPU_COLDFIRE) && !defined(SIMULATOR) #if defined(CPU_COLDFIRE) && !defined(SIMULATOR)
coldfire.S coldfire.S
#endif #endif

View file

@ -46,23 +46,9 @@
#include "coldfire.h" #include "coldfire.h"
#endif #endif
#define INT_MAX 2147483647
#define FFMAX(a,b) ((a) > (b) ? (a) : (b)) #define FFMAX(a,b) ((a) > (b) ? (a) : (b))
#define FFMIN(a,b) ((a) > (b) ? (b) : (a)) #define FFMIN(a,b) ((a) > (b) ? (b) : (a))
/* Needed by golomb.h */
const uint8_t ff_log2_tab[256] ICONST_ATTR = {
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,7,7,7,7,7,7,7,7,7,7,7,7,7,
7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7
};
static const int sample_rate_table[] ICONST_ATTR = static const int sample_rate_table[] ICONST_ATTR =
{ 0, 0, 0, 0, { 0, 0, 0, 0,
8000, 16000, 22050, 24000, 32000, 44100, 48000, 96000, 8000, 16000, 22050, 24000, 32000, 44100, 48000, 96000,

View file

@ -19,9 +19,20 @@
* *
*/ */
#include <limits.h>
/* From libavutil/common.h */ /* From libavutil/common.h */
extern const uint8_t ff_log2_tab[256]; const uint8_t ff_log2_tab[256] ICONST_ATTR = {
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,7,7,7,7,7,7,7,7,7,7,7,7,7,
7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7
};
static inline int av_log2(unsigned int v) static inline int av_log2(unsigned int v)
{ {
int n; int n;
@ -104,3 +115,25 @@ static inline int get_sr_golomb_flac(GetBitContext *gb, int k, int limit, int es
int v= get_ur_golomb_jpegls(gb, k, limit, esc_len); int v= get_ur_golomb_jpegls(gb, k, limit, esc_len);
return (v>>1) ^ -(v&1); return (v>>1) ^ -(v&1);
} }
/**
* read unsigned golomb rice code (shorten).
*/
#define get_ur_golomb_shorten(gb, k) get_ur_golomb_jpegls(gb, k, INT_MAX, 0)
/*
static inline unsigned int get_ur_golomb_shorten(GetBitContext *gb, int k){
return get_ur_golomb_jpegls(gb, k, INT_MAX, 0);
}
*/
/**
* read signed golomb rice code (shorten).
*/
static inline int get_sr_golomb_shorten(GetBitContext* gb, int k)
{
int uvar = get_ur_golomb_jpegls(gb, k + 1, INT_MAX, 0);
if (uvar & 1)
return ~(uvar >> 1);
else
return uvar >> 1;
}

View file

@ -0,0 +1,404 @@
/*
* Shorten decoder
* Copyright (c) 2005 Jeff Muizelaar
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/**
* @file shorten.c
* Shorten decoder
* @author Jeff Muizelaar
*
*/
#include "../codec.h"
#include "../lib/codeclib.h"
extern struct codec_api* ci;
#define DEBUGF ci->debugf
#include "bitstream.h"
#include "golomb.h"
#include "shndec.h"
/* These seem reasonable from my test files.
Does MAX_HEADER_SIZE really need to be 16384? */
#define MAX_PRED_ORDER 16
#define MAX_HEADER_SIZE DEFAULT_BLOCK_SIZE*4
//#define MAX_HEADER_SIZE 16384
#define ULONGSIZE 2
#define WAVE_FORMAT_PCM 0x0001
#define TYPESIZE 4
#define CHANSIZE 0
#define LPCQSIZE 2
#define ENERGYSIZE 3
#define BITSHIFTSIZE 2
#define TYPE_S16HL 3 /* signed 16 bit shorts: high-low */
#define TYPE_S16LH 5 /* signed 16 bit shorts: low-high */
#define NWRAP 3
#define NSKIPSIZE 1
#define LPCQUANT 5
#define V2LPCQOFFSET (1 << LPCQUANT)
#define FNSIZE 2
#define FN_DIFF0 0
#define FN_DIFF1 1
#define FN_DIFF2 2
#define FN_DIFF3 3
#define FN_QUIT 4
#define FN_BLOCKSIZE 5
#define FN_BITSHIFT 6
#define FN_QLPC 7
#define FN_ZERO 8
#define FN_VERBATIM 9
#define VERBATIM_CKSIZE_SIZE 5
#define VERBATIM_BYTE_SIZE 8
#define CANONICAL_HEADER_SIZE 44
#define FFMAX(a,b) ((a) > (b) ? (a) : (b))
#define FFMIN(a,b) ((a) > (b) ? (b) : (a))
#define MKTAG(a,b,c,d) (a | (b << 8) | (c << 16) | (d << 24))
#define get_le16(gb) bswap_16(get_bits_long(gb, 16))
#define get_le32(gb) bswap_32(get_bits_long(gb, 32))
static inline uint32_t bswap_32(uint32_t x){
x= ((x<<8)&0xFF00FF00) | ((x>>8)&0x00FF00FF);
return (x>>16) | (x<<16);
}
static inline uint16_t bswap_16(uint16_t x){
return (x>>8) | (x<<8);
}
/* converts fourcc string to int */
static inline int ff_get_fourcc(const char *s){
//assert( strlen(s)==4 );
return (s[0]) + (s[1]<<8) + (s[2]<<16) + (s[3]<<24);
}
static unsigned int get_uint(ShortenContext *s, int k) ICODE_ATTR;
static unsigned int get_uint(ShortenContext *s, int k)
{
if (s->version != 0)
k = get_ur_golomb_shorten(&s->gb, ULONGSIZE);
return get_ur_golomb_shorten(&s->gb, k);
}
static void decode_subframe_lpc(ShortenContext *s, int32_t *decoded,
int residual_size, int pred_order) ICODE_ATTR;
static void decode_subframe_lpc(ShortenContext *s, int32_t *decoded,
int residual_size, int pred_order)
{
int sum, i, j;
int coeffs[MAX_PRED_ORDER];
for (i=0; i<pred_order; i++) {
coeffs[i] = get_sr_golomb_shorten(&s->gb, LPCQUANT);
}
for (i=0; i < s->blocksize; i++) {
sum = s->lpcqoffset;
for (j=0; j<pred_order; j++)
sum += coeffs[j] * decoded[i-j-1];
decoded[i] =
get_sr_golomb_shorten(&s->gb, residual_size) + (sum >> LPCQUANT);
}
}
int shorten_decode_frame(ShortenContext *s,
int32_t *decoded,
int32_t *offset,
uint8_t *buf,
int buf_size)
{
int i;
int32_t sum;
init_get_bits(&s->gb, buf, buf_size*8);
get_bits(&s->gb, s->bitindex);
int cmd = get_ur_golomb_shorten(&s->gb, FNSIZE);
switch (cmd) {
case FN_ZERO:
case FN_DIFF0:
case FN_DIFF1:
case FN_DIFF2:
case FN_DIFF3:
case FN_QLPC:
{
int residual_size = 0;
int32_t coffset;
if (cmd != FN_ZERO) {
residual_size = get_ur_golomb_shorten(&s->gb, ENERGYSIZE);
/* this is a hack as version 0 differed in defintion of
get_sr_golomb_shorten */
if (s->version == 0)
residual_size--;
}
if (s->nmean == 0) {
coffset = offset[0];
} else {
sum = (s->version < 2) ? 0 : s->nmean / 2;
for (i=0; i<s->nmean; i++)
sum += offset[i];
coffset = sum / s->nmean;
if (s->version >= 2)
coffset >>= FFMIN(1, s->bitshift);
}
switch (cmd) {
case FN_ZERO:
for (i=0; i<s->blocksize; i++)
decoded[i] = 0;
break;
case FN_DIFF0:
for (i=0; i<s->blocksize; i++)
decoded[i] =
get_sr_golomb_shorten(&s->gb, residual_size) +
coffset;
break;
case FN_DIFF1:
for (i=0; i<s->blocksize; i++)
decoded[i] =
get_sr_golomb_shorten(&s->gb, residual_size) +
decoded[i - 1];
break;
case FN_DIFF2:
for (i=0; i<s->blocksize; i++)
decoded[i] =
get_sr_golomb_shorten(&s->gb, residual_size) +
2*decoded[i-1] - decoded[i-2];
break;
case FN_DIFF3:
for (i=0; i<s->blocksize; i++)
decoded[i] =
get_sr_golomb_shorten(&s->gb, residual_size) +
3*decoded[i-1] - 3*decoded[i-2] + decoded[i-3];
break;
case FN_QLPC:
{
int pred_order = get_ur_golomb_shorten(&s->gb, LPCQSIZE);
if (pred_order > MAX_PRED_ORDER) {
return -2;
}
for (i=0; i<pred_order; i++)
decoded[i - pred_order] -= coffset;
decode_subframe_lpc(s, decoded, residual_size, pred_order);
if (coffset != 0) {
for (i=0; i < s->blocksize; i++)
decoded[i] += coffset;
}
}
}
if (s->nmean > 0) {
sum = (s->version < 2) ? 0 : s->blocksize / 2;
for (i=0; i<s->blocksize; i++)
sum += decoded[i];
for (i=1; i<s->nmean; i++)
offset[i-1] = offset[i];
if (s->version < 2) {
offset[s->nmean - 1] = sum / s->blocksize;
} else {
offset[s->nmean - 1] =
(sum / s->blocksize) << s->bitshift;
}
}
for (i=-s->nwrap; i<0; i++)
decoded[i] = decoded[i + s->blocksize];
int scale = s->bitshift + SHN_OUTPUT_DEPTH - s->bits_per_sample;
for (i = 0; i < s->blocksize; i++)
decoded[i] <<= scale;
break;
}
case FN_VERBATIM:
i = get_ur_golomb_shorten(&s->gb, VERBATIM_CKSIZE_SIZE);
while (i--)
get_ur_golomb_shorten(&s->gb, VERBATIM_BYTE_SIZE);
return 4;
break;
case FN_BITSHIFT:
s->bitshift = get_ur_golomb_shorten(&s->gb, BITSHIFTSIZE);
return 3;
break;
case FN_BLOCKSIZE:
s->blocksize = get_uint(s, av_log2(s->blocksize));
return 2;
break;
case FN_QUIT:
return 1;
break;
default:
return -1;
break;
}
return 0;
}
static int decode_wave_header(ShortenContext *s,
uint8_t *header,
int header_size)
{
GetBitContext hb;
int len;
init_get_bits(&hb, header, header_size*8);
if (get_le32(&hb) != MKTAG('R','I','F','F')) {
return -8;
}
int chunk_size = get_le32(&hb);
if (get_le32(&hb) != MKTAG('W','A','V','E')) {
return -9;
}
while (get_le32(&hb) != MKTAG('f','m','t',' ')) {
len = get_le32(&hb);
skip_bits(&hb, 8*len);
}
len = get_le32(&hb);
if (len < 16) {
return -10;
}
if (get_le16(&hb) != WAVE_FORMAT_PCM ) {
return -11;
}
s->channels = get_le16(&hb);
if (s->channels > MAX_CHANNELS) {
return -3;
}
s->sample_rate = get_le32(&hb);
skip_bits(&hb, 32);
//s->bit_rate = 8*get_le32(&hb);
int block_align = get_le16(&hb);
s->totalsamples = (chunk_size - 36) / block_align;
s->bits_per_sample = get_le16(&hb);
if (s->bits_per_sample != 16) {
return -12;
}
len -= 16;
if (len > 0) {
return len;
}
return 0;
}
int shorten_init(ShortenContext* s, uint8_t *buf, int buf_size)
{
int i;
s->blocksize = DEFAULT_BLOCK_SIZE;
s->channels = 1;
s->nmean = -1;
init_get_bits(&s->gb, buf, buf_size*8);
get_bits(&s->gb, s->bitindex);
/* shorten signature */
if (get_bits_long(&s->gb, 32) != bswap_32(ff_get_fourcc("ajkg"))) {
return -1;
}
s->version = get_bits(&s->gb, 8);
int internal_ftype = get_uint(s, TYPESIZE);
if ((internal_ftype != TYPE_S16HL) && (internal_ftype != TYPE_S16LH)) {
return -2;
}
s->channels = get_uint(s, CHANSIZE);
if (s->channels > MAX_CHANNELS) {
return -3;
}
/* get blocksize if version > 0 */
int maxnlpc = 0;
if (s->version > 0) {
s->blocksize = get_uint(s, av_log2(DEFAULT_BLOCK_SIZE));
maxnlpc = get_uint(s, LPCQSIZE);
s->nmean = get_uint(s, 0);
int skip_bytes = get_uint(s, NSKIPSIZE);
for (i=0; i<skip_bytes; i++) {
skip_bits(&s->gb, 8);
}
}
if (s->nmean > MAX_NMEAN) {
return -4;
}
s->nwrap = FFMAX(NWRAP, maxnlpc);
if (s->nwrap > MAX_NWRAP) {
return -5;
}
if (s->version > 1)
s->lpcqoffset = V2LPCQOFFSET;
if (get_ur_golomb_shorten(&s->gb, FNSIZE) != FN_VERBATIM) {
return -6;
}
uint8_t header[MAX_HEADER_SIZE];
int header_size = get_ur_golomb_shorten(&s->gb, VERBATIM_CKSIZE_SIZE);
if (header_size >= MAX_HEADER_SIZE || header_size < CANONICAL_HEADER_SIZE) {
return -7;
}
for (i=0; i<header_size; i++)
header[i] = (char)get_ur_golomb_shorten(&s->gb, VERBATIM_BYTE_SIZE);
s->header_bits = s->gb.index;
return decode_wave_header(s, header, header_size);
}

View file

@ -0,0 +1,36 @@
#include "bitstream.h"
#define SHN_OUTPUT_DEPTH 28
#define DEFAULT_BLOCK_SIZE 256
#define MAX_FRAMESIZE 1024
#define MAX_CHANNELS 2
#define MAX_NWRAP 3
#define MAX_NMEAN 4
typedef struct ShortenContext {
GetBitContext gb;
int32_t lpcqoffset;
uint32_t totalsamples;
int header_bits;
int channels;
int sample_rate;
int bits_per_sample;
int version;
int bitshift;
int nmean;
int nwrap;
int blocksize;
int bitindex;
/* Not needed...
int bit_rate;
int block_align;
int chunk_size;
*/
} ShortenContext;
int shorten_init(ShortenContext* s, uint8_t *buf, int buf_size);
int shorten_decode_frame(ShortenContext *s,
int32_t *decoded,
int32_t *offset,
uint8_t *buf,
int buf_size) ICODE_ATTR;

169
apps/codecs/shorten.c Normal file
View file

@ -0,0 +1,169 @@
/***************************************************************************
* __________ __ ___.
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
* \/ \/ \/ \/ \/
* $Id:
*
* Copyright (C) 2005 Mark Arigo
*
* 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.
*
****************************************************************************/
#include "codeclib.h"
#include <codecs/libffmpegFLAC/shndec.h>
#ifndef SIMULATOR
extern char iramcopy[];
extern char iramstart[];
extern char iramend[];
#endif
struct codec_api* rb;
struct codec_api* ci;
#define MAX_DECODED (DEFAULT_BLOCK_SIZE + MAX_NWRAP)
int32_t decoded0[MAX_DECODED] IBSS_ATTR;
int32_t decoded1[MAX_DECODED] IBSS_ATTR;
#define MAX_OFFSETS MAX_NMEAN
int32_t offset0[MAX_OFFSETS] IBSS_ATTR;
int32_t offset1[MAX_OFFSETS] IBSS_ATTR;
/* this is the codec entry point */
enum codec_status codec_start(struct codec_api* api)
{
ShortenContext sc;
uint32_t samplesdone;
uint32_t elapsedtime;
int8_t *buf;
int cur_chan, consumed, res;
long bytesleft;
/* Generic codec initialisation */
TEST_CODEC_API(api);
rb = api;
ci = (struct codec_api*)api;
#ifndef SIMULATOR
ci->memcpy(iramstart, iramcopy, iramend-iramstart);
#endif
ci->configure(CODEC_SET_FILEBUF_LIMIT, (int *)(1024*1024*10));
ci->configure(CODEC_SET_FILEBUF_WATERMARK, (int *)(1024*512));
ci->configure(CODEC_SET_FILEBUF_CHUNKSIZE, (int *)(1024*128));
ci->configure(CODEC_DSP_ENABLE, (bool *)true);
ci->configure(DSP_DITHER, (bool *)false);
ci->configure(DSP_SET_STEREO_MODE, (long *)STEREO_NONINTERLEAVED);
ci->configure(DSP_SET_SAMPLE_DEPTH, (int *)(SHN_OUTPUT_DEPTH-1));
next_track:
/* Codec initialization */
if (codec_init(api)) {
LOGF("Shorten: Error initialising codec\n");
return CODEC_ERROR;
}
while (!*ci->taginfo_ready)
ci->yield();
/* Shorten decoder initialization */
ci->memset(&sc, 0, sizeof(ShortenContext));
/* Read the shorten & wave headers */
buf = ci->request_buffer(&bytesleft, MAX_FRAMESIZE);
res = shorten_init(&sc, buf, bytesleft);
if (res < 0) {
LOGF("shorten_init error: %d\n", res);
return CODEC_ERROR;
}
ci->configure(DSP_SET_FREQUENCY, (long *)(sc.sample_rate));
ci->id3->frequency = sc.sample_rate;
ci->id3->length = (sc.totalsamples / sc.sample_rate) * 1000;
consumed = sc.gb.index/8;
ci->advance_buffer(consumed);
sc.bitindex = sc.gb.index - 8*consumed;
seek_start:
/* The main decoding loop */
ci->memset(&decoded0, 0, sizeof(int32_t)*MAX_DECODED);
ci->memset(&decoded1, 0, sizeof(int32_t)*MAX_DECODED);
ci->memset(&offset0, 0, sizeof(int32_t)*MAX_OFFSETS);
ci->memset(&offset1, 0, sizeof(int32_t)*MAX_OFFSETS);
cur_chan = 0;
samplesdone = 0;
buf = ci->request_buffer(&bytesleft, MAX_FRAMESIZE);
while (bytesleft) {
ci->yield();
if (ci->stop_codec || ci->reload_codec) {
break;
}
/* Seek to start of track */
if (ci->seek_time == 1) {
if (ci->seek_buffer(sc.header_bits/8)) {
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 */
ci->yield();
if (cur_chan == 0) {
res = shorten_decode_frame(&sc, decoded0 + sc.nwrap, offset0,
buf, bytesleft);
} else {
res = shorten_decode_frame(&sc, decoded1 + sc.nwrap, offset1,
buf, bytesleft);
}
cur_chan++;
if (res == 0 && cur_chan == sc.channels) {
cur_chan = 0;
/* Insert decoded samples in pcmbuf */
ci->yield();
while (!ci->pcmbuf_insert_split((char*)(decoded0 + sc.nwrap),
(char*)(decoded1 + sc.nwrap), sc.blocksize*4)) {
ci->yield();
}
/* Update the elapsed-time indicator */
samplesdone += sc.blocksize;
elapsedtime = (samplesdone*10) / (sc.sample_rate/100);
ci->set_elapsed(elapsedtime);
} else if (res == 1) {
/* End of shorten stream...go to next track */
break;
} else if (res < 0) {
LOGF("shorten_decode_frame error: \n", res);
return CODEC_ERROR;
}
consumed = sc.gb.index/8;
ci->advance_buffer(consumed);
sc.bitindex = sc.gb.index - 8*consumed;
buf = ci->request_buffer(&bytesleft, MAX_FRAMESIZE);
}
LOGF("Shorten: Decoded %d samples\n", samplesdone);
if (ci->request_next_track())
goto next_track;
return CODEC_OK;
}

View file

@ -77,6 +77,7 @@ static const struct format_list formats[] =
{ AFMT_WAVPACK, "wv" }, { AFMT_WAVPACK, "wv" },
{ AFMT_ALAC, "m4a" }, { AFMT_ALAC, "m4a" },
{ AFMT_AAC, "mp4" }, { AFMT_AAC, "mp4" },
{ AFMT_SHN, "shn" },
}; };
static const unsigned short a52_bitrates[] = static const unsigned short a52_bitrates[] =

View file

@ -76,6 +76,7 @@ static volatile bool paused;
#define CODEC_WAVPACK "/.rockbox/codecs/wavpack.codec" #define CODEC_WAVPACK "/.rockbox/codecs/wavpack.codec"
#define CODEC_ALAC "/.rockbox/codecs/alac.codec" #define CODEC_ALAC "/.rockbox/codecs/alac.codec"
#define CODEC_AAC "/.rockbox/codecs/aac.codec" #define CODEC_AAC "/.rockbox/codecs/aac.codec"
#define CODEC_SHN "/.rockbox/codecs/shorten.codec"
#define AUDIO_FILL_CYCLE (1024*256) #define AUDIO_FILL_CYCLE (1024*256)
#define AUDIO_DEFAULT_WATERMARK (1024*512) #define AUDIO_DEFAULT_WATERMARK (1024*512)
@ -906,6 +907,10 @@ bool loadcodec(const char *trackname, bool start_play)
logf("Codec: AAC"); logf("Codec: AAC");
codec_path = CODEC_AAC; codec_path = CODEC_AAC;
break; break;
case AFMT_SHN:
logf("Codec: SHN");
codec_path = CODEC_SHN;
break;
default: default:
logf("Codec: Unsupported"); logf("Codec: Unsupported");
snprintf(msgbuf, sizeof(msgbuf)-1, "No codec for: %s", trackname); snprintf(msgbuf, sizeof(msgbuf)-1, "No codec for: %s", trackname);

View file

@ -92,6 +92,7 @@ const struct filetype filetypes[] = {
{ "wv", TREE_ATTR_MPA, Icon_Audio, VOICE_EXT_MPA }, { "wv", TREE_ATTR_MPA, Icon_Audio, VOICE_EXT_MPA },
{ "m4a", TREE_ATTR_MPA, Icon_Audio, VOICE_EXT_MPA }, { "m4a", TREE_ATTR_MPA, Icon_Audio, VOICE_EXT_MPA },
{ "mp4", TREE_ATTR_MPA, Icon_Audio, VOICE_EXT_MPA }, { "mp4", TREE_ATTR_MPA, Icon_Audio, VOICE_EXT_MPA },
{ "shn", TREE_ATTR_MPA, Icon_Audio, VOICE_EXT_MPA },
#endif #endif
{ "m3u", TREE_ATTR_M3U, Icon_Playlist, LANG_PLAYLIST }, { "m3u", TREE_ATTR_M3U, Icon_Playlist, LANG_PLAYLIST },
{ "cfg", TREE_ATTR_CFG, Icon_Config, VOICE_EXT_CFG }, { "cfg", TREE_ATTR_CFG, Icon_Config, VOICE_EXT_CFG },

View file

@ -138,3 +138,4 @@ Stephan Wezel
Alyssa Milburn Alyssa Milburn
Kevin Ferrare Kevin Ferrare
Anton Oleynikov Anton Oleynikov
Mark Arigo

View file

@ -40,6 +40,7 @@ enum {
AFMT_WAVPACK, /* WavPack */ AFMT_WAVPACK, /* WavPack */
AFMT_ALAC, /* Apple Lossless Audio Codec */ AFMT_ALAC, /* Apple Lossless Audio Codec */
AFMT_AAC, /* Advanced Audio Coding (AAC) in M4A container */ AFMT_AAC, /* Advanced Audio Coding (AAC) in M4A container */
AFMT_SHN, /* Shorten */
/* New formats must be added to the end of this list */ /* New formats must be added to the end of this list */

View file

@ -100,6 +100,7 @@ static const char* const codec_labels[] = {
"WV", /* WavPack */ "WV", /* WavPack */
"ALAC", /* Apple Lossless Audio Codec */ "ALAC", /* Apple Lossless Audio Codec */
"AAC", /* Advanced Audio Coding in M4A container */ "AAC", /* Advanced Audio Coding in M4A container */
"SHN", /* Shorten */
#endif #endif
}; };