[FFmpeg-devel] [PATCH] Implement DCT-I

Michael Niedermayer michaelni
Tue Mar 23 15:01:23 CET 2010


On Sun, Mar 21, 2010 at 12:41:45PM +0100, Vitor Sessak wrote:
> $subj, it is very likely to be useful to the Hilbert transform in the 
> wmavoice postfilter (a  Hilbert filter can be written as a DCT-I + DST-I). 
> The API changes should be backward compatible.
>
> -Vitor

>  avfft.c |    2 +-
>  avfft.h |    8 +++++++-
>  dct.c   |   41 +++++++++++++++++++++++++++++++++++------
>  fft.h   |    2 +-
>  4 files changed, 44 insertions(+), 9 deletions(-)
> ed47ac0f9eefa87df5a03641af1f9f1de1395ec4  dct_I.diff
> Index: libavcodec/avfft.c
> ===================================================================
> --- libavcodec/avfft.c	(revision 22567)
> +++ libavcodec/avfft.c	(working copy)
> @@ -116,7 +116,7 @@
>  
>  #if CONFIG_DCT
>  
> -DCTContext *av_dct_init(int nbits, int inverse)
> +DCTContext *av_dct_init(int nbits, enum DCTTransformType inverse)
>  {
>      DCTContext *s = av_malloc(sizeof(*s));
>  
> Index: libavcodec/avfft.h
> ===================================================================
> --- libavcodec/avfft.h	(revision 22567)
> +++ libavcodec/avfft.h	(working copy)
> @@ -77,12 +77,18 @@
>  
>  typedef struct DCTContext DCTContext;
>  
> +enum DCTTransformType {
> +    DCT_II = 0,
> +    DCT_III,
> +    DCT_I,
> +};
> +
>  /**
>   * Set up (Inverse)DCT.
>   * @param nbits           log2 of the length of the input array
>   * @param inverse         >0 forward transform, <0 inverse transform
>   */
> -DCTContext *av_dct_init(int nbits, int inverse);
> +DCTContext *av_dct_init(int nbits, enum DCTTransformType type);
>  void av_dct_calc(DCTContext *s, FFTSample *data);
>  void av_dct_end (DCTContext *s);
>  
> Index: libavcodec/fft.h
> ===================================================================
> --- libavcodec/fft.h	(revision 22619)
> +++ libavcodec/fft.h	(working copy)
> @@ -228,7 +228,7 @@
>   * @param nbits           log2 of the length of the input array
>   * @param inverse         >0 forward transform, <0 inverse transform
>   */
> -int  ff_dct_init(DCTContext *s, int nbits, int inverse);
> +int  ff_dct_init(DCTContext *s, int nbits, enum DCTTransformType type);
>  void ff_dct_calc(DCTContext *s, FFTSample *data);
>  void ff_dct_end (DCTContext *s);
>  
> Index: libavcodec/dct.c
> ===================================================================
> --- libavcodec/dct.c	(revision 22619)
> +++ libavcodec/dct.c	(working copy)
> @@ -37,6 +37,35 @@
>  /* cos((M_PI * x / (2*n)) */
>  #define COS(s,n,x) (s->costab[x])
>  
> +static void ff_dct_calc_I_c(DCTContext *ctx, FFTSample *data)
> +{
> +    int n = 1 << ctx->nbits;
> +    int i;
> +    float next = -0.5f * (data[0] + data[n]);

data[n]
is that not out of the array?


> +    float tmp;
> +
> +    for(i = 0; i < n/2; i++) {
> +        float tmp1 = data[i    ];
> +        float tmp2 = data[n - i];
> +        float s = SIN(ctx, n, 2*i);
> +
> +        next += tmp1 * COS(ctx, n, 2*i);
> +        next -= tmp2 * COS(ctx, n, 2*(n-i));

is COS(ctx, n, 2*i) == -COS(ctx, n, 2*(n-i))
?

if yes, where is this algorithm from?


[...]
-- 
Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

Opposition brings concord. Out of discord comes the fairest harmony.
-- Heraclitus
-------------- 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/20100323/afa0bf96/attachment.pgp>



More information about the ffmpeg-devel mailing list