From 4ff2cf4f0c96908f28c5037521251e0c809130bb Mon Sep 17 00:00:00 2001 From: Mohamed Tarek Date: Sat, 7 Aug 2010 17:55:02 +0000 Subject: WMA Voice now plays and seeks in the sim. The code is still in floating point, and is not added to the main build. There's still a bug with the decoder in the current state that it outputs a fewer number of samples than ffmpeg's. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@27744 a1c6a512-1295-4272-9138-f99709370657 --- apps/codecs/libwmavoice/SOURCES | 17 +++++++++++++++ apps/codecs/libwmavoice/libwmavoice.make | 37 ++++++++++++++++++++++++++++++++ apps/codecs/libwmavoice/wmavoice.c | 33 +++++++++++++++++++++++----- apps/codecs/libwmavoice/wmavoice.h | 7 ++++++ 4 files changed, 89 insertions(+), 5 deletions(-) create mode 100644 apps/codecs/libwmavoice/SOURCES create mode 100644 apps/codecs/libwmavoice/libwmavoice.make create mode 100644 apps/codecs/libwmavoice/wmavoice.h (limited to 'apps/codecs/libwmavoice') diff --git a/apps/codecs/libwmavoice/SOURCES b/apps/codecs/libwmavoice/SOURCES new file mode 100644 index 0000000..c98821c --- /dev/null +++ b/apps/codecs/libwmavoice/SOURCES @@ -0,0 +1,17 @@ +acelp_filters.c +acelp_vectors.c +avfft.c +bitstream.c +celp_filters.c +celp_math.c +dct.c +fft.c +lsp.c +mdct.c +rdft.c +utils.c +wmavoice.c +libavutil/log.c +libavutil/lzo.c +libavutil/mem.c +libavutil/mathematics.c diff --git a/apps/codecs/libwmavoice/libwmavoice.make b/apps/codecs/libwmavoice/libwmavoice.make new file mode 100644 index 0000000..0497e18 --- /dev/null +++ b/apps/codecs/libwmavoice/libwmavoice.make @@ -0,0 +1,37 @@ +# __________ __ ___. +# Open \______ \ ____ ____ | | _\_ |__ _______ ___ +# Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / +# Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < +# Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ +# \/ \/ \/ \/ \/ +# $Id: libwmavoice.make 27586 2010-07-27 06:48:15Z nls $ +# + +# libwmavoice +WMAVOICELIB := $(CODECDIR)/libwmavoice.a +WMAVOICELIB_SRC := $(call preprocess, $(APPSDIR)/codecs/libwmavoice/SOURCES) +WMAVOICELIB_OBJ := $(call c2obj, $(WMAVOICELIB_SRC)) +OTHER_SRC += $(WMAVOICELIB_SRC) + +$(WMAVOICELIB): $(WMAVOICELIB_OBJ) + $(SILENT)$(shell rm -f $@) + $(call PRINTS,AR $(@F))$(AR) rcs $@ $^ >/dev/null + +WMAVOICEFLAGS = -I$(APPSDIR)/codecs/libwmavoice $(filter-out -O%,$(CODECFLAGS)) + +ifeq ($(CPU),coldfire) + WMAVOICEFLAGS += -O2 +else + WMAVOICEFLAGS += -O1 +endif + +ifeq ($(APP_TYPE),sdl-sim) +# wmavoice needs libm in the simulator +$(CODECDIR)/wmavoice.codec: $(CODECDIR)/wmavoice.o + $(call PRINTS,LD $(@F))$(CC) $(CODECFLAGS) -o $(CODECDIR)/wmavoice.elf \ + $(filter %.o, $^) \ + $(filter %.a, $+) \ + -lgcc -lm $(CODECLDFLAGS) + $(SILENT)cp $(CODECDIR)/wmavoice.elf $@ +endif + diff --git a/apps/codecs/libwmavoice/wmavoice.c b/apps/codecs/libwmavoice/wmavoice.c index 39bcb0e..f8bd6d6 100644 --- a/apps/codecs/libwmavoice/wmavoice.c +++ b/apps/codecs/libwmavoice/wmavoice.c @@ -26,7 +26,7 @@ */ #include -#include "avcodec.h" +#include "wmavoice.h" #include "get_bits.h" #include "put_bits.h" #include "wmavoice_data.h" @@ -286,6 +286,10 @@ typedef struct { */ } WMAVoiceContext; +/* global decode context */ +static WMAVoiceContext globWMAVoiceCtx; + + /** * Set up the variable bit mode (VBM) tree from container extradata. * @param gb bit I/O context. @@ -330,9 +334,10 @@ static av_cold int decode_vbmtree(GetBitContext *gb, int8_t vbm_tree[25]) /** * Set up decoder with parameters from demuxer (extradata etc.). */ -static av_cold int wmavoice_decode_init(AVCodecContext *ctx) +av_cold int wmavoice_decode_init(AVCodecContext *ctx) { int n, flags, pitch_range, lsp16_flag; + ctx->priv_data = &globWMAVoiceCtx; WMAVoiceContext *s = ctx->priv_data; /** @@ -1743,7 +1748,7 @@ static int synth_superframe(AVCodecContext *ctx, * the wild yet. */ if (!get_bits1(gb)) { av_log_missing_feature(ctx, "WMAPro-in-WMAVoice support", 1); - return -1; + return ERROR_WMAPRO_IN_WMAVOICE; } /* (optional) nr. of samples in superframe; always <= 480 and >= 0 */ @@ -1893,7 +1898,7 @@ static void copy_bits(PutBitContext *pb, * * For more information about frames, see #synth_superframe(). */ -static int wmavoice_decode_packet(AVCodecContext *ctx, void *data, +int wmavoice_decode_packet(AVCodecContext *ctx, void *data, int *data_size, AVPacket *avpkt) { WMAVoiceContext *s = ctx->priv_data; @@ -1936,6 +1941,15 @@ static int wmavoice_decode_packet(AVCodecContext *ctx, void *data, s->sframe_cache_size += s->spillover_nbits; if ((res = synth_superframe(ctx, data, data_size)) == 0 && *data_size > 0) { + /* convert the float values to int32 for rockbox */ + int i; + int32_t *iptr = data; + float *fptr = data; + for(i = 0; i < *data_size/sizeof(float); i++) + { + fptr[i] *= (float)(INT32_MAX); + iptr[i] = (int32_t)fptr[i]; + } cnt += s->spillover_nbits; s->skip_bits_next = cnt & 7; return cnt >> 3; @@ -1957,12 +1971,21 @@ static int wmavoice_decode_packet(AVCodecContext *ctx, void *data, } else if (*data_size > 0) { int cnt = get_bits_count(gb); s->skip_bits_next = cnt & 7; + /* convert the float values to int32 for rockbox */ + int i; + int32_t *iptr = data; + float *fptr = data; + for(i = 0; i < *data_size/sizeof(float); i++) + { + fptr[i] *= (float)(INT32_MAX); + iptr[i] = (int32_t)fptr[i]; + } return cnt >> 3; } else if ((s->sframe_cache_size = pos) > 0) { /* rewind bit reader to start of last (incomplete) superframe... */ init_get_bits(gb, avpkt->data, size << 3); skip_bits_long(gb, (size << 3) - pos); - assert(get_bits_left(gb) == pos); + //assert(get_bits_left(gb) == pos); /* ...and cache it for spillover in next packet */ init_put_bits(&s->pb, s->sframe_cache, SFRAME_CACHE_MAXSIZE); diff --git a/apps/codecs/libwmavoice/wmavoice.h b/apps/codecs/libwmavoice/wmavoice.h new file mode 100644 index 0000000..33ec72b --- /dev/null +++ b/apps/codecs/libwmavoice/wmavoice.h @@ -0,0 +1,7 @@ +#include "avcodec.h" + +#define ERROR_WMAPRO_IN_WMAVOICE -0x162 + +av_cold int wmavoice_decode_init(AVCodecContext *ctx); +int wmavoice_decode_packet(AVCodecContext *ctx, void *data, + int *data_size, AVPacket *avpkt); -- cgit v1.1