[Ffmpeg-devel] [RFC] mdct window generation
Michael Niedermayer
michaelni
Sat Jul 8 17:57:01 CEST 2006
Hi
On Sat, Jul 08, 2006 at 04:38:16PM +0200, Benjamin Larsson wrote:
> With the upcoming ffmpeg native aac and ac3 codecs something like this
> is needed to prevent code duplication. Currently each codec generate
> it's own mdct window, with more audio codecs being added it would be
> nice to have something like this patch. Note that the code in this patch
> isn't correct and that the code to use this in wma, vorbis and cook is
> missing.
[...]
> +/**
> + * Generate a Kaiser Window.
> + */
> +static void k_window_init(int alpha, float *window, int n, int iterations)
> +{
> + int j, k;
> + float a, x;
> + a = alpha * M_PI / n;
> + a = a*a;
> + for(k=0; k<n; k++) {
> + x = k * (n - k) * a;
> + window[k] = 1.0;
> + for(j=iterations; j>0; j--) {
> + window[k] = (window[k] * x / (j*j)) + 1.0;
> + }
> + }
> +}
> +
> +/**
> + * Generate a Kaiser-Bessel Derived Window.
> + * @param alpha determines window shape
> + * @param window array to fill with window values
> + * @param n length of the window
> + * @param iter number of iterations to use in BesselI0
> + */
> +static void kbd_window_init(int alpha, float *window, int n, int iterations)
> +{
> + int k, n2;
> + float *kwindow;
> +
> + n2 = n >> 1;
> + kwindow = &window[n2];
> + k_window_init(alpha, kwindow, n2, iterations);
> + window[0] = kwindow[0];
> + for(k=1; k<n2; k++) {
> + window[k] = window[k-1] + kwindow[k];
> + }
> + for(k=0; k<n2; k++) {
> + window[k] = sqrt(window[k] / (window[n2-1]+1));
> + window[n-1-k] = window[k];
> + }
> +}
> +
> +/**
> + * Generate a MDCT window.
> + * @param window_type one of the diffrent
> + * @param window array to fill with window values
> + * @param size length of the window
> + * @param kbd_alpha optional argument, used for KBD windows
> + */
> +
> +void ff_generate_mdct_window(enum MDCT_window window_type, float* window, int size, int kbd_alpha) {
> + int i;
> + float alpha;
> +
> + switch(window_type) {
> + case SINE:
> + alpha = M_PI / (2.0 * (float)size);
> + for(i=0 ; i<size ; i++)
> + window[i] = sin((i + 512.0/(float)size) * alpha);
> + break;
> + case KBD:
> + kbd_window_init(kbd_alpha, window, size, 50);
> + break;
> + case VORBIS:
> + for(i=0 ; i<size ; i++)
> + window[i]=sin(0.5*M_PI*(sin(((float)i+0.5)/(float)size*M_PI))*(sin(((float)i+0.5)/(float)size*M_PI)));
> + break;
> + }
> +}
is there _anything_ shared between the 3 cases? if no then IMO they should
be 3 seperate functions
furthermore, the code to generate a window MUST be smaller then the
window of course, otherwise its just wasting space
[...]
--
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB
In the past you could go to a library and read, borrow or copy any book
Today you'd get arrested for mere telling someone where the library is
More information about the ffmpeg-devel
mailing list