[FFmpeg-devel] [PATCH] Implement DCT-I
Michael Niedermayer
michaelni
Tue Mar 23 17:58:05 CET 2010
On Tue, Mar 23, 2010 at 04:52:57PM +0100, Vitor Sessak wrote:
> 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).
good, then it should be optimal
>
> New patch with decent documentation and a discrete sine transform
> implementation.
>
> -Vitor
> avfft.c | 2 -
> avfft.h | 18 +++++++++++----
> dct.c | 75 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++------
> fft.h | 11 +++++----
> 4 files changed, 90 insertions(+), 16 deletions(-)
> 9b3d54b931800a2c439479490d7efd648847cd1d dct_dst.diff
patch should be ok if tested
[...]
--
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB
Awnsering whenever a program halts or runs forever is
On a turing machine, in general impossible (turings halting problem).
On any real computer, always possible as a real computer has a finite number
of states N, and will either halt in less than N cycles or never halt.
-------------- 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/1b108824/attachment.pgp>
More information about the ffmpeg-devel
mailing list