[Flake-enc-svnlog] SF.net SVN: flake-enc:[246] libflake
Status: Beta
Brought to you by:
jbr79
|
From: <jb...@us...> - 2009-05-20 00:44:37
|
Revision: 246
http://flake-enc.svn.sourceforge.net/flake-enc/?rev=246&view=rev
Author: jbr79
Date: 2009-05-20 00:44:29 +0000 (Wed, 20 May 2009)
Log Message:
-----------
add support for shifting out wasted low-order bits
Modified Paths:
--------------
libflake/encode.c
libflake/encode.h
Modified: libflake/encode.c
===================================================================
--- libflake/encode.c 2009-05-19 23:43:18 UTC (rev 245)
+++ libflake/encode.c 2009-05-20 00:44:29 UTC (rev 246)
@@ -526,6 +526,7 @@
// initialize output bps for each channel
for(ch=0; ch<ctx->channels; ch++) {
frame->subframes[ch].obits = ctx->bps;
+ frame->subframes[ch].wasted_bits = 0;
}
return 0;
@@ -549,6 +550,46 @@
}
/**
+ * Shift out any zero bits and set the wasted_bits parameter.
+ */
+static void
+remove_wasted_bits(FlacEncodeContext *ctx)
+{
+ int i, ch, b;
+ int wasted;
+ FlacFrame *frame;
+ int32_t *samples;
+
+ frame = &ctx->frame;
+ for (ch = 0; ch < ctx->channels; ch++) {
+ wasted = ctx->bps-1;
+ samples = frame->subframes[ch].samples;
+ for (i = 0; i < frame->blocksize; i++) {
+ int32_t s = samples[i];
+ uint32_t mask = 0x1;
+ for (b = 0; b <= wasted; b++) {
+ if (s & mask)
+ break;
+ mask <<= 1;
+ }
+ if (b < wasted)
+ wasted = b;
+ if (!wasted)
+ break;
+ }
+ if (wasted == ctx->bps-1) {
+ wasted = 0;
+ } else if (wasted) {
+ for (i = 0; i < frame->blocksize; i++) {
+ samples[i] >>= wasted;
+ }
+ frame->subframes[ch].obits -= wasted;
+ }
+ frame->subframes[ch].wasted_bits = wasted;
+ }
+}
+
+/**
* Estimate the best stereo decorrelation mode
*/
static int
@@ -838,7 +879,13 @@
// subframe header
bitwriter_writebits(ctx->bw, 1, 0);
bitwriter_writebits(ctx->bw, 6, frame->subframes[ch].type_code);
- bitwriter_writebits(ctx->bw, 1, 0);
+ if (frame->subframes[ch].wasted_bits) {
+ bitwriter_writebits(ctx->bw, 1, 1);
+ bitwriter_writebits(ctx->bw, frame->subframes[ch].wasted_bits-1, 0);
+ bitwriter_writebits(ctx->bw, 1, 1);
+ } else {
+ bitwriter_writebits(ctx->bw, 1, 0);
+ }
// subframe
switch(frame->subframes[ch].type) {
@@ -883,6 +930,8 @@
channel_decorrelation(ctx);
+ remove_wasted_bits(ctx);
+
for(ch=0; ch<ctx->channels; ch++) {
if(encode_residual(ctx, ch) < 0) {
return -1;
Modified: libflake/encode.h
===================================================================
--- libflake/encode.h 2009-05-19 23:43:18 UTC (rev 245)
+++ libflake/encode.h 2009-05-20 00:44:29 UTC (rev 246)
@@ -52,6 +52,7 @@
typedef struct FlacSubframe {
int type;
int type_code;
+ int wasted_bits;
int order;
int obits;
int32_t coefs[MAX_LPC_ORDER];
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|