Commit 2c52ee9b authored by jbr's avatar jbr

share channel mode constants between the FLAC decoder and FLAC encoder


git-svn-id: file:///var/local/repositories/ffmpeg/trunk@18082 9553f0bf-9b14-0410-a0b8-cfaf0461ba5b
parent 1f6c472b
...@@ -34,6 +34,13 @@ ...@@ -34,6 +34,13 @@
#define FLAC_MIN_BLOCKSIZE 16 #define FLAC_MIN_BLOCKSIZE 16
#define FLAC_MAX_BLOCKSIZE 65535 #define FLAC_MAX_BLOCKSIZE 65535
enum {
FLAC_CHMODE_INDEPENDENT = 0,
FLAC_CHMODE_LEFT_SIDE = 8,
FLAC_CHMODE_RIGHT_SIDE = 9,
FLAC_CHMODE_MID_SIDE = 10,
};
enum { enum {
FLAC_METADATA_TYPE_STREAMINFO = 0, FLAC_METADATA_TYPE_STREAMINFO = 0,
FLAC_METADATA_TYPE_PADDING, FLAC_METADATA_TYPE_PADDING,
......
...@@ -46,13 +46,6 @@ ...@@ -46,13 +46,6 @@
#undef NDEBUG #undef NDEBUG
#include <assert.h> #include <assert.h>
enum decorrelation_type {
INDEPENDENT,
LEFT_SIDE,
RIGHT_SIDE,
MID_SIDE,
};
typedef struct FLACContext { typedef struct FLACContext {
FLACSTREAMINFO FLACSTREAMINFO
...@@ -63,7 +56,7 @@ typedef struct FLACContext { ...@@ -63,7 +56,7 @@ typedef struct FLACContext {
int curr_bps; ///< bps for current subframe, adjusted for channel correlation and wasted bits int curr_bps; ///< bps for current subframe, adjusted for channel correlation and wasted bits
int sample_shift; ///< shift required to make output samples 16-bit or 32-bit int sample_shift; ///< shift required to make output samples 16-bit or 32-bit
int is32; ///< flag to indicate if output should be 32-bit instead of 16-bit int is32; ///< flag to indicate if output should be 32-bit instead of 16-bit
enum decorrelation_type decorrelation; ///< channel decorrelation type in the current frame int decorrelation; ///< channel decorrelation type in the current frame
int got_streaminfo; ///< indicates if the STREAMINFO has been read int got_streaminfo; ///< indicates if the STREAMINFO has been read
int32_t *decoded[FLAC_MAX_CHANNELS]; ///< decoded samples int32_t *decoded[FLAC_MAX_CHANNELS]; ///< decoded samples
...@@ -445,10 +438,10 @@ static inline int decode_subframe(FLACContext *s, int channel) ...@@ -445,10 +438,10 @@ static inline int decode_subframe(FLACContext *s, int channel)
s->curr_bps = s->bps; s->curr_bps = s->bps;
if (channel == 0) { if (channel == 0) {
if (s->decorrelation == RIGHT_SIDE) if (s->decorrelation == FLAC_CHMODE_RIGHT_SIDE)
s->curr_bps++; s->curr_bps++;
} else { } else {
if (s->decorrelation == LEFT_SIDE || s->decorrelation == MID_SIDE) if (s->decorrelation == FLAC_CHMODE_LEFT_SIDE || s->decorrelation == FLAC_CHMODE_MID_SIDE)
s->curr_bps++; s->curr_bps++;
} }
...@@ -508,9 +501,9 @@ static int decode_frame(FLACContext *s, int alloc_data_size) ...@@ -508,9 +501,9 @@ static int decode_frame(FLACContext *s, int alloc_data_size)
assignment = get_bits(&s->gb, 4); /* channel assignment */ assignment = get_bits(&s->gb, 4); /* channel assignment */
if (assignment < FLAC_MAX_CHANNELS && s->channels == assignment+1) if (assignment < FLAC_MAX_CHANNELS && s->channels == assignment+1)
decorrelation = INDEPENDENT; decorrelation = FLAC_CHMODE_INDEPENDENT;
else if (assignment >= FLAC_MAX_CHANNELS && assignment < 11 && s->channels == 2) else if (assignment >= FLAC_MAX_CHANNELS && assignment < 11 && s->channels == 2)
decorrelation = LEFT_SIDE + assignment - 8; decorrelation = assignment;
else { else {
av_log(s->avctx, AV_LOG_ERROR, "unsupported channel assignment %d (channels=%d)\n", av_log(s->avctx, AV_LOG_ERROR, "unsupported channel assignment %d (channels=%d)\n",
assignment, s->channels); assignment, s->channels);
...@@ -710,7 +703,7 @@ static int flac_decode_frame(AVCodecContext *avctx, ...@@ -710,7 +703,7 @@ static int flac_decode_frame(AVCodecContext *avctx,
break; break;
switch (s->decorrelation) { switch (s->decorrelation) {
case INDEPENDENT: case FLAC_CHMODE_INDEPENDENT:
for (j = 0; j < s->blocksize; j++) { for (j = 0; j < s->blocksize; j++) {
for (i = 0; i < s->channels; i++) { for (i = 0; i < s->channels; i++) {
if (s->is32) if (s->is32)
...@@ -720,11 +713,11 @@ static int flac_decode_frame(AVCodecContext *avctx, ...@@ -720,11 +713,11 @@ static int flac_decode_frame(AVCodecContext *avctx,
} }
} }
break; break;
case LEFT_SIDE: case FLAC_CHMODE_LEFT_SIDE:
DECORRELATE(a,a-b) DECORRELATE(a,a-b)
case RIGHT_SIDE: case FLAC_CHMODE_RIGHT_SIDE:
DECORRELATE(a+b,b) DECORRELATE(a+b,b)
case MID_SIDE: case FLAC_CHMODE_MID_SIDE:
DECORRELATE( (a-=b>>1) + b, a) DECORRELATE( (a-=b>>1) + b, a)
} }
......
...@@ -34,12 +34,6 @@ ...@@ -34,12 +34,6 @@
#define FLAC_SUBFRAME_FIXED 8 #define FLAC_SUBFRAME_FIXED 8
#define FLAC_SUBFRAME_LPC 32 #define FLAC_SUBFRAME_LPC 32
#define FLAC_CHMODE_NOT_STEREO 0
#define FLAC_CHMODE_LEFT_RIGHT 1
#define FLAC_CHMODE_LEFT_SIDE 8
#define FLAC_CHMODE_RIGHT_SIDE 9
#define FLAC_CHMODE_MID_SIDE 10
#define MAX_FIXED_ORDER 4 #define MAX_FIXED_ORDER 4
#define MAX_PARTITION_ORDER 8 #define MAX_PARTITION_ORDER 8
#define MAX_PARTITIONS (1 << MAX_PARTITION_ORDER) #define MAX_PARTITIONS (1 << MAX_PARTITION_ORDER)
...@@ -1006,7 +1000,7 @@ static int estimate_stereo_mode(int32_t *left_ch, int32_t *right_ch, int n) ...@@ -1006,7 +1000,7 @@ static int estimate_stereo_mode(int32_t *left_ch, int32_t *right_ch, int n)
} }
} }
if(best == 0) { if(best == 0) {
return FLAC_CHMODE_LEFT_RIGHT; return FLAC_CHMODE_INDEPENDENT;
} else if(best == 1) { } else if(best == 1) {
return FLAC_CHMODE_LEFT_SIDE; return FLAC_CHMODE_LEFT_SIDE;
} else if(best == 2) { } else if(best == 2) {
...@@ -1031,14 +1025,14 @@ static void channel_decorrelation(FlacEncodeContext *ctx) ...@@ -1031,14 +1025,14 @@ static void channel_decorrelation(FlacEncodeContext *ctx)
right = frame->subframes[1].samples; right = frame->subframes[1].samples;
if(ctx->channels != 2) { if(ctx->channels != 2) {
frame->ch_mode = FLAC_CHMODE_NOT_STEREO; frame->ch_mode = FLAC_CHMODE_INDEPENDENT;
return; return;
} }
frame->ch_mode = estimate_stereo_mode(left, right, n); frame->ch_mode = estimate_stereo_mode(left, right, n);
/* perform decorrelation and adjust bits-per-sample */ /* perform decorrelation and adjust bits-per-sample */
if(frame->ch_mode == FLAC_CHMODE_LEFT_RIGHT) { if(frame->ch_mode == FLAC_CHMODE_INDEPENDENT) {
return; return;
} }
if(frame->ch_mode == FLAC_CHMODE_MID_SIDE) { if(frame->ch_mode == FLAC_CHMODE_MID_SIDE) {
...@@ -1078,7 +1072,7 @@ static void output_frame_header(FlacEncodeContext *s) ...@@ -1078,7 +1072,7 @@ static void output_frame_header(FlacEncodeContext *s)
put_bits(&s->pb, 16, 0xFFF8); put_bits(&s->pb, 16, 0xFFF8);
put_bits(&s->pb, 4, frame->bs_code[0]); put_bits(&s->pb, 4, frame->bs_code[0]);
put_bits(&s->pb, 4, s->sr_code[0]); put_bits(&s->pb, 4, s->sr_code[0]);
if(frame->ch_mode == FLAC_CHMODE_NOT_STEREO) { if(frame->ch_mode == FLAC_CHMODE_INDEPENDENT) {
put_bits(&s->pb, 4, s->ch_code); put_bits(&s->pb, 4, s->ch_code);
} else { } else {
put_bits(&s->pb, 4, frame->ch_mode); put_bits(&s->pb, 4, frame->ch_mode);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment