[FFmpeg-devel] [PATCH] QCELP decoder

Michael Niedermayer michaelni
Thu Oct 30 19:49:49 CET 2008


On Tue, Oct 28, 2008 at 04:26:36PM -0700, Kenan Gillet wrote:
> On Oct 24, 2008, at 6:00 PM, Michael Niedermayer wrote:
> 
> > On Fri, Oct 17, 2008 at 09:46:31AM -0700, Kenan Gillet wrote:
[...]
> > [...]
> >> Index: libavcodec/qcelp_lsp.c
> >> ===================================================================
> >> --- libavcodec/qcelp_lsp.c	(revision 0)
> >> +++ libavcodec/qcelp_lsp.c	(revision 0)
> >> @@ -0,0 +1,98 @@
> >> +/*
> >> + * 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_lsp.c
> >> + * QCELP decoder
> >> + * @author Reynaldo H. Verdejo Pinochet
> >> + */
> >> +
> >> +#include <math.h>
> >> +#include <string.h>
> >> +
> >> +#include "dsputil.h"
> >> +
> >> +/**
> >> + * Linear convolution of two vectors v1 and [1, cos, 1]
> >> + *
> >> + * @param v_out the result of the convolution,
> >> + *              needs to be able to hold v_in_len + 2 elements
> >> + * @param v_in the input vector
> >> + * @param cos
> >> + * @param v_in_len the dimension of v_in assumed to be in   
> >> {2,4,6,8,10}
> >> + */
> >> +static void convolve(float *v_out, const float *v_in, const float  
> >> cos, const int v_in_len) {
> >> +    int   i;
> >> +
> >> +    v_out[0] = v_in[0];
> >> +    v_out[1] = v_in[1] + v_in[0] * cos;
> >> +    for (i = 2; i < v_in_len; i++) {
> >> +        v_out[i] = v_in[i]
> >> +                 + v_in[i - 1] * cos
> >> +                 + v_in[i - 2];
> >> +    }
> >> +    v_out[v_in_len    ] = v_in[v_in_len - 1] * cos + v_in[v_in_len  
> >> - 2];
> >> +    v_out[v_in_len + 1] = v_in[v_in_len - 1];
> >> +}
> >> +
> >> +/**
> >> + * Computes the Pa and Qa coefficients needed for LSP to LPC  
> >> conversion.
> >> + *
> >> + * TIA/EIA/IS-733 2.4.3.3.5-1/2
> >> + */
> >> +static void lsp2poly(float *poly, const float *lspf, float *v_in,  
> >> float *v_buf, const int odd) {
> >> +    int   i;
> >> +    float *v1 = v_in, *v2 = v_buf;
> >> +
> >> +    for (i = 0; i < 10; i += 2) {
> >> +        convolve(v2, v1, -2 * cos(M_PI * lspf[i + odd]), i + 2);
> >> +        FFSWAP(float *, v1, v2);
> >> +    }
> >> +    memcpy(poly, v1 + 1, 5 * sizeof(float));
> >> +}
> >> +
> >> +/**
> >> + * Reconstructs LPC coefficients from the line spectral pair  
> >> frequencies.
> >> + *
> >> + * TIA/EIA/IS-733 2.4.3.3.5
> >> + */
> >> +void qcelp_lspf2lpc(const float *lspf, float *lpc) {
> >> +    float pa[5],qa[5];
> >> +    float v1[12], v2[12];
> >> +    float beta = 0.9883;
> >> +    int   i;
> >> +
> >> +    v1[0] = 0.5;
> >> +    v1[1] = 0.5;
> >> +    lsp2poly(pa, lspf, v1, v2, 0);
> >> +
> >> +    v1[0] =  0.5;
> >> +    v1[1] = -0.5;
> >> +    lsp2poly(qa, lspf, v1, v2, 1);
> >> +
> >> +    for (i = 0; i < 5; i++) {
> >> +        lpc[i] = -(pa[i] + qa[i]) * beta;
> >> +        beta *= 0.9883;
> >> +    }
> >> +    for (i = 5; i < 10; i++) {
> >> +        lpc[i] = -(pa[9-i] - qa[9-i]) * beta;
> >> +        beta *= 0.9883;
> >> +    }
> >> +}
> >
> > we have some float lsp code in ffmpeg already (in wma&vorbis), i would
> > prefer to avoid adding more duplicated code.
> > If there are problems with merging the different implementations  
> > then this
> > should be discussed, maybe there is a problem that would leave us
> > no choice than adding this but until such problem is found this is  
> > not good.
> 
> After looking at the vorbis code, and the vorbis specification, at
> http://www.xiph.org/vorbis/doc/Vorbis_I_spec.html#vorbis-spec-floor0-synth
> and comparing it to the QCELP specification (TIA/EIA/IS-733 2.4.3.3.5),
> I don't see any way of merging the vorbis/wma code with the qcelp code.
> But again I am no audio guru, and any help would be appreciated to  
> confirm.
> 
> I've reworked the qcelp_lsp.c though to extract a more general  
> convolve function.

Well at least this should be optimized so it does not multiply by 1 and
does not do calculations twice due to symmetries.

[...]

-- 
Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

No snowflake in an avalanche ever feels responsible. -- Voltaire
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
URL: <http://lists.mplayerhq.hu/pipermail/ffmpeg-devel/attachments/20081030/938287d0/attachment.pgp>



More information about the ffmpeg-devel mailing list