[Ffmpeg-devel] [PATCH] flacenc - lpc and options
Michael Niedermayer
michaelni
Fri Jun 30 19:05:00 CEST 2006
Hi
On Fri, Jun 30, 2006 at 01:40:48AM -0400, Justin Ruggles wrote:
[...]
> 2) added 8 compression options to AVCodecContext which are used by the
> encoder. most of them are set to -1 by default, which indicates for the
> encoder to use its default setting. this is so that other codecs can
> reuse these fields if they wish, and can have different default values.
>
> 3) modified flacenc.c to first check for the compression_level and set
> all the options based on that value, then read the other AVCodecContext
> values and override the defaults if they are explicitly set by the user.
>
> If any of this should be changed, let me know. Michael's idea of a
> 'preset' field in AVCodecContext would work, but it was unnecessary in
> this case. I guess it could still be added for shortcuts like "best" or
> "fast".
>
> Since I have not yet added any more extensive order search options, the
> compression level only goes from 0 to 5 for now. Below are the results
> of a few tests comparing ffmpeg to the reference encoder. The faster
> decode times for the ffmpeg-generated files are mostly due to the fact
> that MD5 sums are not implemented yet, so the decoder doesn't do any
> verification.
[...]
> + if(avctx->min_prediction_order >= 0) {
> + if(s->options.use_lpc) {
> + if(avctx->min_prediction_order == 0 ||
> + avctx->min_prediction_order > 32) {
this could be MAX_LPC_ORDER
[...]
> +/**
> + * Apply Welch window function to audio block
> + */
> +static void apply_welch_window(const int32_t *data, int len, double *w_data)
> +{
> + int i, n2;
> + double w;
> + double c;
> +
> + n2 = (len >> 1);
> + c = 2.0 / (len - 1.0);
> + for(i=0; i<n2; i++) {
> + w = c - i - 1.0;
> + w = 1.0 - (w * w);
> + w_data[i] = data[i] * w;
> + w_data[len-1-i] = data[len-1-i] * w;
> + }
> +}
> +
> +static double *welch_window;
> +static int window_size;
> +
> +static void window_init(int size)
> +{
> + int i, n2;
> + double w;
> + double c;
> +
> + window_size = size;
> + welch_window = av_malloc(size * sizeof(double));
> +
> + n2 = (size >> 1);
> + c = 2.0 / (size - 1.0);
> + for(i=0; i<n2; i++) {
> + w = c - i - 1.0;
there are tabs in the line above
the code is duplicated from apply_welch_window
and this is not thread safe, window_size, ... are non constant static
variables
[...]
> +
> +/**
> + * Levinson-Durbin recursion.
> + * Produces LPC coefficients from autocorrelation data.
> + */
> +static void compute_lpc_coefs(const double *autoc, int max_order,
> + double lpc[][MAX_LPC_ORDER], double *ref)
> +{
> + int i, j, i2;
> + double r, err, tmp;
> + double lpc_tmp[MAX_LPC_ORDER];
> +
> + for(i=0; i<max_order; i++) lpc_tmp[i] = 0;
> + err = autoc[0];
> +
> + for(i=0; i<max_order; i++) {
> + r = -autoc[i+1];
> + for(j=0; j<i; j++) {
> + r -= lpc_tmp[j] * autoc[i-j];
> + }
> + r /= err;
> + ref[i] = fabs(r);
> +
> + err *= 1.0 - (r * r);
> +
> + i2 = (i >> 1);
> + lpc_tmp[i] = r;
> + for(j=0; j<i2; j++) {
> + tmp = lpc_tmp[j];
> + lpc_tmp[j] += r * lpc_tmp[i-1-j];
> + lpc_tmp[i-1-j] += r * tmp;
> + }
> + if(i % 2) {
i&1 is faster then i%2
[...]
> + for(i=0; i<sub->order; i++) {
> + sub->coefs[i] = coefs[sub->order-1][i];
> }
> - return bits[sub->order];
> + porder = get_max_p_order(max_porder, n, sub->order);
> + encode_residual_lpc(res, smp, n, sub->order, sub->coefs, sub->shift);
hmm, coeffs is copied into sub->coefs and then used, why isnt it used withot
copying?
[...]
> + /**
> + * sets audio frame size using frame duration in milliseconds
> + * - encoding: set by user.
> + * - decoding: unused.
> + */
> + int block_time_ms;
iam a little unsure about this, maybe you could leave this one out for now
and set it just based on compression_level
[...]
--
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