From cf0f2642f415bfacdc89698ab9ebad0126e55fe4 Mon Sep 17 00:00:00 2001 From: Oded Shimon Date: Mon, 2 Oct 2006 06:07:49 +0000 Subject: [PATCH] Original Commit: r61 | ods15 | 2006-09-25 13:10:56 +0300 (Mon, 25 Sep 2006) | 2 lines step 2, floor_fit, decides on the values to be encoded Originally committed as revision 6466 to svn://svn.ffmpeg.org/ffmpeg/trunk --- libavcodec/vorbis_enc.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/libavcodec/vorbis_enc.c b/libavcodec/vorbis_enc.c index 65ca68f5c7..66ffeec10b 100644 --- a/libavcodec/vorbis_enc.c +++ b/libavcodec/vorbis_enc.c @@ -643,6 +643,27 @@ static int put_main_header(venc_context_t * venc, uint8_t ** out) { return p - *out; } +static void floor_fit(venc_context_t * venc, floor_t * fc, float * coeffs, int * posts, int samples) { + int range = 255 / fc->multiplier + 1; + int i; + for (i = 0; i < fc->values; i++) { + int position = fc->list[fc->list[i].sort].x; + int begin = fc->list[fc->list[FFMAX(i-1, 0)].sort].x; + int end = fc->list[fc->list[FFMIN(i+1, fc->values - 1)].sort].x; + int j; + float average = 0; + begin = (position + begin) / 2; + end = (position + end ) / 2; + + assert(end <= samples); + for (j = begin; j < end; j++) average += fabs(coeffs[j]); + average /= end - begin; + average /= 64; // MAGIC! + for (j = 0; j < range; j++) if (floor1_inverse_db_table[j * fc->multiplier] > average) break; + posts[fc->list[i].sort] = j; + } +} + static void floor_encode(venc_context_t * venc, floor_t * fc, PutBitContext * pb, float * floor, int samples) { int range = 255 / fc->multiplier + 1; int j; @@ -805,6 +826,7 @@ static int vorbis_encode_frame(AVCodecContext * avccontext, unsigned char * pack int i; if (!window(venc, audio, samples)) return 0; + samples = 1 << (venc->blocksize[0] - 1); init_put_bits(&pb, packets, buf_size); @@ -821,6 +843,8 @@ static int vorbis_encode_frame(AVCodecContext * avccontext, unsigned char * pack for (i = 0; i < venc->channels; i++) { floor_t * fc = &venc->floors[mapping->floor[mapping->mux[i]]]; + int posts[fc->values]; + floor_fit(venc, fc, &venc->coeffs[i * samples], posts, samples); floor_encode(venc, fc, &pb, &venc->floor[i * samples], samples); }