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

Vitor Sessak vitor1001
Tue Mar 23 16:52:57 CET 2010


Michael Niedermayer wrote:
> 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?

No, it is just that I forgot to mention in the doxy that DCT-I needs an 
array 1 element longer.

>> +    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))
> ?

yes

> if yes, where is this algorithm from?

Numerical recipes (the text, not the unreadable fortran-born mess).

New patch with decent documentation and a discrete sine transform 
implementation.

-Vitor
-------------- next part --------------
A non-text attachment was scrubbed...
Name: dct_dst.diff
Type: text/x-patch
Size: 4854 bytes
Desc: not available
URL: <http://lists.mplayerhq.hu/pipermail/ffmpeg-devel/attachments/20100323/6608d06e/attachment.bin>



More information about the ffmpeg-devel mailing list