[FFmpeg-soc] [soc]: r310 - in qcelp: README doc doc/NOTES doc/TODO qcelp.h qcelp_glue.diff qcelpdec.c srcprepare.sh

reynaldo subversion at mplayerhq.hu
Tue Jul 3 22:16:49 CEST 2007


Author: reynaldo
Date: Tue Jul  3 22:16:49 2007
New Revision: 310

Log:
Some structural code frame, only thing I would consider ready for initial peer review here is the parsing and reordering routine. feel free to destroy everything along with it thouhg ;)

Added:
   qcelp/README
   qcelp/doc/
   qcelp/doc/NOTES
   qcelp/doc/TODO
   qcelp/qcelp.h
   qcelp/qcelp_glue.diff
   qcelp/qcelpdec.c
   qcelp/srcprepare.sh   (contents, props changed)

Added: qcelp/README
==============================================================================
--- (empty file)
+++ qcelp/README	Tue Jul  3 22:16:49 2007
@@ -0,0 +1,7 @@
+Testing instructions ;)
+
+1.- svn update
+2.- From this dir run ./srcprepare.sh /path/to/clean/FFmpeg/repo
+    (a new dir with ffmpeg sources is created here, your repo stays untouched)
+3.- cd trunk
+4.- ./configure ; make

Added: qcelp/doc/NOTES
==============================================================================
--- (empty file)
+++ qcelp/doc/NOTES	Tue Jul  3 22:16:49 2007
@@ -0,0 +1,36 @@
+This notes are abstracts from the standard that might
+be usesfull in understanding whats going on.
+
+
+How stuff works
+---------------
+
+The input speech is sampled at 8kHz. This speech is broken
+down into 20ms speech codec frames, each consisting of 160
+samples. The format synthesis (LPC) filter coefficients are
+updated once per frame, regardless of the data rate selected.
+The number of bits used to encode the LPC parameters is a
+function of the selected rate (1, 1/2, 1/4, 1/8).
+
+
+Parameters codes transmited for each rate packet (Page 25)
+------------------------------------------------
+
+LSPi     |  Line Spectral Pair frequency i.
+LSPVi    |  Line Spectral Pair frequencies grouped into five R2 vectors.
+PLAGi    |  Pitch Lag for the ith pitch subframe.
+PFRACi   |  Fractional Pitch Lag for the ith pitch subframe.
+PGAINi   |  Pitch Gain for the ith pitch subframe.
+CBINDEXi |  Codebook Index for the ith codebook subframe.
+CBGAINi  |  Unsigned Codebook Gain for the ith codebook subframe.
+CBSEED   |  Random Seed for Rate 1/8 packets.
+CBSIGNi  |  Sign of the Codebook Gain for the ith codebook subframe.
+
+
+Bits for each rate packet (Page 26)
+-------------------------
+
+Rate 1   | 264 + 2 Reserved
+Rate 1/2 | 124
+Rate 1/4 | 52  + 2 Reserved
+Rate 1/8 | 16  + 4 Reserved

Added: qcelp/doc/TODO
==============================================================================
--- (empty file)
+++ qcelp/doc/TODO	Tue Jul  3 22:16:49 2007
@@ -0,0 +1 @@
+- todo :)

Added: qcelp/qcelp.h
==============================================================================
--- (empty file)
+++ qcelp/qcelp.h	Tue Jul  3 22:16:49 2007
@@ -0,0 +1,242 @@
+/*
+ * QCELP Decoder
+ * Copyright (c) 2007 Reynaldo H. Verdejo Pinochet
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg 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.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg 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 FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+/**
+ * @file qcelp.h
+ * QCELP decoder.
+ */
+
+typedef enum
+{
+    RATE_FULL   = 0,
+    RATE_HALF   = 1,
+    RATE_QUARTER= 2,
+    RATE_OCTAVE = 3,
+    I_F_Q,        /* insuficient frame quality */
+    BLANK,
+    RATE_UNKNOWN
+} qcelp_packet_type;
+
+static uint16_t qcelp_bits_per_type[]={266,124,54,20};
+
+typedef struct {
+    uint8_t index;  /* index into the reference frame */
+    uint8_t bitpos; /* bit position in the value's byte */
+} QCELPBitmap;
+
+
+/*
+ * WARNING
+ *
+ * YOU WONT SEE ANY mention of a REFERENCE nor an UNIVERSAL frame
+ * in the specs, this is just some internal way of handling the
+ * reordering needed to unify the decoding process _inside_ this
+ * code, nothing more.
+ *
+ */
+
+/*
+ * REFERENCE FRAME
+ *
+ * This are the reference frame slices. Each touple will be mapped to a
+ * QCELPBitmap showing the location of each bit in the input * with
+ * respect to a transmision code in the 'universal frame'.
+ *
+ * FIXME
+ * it would be really nice if someone reviewed this numbers :)
+ *------------------------------------------------------------------*/
+
+#define QCELP_RATE_FULL_BITMAP \
+{15,0},{47,0},{47,1},{47,2},{47,3},{47,4},{47,5},{47,6},\
+{65,0},{65,1},{45,6},{30,0},{30,1},{30,2},{30,3},{14,0},\
+{46,0},{46,1},{46,2},{46,3},{46,4},{46,5},{46,6},{31,0},\
+{31,1},{31,2},{44,2},{44,3},{44,4},{44,5},{44,6},{29,0},\
+{29,1},{29,2},{29,3},{13,0},{45,0},{45,1},{45,2},{45,3},\
+{45,4},{45,5},{59,2},{51,0},{51,1},{51,2},{51,3},{51,4},\
+{51,5},{51,6},{55,0},{28,0},{28,1},{28,2},{28,3},{12,0},\
+{44,0},{44,1},{42,4},{42,5},{42,6},{27,0},{27,1},{27,2},\
+{11,0},{43,0},{43,1},{43,2},{43,3},{43,4},{43,5},{43,6},\
+{59,0},{59,1},{41,0},{41,1},{41,2},{41,3},{41,4},{41,5},\
+{41,6},{26,0},{26,1},{26,2},{26,3},{10,0},{42,0},{42,1},\
+{42,2},{42,3},{24,1},{24,2},{24,3},{ 8,0},{40,0},{40,1},\
+{40,2},{40,3},{40,4},{40,5},{40,6},{24,0},{24,1},{24,2},\
+{24,3},{ 9,0},{39,3},{39,4},{39,5},{39,6},{58,0},{58,1},\
+{58,3},{50,0},{50,1},{50,2},{50,3},{50,4},{50,5},{50,6},\
+{54,0},{24,0},{22,3},{ 6,0},{38,0},{38,1},{38,2},{38,3},\
+{38,4},{38,5},{38,6},{23,0},{23,1},{23,2},{ 7,0},{39,0},\
+{39,1},{39,2},{36,6},{21,0},{21,1},{21,2},{21,3},{ 5,0},\
+{37,0},{37,1},{37,2},{37,3},{37,4},{37,5},{37,6},{22,0},\
+{22,1},{22,2},{49,3},{49,4},{49,5},{49,6},{53,0},{20,0},\
+{20,1},{20,2},{20,3},{ 4,0},{36,0},{36,1},{36,2},{36,3},\
+{36,4},{36,5},{19,1},{19,2},{ 3,0},{35,0},{35,1},{35,2},\
+{35,3},{35,4},{35,5},{35,6},{57,0},{57,1},{57,2},{49,0},\
+{49,1},{49,2},{33,4},{33,5},{33,6},{18,0},{18,1},{18,2},\
+{18,3},{ 2,0},{34,0},{34,1},{34,2},{34,3},{34,4},{34,5},\
+{34,6},{19,0},{32,0},{32,1},{32,2},{32,3},{32,4},{32,5},\
+{32,6},{17,0},{17,1},{17,2},{17,3},{ 1,0},{33,0},{33,1},\
+{33,2},{33,3},{56,0},{56,1},{56,2},{48,0},{48,1},{48,2},\
+{48,3},{48,4},{48,5},{48,6},{52,0},{16,0},{16,1},{16,2},\
+{ 0,3},{ 0,0},{62,3},{62,4},{62,5},{62,6},{63,0},{63,1},\
+{63,2},{63,3},{63,4},{63,5},{64,0},{64,1},{64,2},{64,3},\
+{64,4},{64,5},{60,0},{60,1},{60,2},{60,3},{60,4},{60,5},\
+{61,0},{61,1},{61,2},{61,3},{61,4},{61,5},{61,6},{62,0},\
+{62,1},{62,2}
+
+#define QCELP_RATE_HALF_BITMAP \
+{19,0},{19,1},{19,2},{19,3},{ 3,0},{35,0},{35,1},{35,2},\
+{35,3},{35,4},{35,5},{35,6},{34,2},{34,3},{34,4},{34,5},\
+{34,6},{59,0},{59,1},{59,2},{51,0},{51,1},{51,2},{51,3},\
+{51,4},{51,5},{51,6},{55,0},{58,2},{50,0},{50,1},{50,2},\
+{50,3},{50,4},{50,5},{50,6},{54,0},{18,0},{18,1},{18,2},\
+{18,3},{ 2,0},{34,0},{34,1},{49,6},{53,0},{17,0},{17,1},\
+{17,2},{17,3},{ 1,0},{33,0},{33,1},{33,2},{33,3},{33,4},\
+{33,5},{33,6},{58,0},{58,1},{32,0},{32,1},{32,2},{32,3},\
+{32,4},{32,5},{32,6},{57,0},{57,1},{57,2},{49,0},{49,1},\
+{49,2},{49,3},{49,4},{49,5},{56,0},{56,1},{56,2},{48,0},\
+{48,1},{48,2},{48,3},{48,4},{48,5},{48,6},{52,1},{16,0},\
+{16,1},{16,2},{16,3},{ 0,0},{62,3},{62,4},{62,5},{62,6},\
+{63,0},{63,1},{63,2},{63,3},{63,4},{63,5},{64,0},{64,1},\
+{64,2},{64,3},{64,4},{64,5},{60,0},{60,1},{60,2},{60,3},\
+{60,4},{60,5},{61,0},{61,1},{61,2},{61,3},{61,4},{61,5},\
+{61,6},{62,0},{62,1},{62,2}
+
+#define QCELP_RATE_4THR_BITMAP \
+{20,0},{20,1},{20,2},{20,3},{65,0},{65,1},{16,0},{16,1},\
+{16,2},{16,3},{17,0},{17,1},{17,2},{17,3},{18,0},{18,1},\
+{18,2},{18,3},{19,0},{19,1},{19,2},{19,3},{62,3},{62,4},\
+{62,5},{62,6},{63,0},{63,1},{63,2},{63,3},{63,4},{63,5},\
+{64,0},{64,1},{64,2},{64,3},{64,4},{64,5},{60,0},{60,1},\
+{60,2},{60,3},{60,4},{60,5},{61,0},{61,1},{61,2},{61,3},\
+{61,4},{61,5},{61,6},{62,0},{62,1},{62,2}
+
+#define QCELP_RATE_8THR_BITMAP \
+{76,3},{66,0},{67,0},{68,0},{76,2},{69,0},{70,0},{71,0},\
+{76,1},{72,0},{73,0},{74,0},{76,0},{75,0},{16,1},{16,0},\
+{65,3},{65,2},{65,1},{65,0}
+
+
+/*
+ * Position of the bitmapping data for each pkt type in
+ * the big REFERENCE FRAME array
+ *
+ */
+
+#define QCELP_FULLPKT_REFERENCE_POS 0
+#define QCELP_HALFPKT_REFERENCE_POS 266
+#define QCELP_4THRPKT_REFERENCE_POS 390
+#define QCELP_8THRPKT_REFERENCE_POS 444
+
+/*
+ * Reference frame, finally :-)
+ *
+ */
+
+static QCELPBitmap QCELP_REFERENCE_FRAME[]={QCELP_RATE_FULL_BITMAP,
+                                            QCELP_RATE_HALF_BITMAP,
+                                            QCELP_RATE_4THR_BITMAP,
+                                            QCELP_RATE_8THR_BITMAP};
+
+/*
+ * UNIVERSAL FRAME
+ *
+ *
+ * Oce frame is parsed all data gets stored in QCELPFrame.data acording
+ * to this structure:
+ *
+ *     QCELP_X0_POS
+ *           |
+ * CBSIGNs   0     1  2  3  4  5  6  7  8  9 10 11 12 13 14 15
+ * CBGAINs  16    17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
+ * CINDEXs  32    33 34 35 36 37 38 39 40 41 43 43 44 45 46 47
+ * PLAGs    48    49 50 51
+ * PFRACs   52    53 54 55
+ * PGAINs   56    57 58 59
+ * LSPVs    60    61 62 63 64
+ * RSVD     65
+ * LSP      66    67 68 69 70 71 72 73 74 75
+ * CBSEED   76
+ *
+ *-------------------------------------------------------------------------*/
+
+typedef struct
+{
+    qcelp_packet_type type;
+    uint8_t data[76];       /* holds all data from a frame (_once_ parsed) */
+    uint8_t bits;
+} QCELPFrame;
+
+/*
+ * Position of the transmision codes inside the universal frame.
+ *
+ */
+
+#define QCELP_CBSIGN0_POS 0
+#define QCELP_CBGAIN0_POS 16
+#define QCELP_CINDEX0_POS 32
+#define QCELP_PLAG0_POS   48
+#define QCELP_PFRAC0_POS  52
+#define QCELP_PGAIN0_POS  56
+#define QCELP_LSPV0_POS   60
+#define QCELP_RSRVD_POS   65    /* on all but rate 1/2 packets */
+#define QCELP_LSP0_POS    66    /* only in rate 1/8 packets    */
+#define QCELP_CBSEED_POS  76    /* only in rate 1/8 packets    */
+
+/* rest its currently unused */
+
+static float qcelp_fullrate_ccodebook[]=
+{
+    0.10,-0.65,-0.59, 0.12, 1.10, 0.34,-1.34, 1.57,
+    1.04,-0.84,-0.34,-1.15, 0.23,-1.01, 0.03, 0.45,
+   -1.01,-0.16,-0.59, 0.28,-0.45, 1.34,-0.67, 0.22,
+    0.61,-0.29, 2.26,-0.26,-0.55,-1.79, 1.57,-0.51,
+   -2.20,-0.93,-0.37, 0.60, 1.18, 0.74,-0.48,-0.95,
+   -1.81, 1.11, 0.36,-0.52,-2.15, 0.78,-1.12, 0.39,
+   -0.17,-0.47,-2.23, 0.19, 0.12,-0.98,-1.42, 1.30,
+    0.54,-1.27, 0.21,-0.12, 0.39,-0.48, 0.12, 1.28,
+    0.06,-1.67, 0.82,-1.02,-0.79, 0.55,-0.44, 0.48,
+   -0.20,-0.53, 0.08,-0.61, 0.11,-0.70,-1.57,-1.68,
+    0.20,-0.56,-0.74, 0.78, 0.33,-0.63,-1.73,-0.02,
+   -0.75,-0.53,-1.46, 0.77, 0.66,-0.29, 0.09,-0.75,
+    0.65, 1.19,-0.43, 0.76, 2.33, 0.98, 1.25,-1.56,
+   -0.27, 0.78,-0.09, 1.70, 1.76, 1.43,-1.48,-0.07,
+    0.27,-1.36, 0.05, 0.27, 0.18, 1.39, 2.04, 0.07,
+   -1.84,-1.97, 0.52,-0.03, 0.78,-1.89, 0.08,-0.65
+};
+
+static float qcelp_halfrate_ccodebook[]=
+{
+    0.0, -2.0,  0.0, -1.5,  0.0,  0.0,  0.0,  0.0,
+    0.0,  0.0,  0.0,  0.0,  0.0,  0.0,  0.0,  0.0,
+    0.0, -1.5, -1.0,  0.0,  0.0,  0.0,  0.0,  0.0,
+    0.0,  0.0,  0.0,  0.0,  0.0,  0.0,  0.0,  2.5,
+    0.0,  0.0,  0.0,  0.0,  0.0,  0.0,  2.0,  0.0,
+    0.0,  1.5,  1.0,  0.0,  1.5,  2.0,  0.0,  0.0,
+    0.0,  0.0,  0.0,  0.0,  0.0,  0.0,  0.0,  0.0,
+    0.0,  0.0,  0.0,  0.0,  0.0,  1.5,  0.0,  0.0,
+   -1.5,  1.5,  0.0,  0.0, -1.0,  0.0,  1.5,  0.0,
+    0.0,  0.0,  0.0,  0.0,  0.0,  0.0, -2.5,  0.0,
+    0.0,  0.0,  0.0,  1.5,  0.0,  0.0,  0.0,  1.5,
+    0.0,  0.0,  0.0,  0.0,  0.0,  0.0,  0.0,  2.0,
+    0.0,  0.0,  0.0,  0.0,  0.0,  0.0,  0.0,  0.0,
+    0.0,  1.5,  3.0, -1.5, -2.0,  0.0, -1.5, -1.5,
+    1.5, -1.5,  0.0,  0.0,  0.0,  0.0,  0.0,  0.0,
+    0.0,  0.0,  0.0,  0.0,  0.0,  0.0,  0.0,  0.0
+};

Added: qcelp/qcelp_glue.diff
==============================================================================
--- (empty file)
+++ qcelp/qcelp_glue.diff	Tue Jul  3 22:16:49 2007
@@ -0,0 +1,48 @@
+Index: libavcodec/Makefile
+===================================================================
+--- libavcodec/Makefile	(revision 9314)
++++ libavcodec/Makefile	(working copy)
+@@ -147,6 +147,7 @@
+ OBJS-$(CONFIG_SHORTEN_DECODER)         += shorten.o golomb.o
+ OBJS-$(CONFIG_SMACKAUD_DECODER)        += smacker.o
+ OBJS-$(CONFIG_SMACKER_DECODER)         += smacker.o
++OBJS-$(CONFIG_QCELP_DECODER)           += qcelpdec.o
+ OBJS-$(CONFIG_SMC_DECODER)             += smc.o
+ OBJS-$(CONFIG_SNOW_DECODER)            += snow.o
+ OBJS-$(CONFIG_SNOW_ENCODER)            += snow.o
+Index: libavcodec/allcodecs.c
+===================================================================
+--- libavcodec/allcodecs.c	(revision 9314)
++++ libavcodec/allcodecs.c	(working copy)
+@@ -196,6 +196,7 @@
+     REGISTER_DECODER(RA_288, ra_288);
+     REGISTER_DECODER(SHORTEN, shorten);
+     REGISTER_DECODER(SMACKAUD, smackaud);
++    REGISTER_DECODER(QCELP, qcelp);
+     REGISTER_ENCDEC (SONIC, sonic);
+     REGISTER_ENCODER(SONIC_LS, sonic_ls);
+     REGISTER_DECODER(TRUESPEECH, truespeech);
+Index: libavcodec/allcodecs.h
+===================================================================
+--- libavcodec/allcodecs.h	(revision 9314)
++++ libavcodec/allcodecs.h	(working copy)
+@@ -161,6 +161,7 @@
+ extern AVCodec shorten_decoder;
+ extern AVCodec smackaud_decoder;
+ extern AVCodec smacker_decoder;
++extern AVCodec qcelp_decoder;
+ extern AVCodec smc_decoder;
+ extern AVCodec snow_decoder;
+ extern AVCodec sol_dpcm_decoder;
+Index: libavformat/mov.c
+===================================================================
+--- libavformat/mov.c	(revision 9314)
++++ libavformat/mov.c	(working copy)
+@@ -832,6 +832,7 @@
+         st->codec->sample_rate= 16000;
+         st->codec->channels= 1; /* really needed */
+         break;
++    case CODEC_ID_QCELP:
+     case CODEC_ID_AMR_NB:
+         st->codec->sample_rate= 8000;
+         st->codec->channels= 1; /* really needed */

Added: qcelp/qcelpdec.c
==============================================================================
--- (empty file)
+++ qcelp/qcelpdec.c	Tue Jul  3 22:16:49 2007
@@ -0,0 +1,235 @@
+/*
+ * QCELP Decoder
+ * Copyright (c) 2007 Reynaldo H. Verdejo Pinochet
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg 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.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg 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 FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+/**
+ * @file qcelpdec.c
+ * QCELP decoder.
+ */
+
+/* First we include some default includes */
+#include <math.h>
+#include <stddef.h>
+#include <stdio.h>
+
+/* The following includes have the bitstream reader, various dsp functions and the various defaults */
+#define ALT_BITSTREAM_READER
+#include "avcodec.h"
+#include "bitstream.h"
+#include "dsputil.h"
+
+#include "qcelp.h"
+
+#define DEBUG 1
+
+typedef struct {
+    GetBitContext gb;
+    QCELPFrame    *frame;
+    uint8_t       erasure_count;
+    uint8_t       ifq_count;
+} QCELPContext;
+
+static int qcelp_decode_init(AVCodecContext *avctx);
+static int qcelp_decode_frame(AVCodecContext *avctx, void *data,
+           int *data_size, uint8_t *buf, int buf_size);
+static int qcelp_decode_close(AVCodecContext *avctx);
+
+
+static int qcelp_decode_init(AVCodecContext *avctx)
+{
+    QCELPContext *q = (QCELPContext *) avctx->priv_data;
+
+    avctx->sample_rate = 8000;
+    avctx->channels = 1;
+
+    q->frame = av_mallocz(sizeof(QCELPFrame));
+
+
+    if(q->frame == NULL)
+        return -1;
+
+    return 0;
+}
+
+static int qcelp_parse_pkt_full(uint8_t *buf, QCELPFrame *frame)
+{
+    return 0;
+}
+
+static int qcelp_decode_frame(AVCodecContext *avctx, void *data,
+           int *data_size, uint8_t *buf, int buf_size)
+{
+    QCELPContext *q = avctx->priv_data;
+    int16_t *outbuffer = data;
+    int8_t samples;
+    int8_t bitcount;
+    int16_t first16 = 0; /* needed for rate 1/8 particularities */
+
+    QCELPBitmap *order;
+
+    order = NULL;
+
+    init_get_bits(&q->gb, buf, buf_size*8);
+
+    /*
+     * FIXME this comment should actually make some sence ..
+     *
+     * Here we try to identify each frame's rate by its byte size,
+     * then, after setting a few utility vars we point 'order'
+     * to start at the location of the rate's reference _slice_
+     * inside the big REFERECE_FRAME array. We then proceed with
+     * the bit reordering that will leave a full raw frame's data
+     * ordered in our 'universal frame'
+     */
+
+    switch(buf_size)
+    {
+        case 34:
+            q->frame->type = RATE_FULL;
+            q->frame->bits = qcelp_bits_per_type[RATE_FULL];
+            order = QCELP_REFERENCE_FRAME + QCELP_FULLPKT_REFERENCE_POS;
+            break;
+        case 16:
+            q->frame->type = RATE_HALF;
+            q->frame->bits = qcelp_bits_per_type[RATE_HALF];
+            order = QCELP_REFERENCE_FRAME + QCELP_HALFPKT_REFERENCE_POS;
+            break;
+        case 7:
+            q->frame->type = RATE_QUARTER;
+            q->frame->bits = qcelp_bits_per_type[RATE_QUARTER];
+            order = QCELP_REFERENCE_FRAME + QCELP_4THRPKT_REFERENCE_POS;
+            break;
+        case 3:
+            q->frame->type = RATE_OCTAVE;
+            q->frame->bits = qcelp_bits_per_type[RATE_OCTAVE];
+            order = QCELP_REFERENCE_FRAME + QCELP_8THRPKT_REFERENCE_POS;
+            break;
+        case 0: /* FIXME */
+            q->frame->type = BLANK;
+            q->frame->bits = 0;
+            break;
+        default:
+            q->frame->type = RATE_UNKNOWN;
+            q->frame->bits = 0;
+            printf("UNKNOWN PACKET RATE\n");
+            break;
+    }
+
+    /*
+     * reordering loop
+     */
+
+    bitcount=0;
+    while(bitcount < q->frame->bits)
+    {
+        /*
+         * order[bitcount]->index holds the placement of this
+         * input stream bit in the universal frame.
+         *
+         * order[bitcount]->pos holds the bit pos inside this value
+         * byte.
+         *
+         */
+
+        q->frame->data[ order[bitcount].index ] |=
+        get_bits1(&q->gb)>>(order[bitcount].bitpos);
+
+        /*
+         * viral sample! :D
+         *
+         * just needed for rate 1/8 packets
+         *
+         */
+
+        if(bitcount<16)
+        {
+            first16 |= q->frame->data[ order[bitcount].index ]>>bitcount
+        }
+
+        bitcount++;
+    }
+
+    /* DONE REORDERING */
+
+    /*
+     * check for erasures/blanks on rates 1, 1/4 and 1/8
+     *
+     */
+
+    if(q->frame->type != RATE_HALF)
+    {
+        if(!q->frame->data[QCELP_RSRVD_POS])
+        {
+            /*
+             * flag aproach: set flag for ifq/blank/incorrect
+             * decoding
+             */
+        }
+    }
+
+    /* particularities for rate 1/8 */
+    if(q->frame->type == RATE_OCTAVE)
+    {
+        if(first16==0xFFFF)
+        {
+            /*
+             * flag aproach: set flag for ifq/blank/incorrect
+             * decoding
+             */
+        }
+    }
+
+    /*
+     * check for badly received packets
+     * for rate 1, 1/2 and 1/4
+     */
+
+    if(q->frame->type != RATE_OCTAVE)
+    {
+        /*
+         * flag aproach: set flag for ifq/blank/incorrect
+         * decoding
+         */
+
+    }
+
+
+
+     /*
+      * decode loop
+      *
+      */
+
+
+
+
+    return 1;
+}
+
+AVCodec qcelp_decoder =
+{
+    .name = "qcelp",
+    .type = CODEC_TYPE_AUDIO,
+    .id = CODEC_ID_QCELP,
+    .priv_data_size = sizeof(QCELPContext),
+    .init = qcelp_decode_init,
+    .close = qcelp_decode_close,
+    .decode = qcelp_decode_frame,
+};

Added: qcelp/srcprepare.sh
==============================================================================
--- (empty file)
+++ qcelp/srcprepare.sh	Tue Jul  3 22:16:49 2007
@@ -0,0 +1,91 @@
+#############################################################################
+# QCELP Decoder / Source helper
+# Copyright (c) 2007 Reynaldo H. Verdejo Pinochet
+#
+# This file is part of FFmpeg.
+#
+# FFmpeg 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.1 of the License, or (at your option) any later version.
+#
+# FFmpeg 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 FFmpeg; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+#
+#
+#!/bin/bash
+
+RSYNC=`which rsync`
+PATCH=`which patch`
+
+function missing()
+{
+    echo ""
+    echo "You need patch and rsync somewhere in your PATH for this script"
+    echo "to work properly"
+    echo ""
+}
+
+function usage()
+{
+    echo ""
+    echo "Simple source preparation script for ffmpeg's qcelp decoder."
+    echo ""
+    echo "Usage:"
+    echo ""
+    echo "$0 PATH_TO_FFMPEG_REPO"
+    echo ""
+    echo "PATH_TO_FFMPEG_REPO should point to the dir containing ffmpeg's trunk"
+    echo ""
+}
+
+# Check usage
+
+if [ $# -lt 1 ]; then
+    usage
+    exit 1
+fi
+
+# Check needed
+for i in rsync patch; do
+    if [ -z "`which $i`" ]; then
+        echo "[ERROR] $i not found in $PATH!"
+        missing
+        exit 1
+    fi
+done
+
+RSYNC=`which rsync`
+PATCH=`which patch`
+
+echo -n "syncing FFmpeg sources from $1: "
+
+for i in `rsync -avz $1 .` ; do true  ; done
+
+if [ $? ]; then
+    echo "Finished"
+fi
+
+# copying files and patching sources
+echo ""
+echo "Copying needed files and patching synced sources: "
+
+cd trunk
+patch -p0 < ../qcelp_glue.diff
+cp ../qcelpdec.c libavcodec/
+cp ../qcelp.h libavcodec
+
+cd ..
+
+echo "Finished"
+echo ""
+echo "Patched source is in trunk dir. happy hacking"
+
+exit 0
+echo "



More information about the FFmpeg-soc mailing list