From dc6d69e64bf12e8205aa4d23c93d31f8c7d77d26 Mon Sep 17 00:00:00 2001 From: Jean-Marc Valin Date: Tue, 21 Dec 2010 01:04:11 -0500 Subject: [PATCH] Ordering Hadamard frequencies when increasing the time-resolution. This means we're "time-ordered" in all cases except when increasing the time resolution on frames that already use short blocks. There's no reordering when increasing the frequency resolution on short blocks. --- libcelt/bands.c | 64 ++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 50 insertions(+), 14 deletions(-) diff --git a/libcelt/bands.c b/libcelt/bands.c index d348b300..025cde1e 100644 --- a/libcelt/bands.c +++ b/libcelt/bands.c @@ -387,7 +387,18 @@ void measure_norm_mse(const CELTMode *m, float *X, float *X0, float *bandE, floa #endif -static void interleave_vector(celt_norm *X, int N0, int stride) +/* Indexing table for converting from natural Hadamard to ordery Hadamard + This is essentially a bit-reversed Gray, on top of which we've added + an inversion of the order because we want the DC at the end rather than + the beginning. The lines are for N=2, 4, 8, 16 */ +static const int ordery_table[] = { + 1, 0, + 3, 0, 2, 1, + 7, 0, 4, 3, 6, 1, 5, 2, + 15, 0, 8, 7, 12, 3, 11, 4, 14, 1, 9, 6, 13, 2, 10, 5, +}; + +static void deinterleave_hadamard(celt_norm *X, int N0, int stride, int hadamard) { int i,j; VARDECL(celt_norm, tmp); @@ -395,15 +406,25 @@ static void interleave_vector(celt_norm *X, int N0, int stride) SAVE_STACK; N = N0*stride; ALLOC(tmp, N, celt_norm); - for (i=0;i1) { if (encode) - deinterleave_vector(X, N_B, B0); + deinterleave_hadamard(X, N_B, B0, longBlocks); if (lowband) - deinterleave_vector(lowband, N_B, B0); + deinterleave_hadamard(lowband, N_B, B0, longBlocks); } } @@ -765,9 +797,13 @@ static void quant_band(int encode, const CELTMode *m, int i, celt_norm *X, celt_ int next_level=0; /* Give more bits to low-energy MDCTs than they would otherwise deserve */ - if (B>1 && !stereo && itheta > 8192) - delta -= delta>>(1+level); - + if (B>1 && !stereo) + { + if (itheta > 8192) + delta -= delta>>(4+level-LM); + else + delta -= delta>>(5+level-LM); + } mbits = (b-qalloc-delta)/2; if (mbits > b-qalloc) mbits = b-qalloc; @@ -866,7 +902,7 @@ static void quant_band(int encode, const CELTMode *m, int i, celt_norm *X, celt_ /* Undo the sample reorganization going from time order to frequency order */ if (B0>1) - interleave_vector(X, N_B, B0); + interleave_hadamard(X, N_B, B0, longBlocks); /* Undo time-freq changes that we did earlier */ N_B = N_B0;