add -M (force_mid_side) option
authorJosh Coalson <jcoalson@users.sourceforce.net>
Wed, 24 Jan 2001 01:01:04 +0000 (01:01 +0000)
committerJosh Coalson <jcoalson@users.sourceforce.net>
Wed, 24 Jan 2001 01:01:04 +0000 (01:01 +0000)
src/flac/encode.c
src/flac/encode.h
src/flac/main.c

index 148962f..3eb544e 100644 (file)
@@ -81,7 +81,7 @@ static int32 *input[FLAC__MAX_CHANNELS];
 
 /* local routines */
 static bool init(encoder_wrapper_struct *encoder_wrapper);
-static bool init_encoder(bool lax, bool do_mid_side, bool do_exhaustive_model_search, bool do_qlp_coeff_prec_search, unsigned rice_optimization_level, unsigned max_lpc_order, unsigned blocksize, unsigned qlp_coeff_precision, unsigned channels, unsigned bps, unsigned sample_rate, encoder_wrapper_struct *encoder_wrapper);
+static bool init_encoder(bool lax, bool do_mid_side, bool force_mid_side, bool do_exhaustive_model_search, bool do_qlp_coeff_prec_search, unsigned rice_optimization_level, unsigned max_lpc_order, unsigned blocksize, unsigned qlp_coeff_precision, unsigned channels, unsigned bps, unsigned sample_rate, encoder_wrapper_struct *encoder_wrapper);
 static void format_input(unsigned wide_samples, bool is_big_endian, bool is_unsigned_samples, unsigned channels, unsigned bps, encoder_wrapper_struct *encoder_wrapper);
 static FLAC__EncoderWriteStatus write_callback(const FLAC__Encoder *encoder, const byte buffer[], unsigned bytes, unsigned samples, unsigned current_frame, void *client_data);
 static void metadata_callback(const FLAC__Encoder *encoder, const FLAC__StreamMetaData *metadata, void *client_data);
@@ -93,7 +93,7 @@ static void print_stats(const encoder_wrapper_struct *encoder_wrapper);
 static bool read_little_endian_uint16(FILE *f, uint16 *val, bool eof_ok);
 static bool read_little_endian_uint32(FILE *f, uint32 *val, bool eof_ok);
 
-int encode_wav(const char *infile, const char *outfile, bool verbose, uint64 skip, bool verify, bool lax, bool do_mid_side, bool do_exhaustive_model_search, bool do_qlp_coeff_prec_search, unsigned rice_optimization_level, unsigned max_lpc_order, unsigned blocksize, unsigned qlp_coeff_precision)
+int encode_wav(const char *infile, const char *outfile, bool verbose, uint64 skip, bool verify, bool lax, bool do_mid_side, bool force_mid_side, bool do_exhaustive_model_search, bool do_qlp_coeff_prec_search, unsigned rice_optimization_level, unsigned max_lpc_order, unsigned blocksize, unsigned qlp_coeff_precision)
 {
        encoder_wrapper_struct encoder_wrapper;
        FILE *fin;
@@ -245,7 +245,7 @@ int encode_wav(const char *infile, const char *outfile, bool verbose, uint64 ski
        encoder_wrapper.total_samples_to_encode = data_bytes / bytes_per_wide_sample - skip;
        encoder_wrapper.unencoded_size = encoder_wrapper.total_samples_to_encode * bytes_per_wide_sample + 44; /* 44 for the size of the WAV headers */
 
-       if(!init_encoder(lax, do_mid_side, do_exhaustive_model_search, do_qlp_coeff_prec_search, rice_optimization_level, max_lpc_order, blocksize, qlp_coeff_precision, channels, bps, sample_rate, &encoder_wrapper))
+       if(!init_encoder(lax, do_mid_side, force_mid_side, do_exhaustive_model_search, do_qlp_coeff_prec_search, rice_optimization_level, max_lpc_order, blocksize, qlp_coeff_precision, channels, bps, sample_rate, &encoder_wrapper))
                goto wav_abort_;
 
        encoder_wrapper.verify_fifo.into_frames = true;
@@ -322,7 +322,7 @@ wav_abort_:
        return 1;
 }
 
-int encode_raw(const char *infile, const char *outfile, bool verbose, uint64 skip, bool verify, bool lax, bool do_mid_side, bool do_exhaustive_model_search, bool do_qlp_coeff_prec_search, unsigned rice_optimization_level, unsigned max_lpc_order, unsigned blocksize, unsigned qlp_coeff_precision, bool is_big_endian, bool is_unsigned_samples, unsigned channels, unsigned bps, unsigned sample_rate)
+int encode_raw(const char *infile, const char *outfile, bool verbose, uint64 skip, bool verify, bool lax, bool do_mid_side, bool force_mid_side, bool do_exhaustive_model_search, bool do_qlp_coeff_prec_search, unsigned rice_optimization_level, unsigned max_lpc_order, unsigned blocksize, unsigned qlp_coeff_precision, bool is_big_endian, bool is_unsigned_samples, unsigned channels, unsigned bps, unsigned sample_rate)
 {
        encoder_wrapper_struct encoder_wrapper;
        FILE *fin;
@@ -395,7 +395,7 @@ int encode_raw(const char *infile, const char *outfile, bool verbose, uint64 ski
                }
        }
 
-       if(!init_encoder(lax, do_mid_side, do_exhaustive_model_search, do_qlp_coeff_prec_search, rice_optimization_level, max_lpc_order, blocksize, qlp_coeff_precision, channels, bps, sample_rate, &encoder_wrapper))
+       if(!init_encoder(lax, do_mid_side, force_mid_side, do_exhaustive_model_search, do_qlp_coeff_prec_search, rice_optimization_level, max_lpc_order, blocksize, qlp_coeff_precision, channels, bps, sample_rate, &encoder_wrapper))
                goto raw_abort_;
 
        encoder_wrapper.verify_fifo.into_frames = true;
@@ -483,10 +483,10 @@ bool init(encoder_wrapper_struct *encoder_wrapper)
        return true;
 }
 
-bool init_encoder(bool lax, bool do_mid_side, bool do_exhaustive_model_search, bool do_qlp_coeff_prec_search, unsigned rice_optimization_level, unsigned max_lpc_order, unsigned blocksize, unsigned qlp_coeff_precision, unsigned channels, unsigned bps, unsigned sample_rate, encoder_wrapper_struct *encoder_wrapper)
+bool init_encoder(bool lax, bool do_mid_side, bool force_mid_side, bool do_exhaustive_model_search, bool do_qlp_coeff_prec_search, unsigned rice_optimization_level, unsigned max_lpc_order, unsigned blocksize, unsigned qlp_coeff_precision, unsigned channels, unsigned bps, unsigned sample_rate, encoder_wrapper_struct *encoder_wrapper)
 {
        if(channels != 2 || bps > 16)
-               do_mid_side = false;
+               do_mid_side = force_mid_side = false;
 
        if(encoder_wrapper->verify) {
                unsigned i;
@@ -523,6 +523,7 @@ bool init_encoder(bool lax, bool do_mid_side, bool do_exhaustive_model_search, b
        encoder_wrapper->encoder->qlp_coeff_precision = qlp_coeff_precision;
        encoder_wrapper->encoder->max_lpc_order = max_lpc_order;
        encoder_wrapper->encoder->do_mid_side_stereo = do_mid_side;
+       encoder_wrapper->encoder->force_mid_side_stereo = force_mid_side;
        encoder_wrapper->encoder->do_exhaustive_model_search = do_exhaustive_model_search;
        encoder_wrapper->encoder->do_qlp_coeff_prec_search = do_qlp_coeff_prec_search;
        encoder_wrapper->encoder->rice_optimization_level = rice_optimization_level;
index 0d98792..e637595 100644 (file)
@@ -21,7 +21,7 @@
 
 #include "FLAC/ordinals.h"
 
-int encode_wav(const char *infile, const char *outfile, bool verbose, uint64 skip, bool verify, bool lax, bool do_mid_side, bool do_exhaustive_model_search, bool do_qlp_coeff_prec_search, unsigned rice_optimization_level, unsigned max_lpc_order, unsigned blocksize, unsigned qlp_coeff_precision);
-int encode_raw(const char *infile, const char *outfile, bool verbose, uint64 skip, bool verify, bool lax, bool do_mid_side, bool do_exhaustive_model_search, bool do_qlp_coeff_prec_search, unsigned rice_optimization_level, unsigned max_lpc_order, unsigned blocksize, unsigned qlp_coeff_precision, bool is_big_endian, bool is_unsigned_samples, unsigned channels, unsigned bps, unsigned sample_rate);
+int encode_wav(const char *infile, const char *outfile, bool verbose, uint64 skip, bool verify, bool lax, bool do_mid_side, bool force_mid_side, bool do_exhaustive_model_search, bool do_qlp_coeff_prec_search, unsigned rice_optimization_level, unsigned max_lpc_order, unsigned blocksize, unsigned qlp_coeff_precision);
+int encode_raw(const char *infile, const char *outfile, bool verbose, uint64 skip, bool verify, bool lax, bool do_mid_side, bool force_mid_side, bool do_exhaustive_model_search, bool do_qlp_coeff_prec_search, unsigned rice_optimization_level, unsigned max_lpc_order, unsigned blocksize, unsigned qlp_coeff_precision, bool is_big_endian, bool is_unsigned_samples, unsigned channels, unsigned bps, unsigned sample_rate);
 
 #endif
index 8d19736..b4ab40c 100644 (file)
@@ -32,7 +32,7 @@ int main(int argc, char *argv[])
 {
        int i;
        bool verify = false, verbose = true, lax = false, mode_decode = false, test_only = false, analyze = false;
-       bool do_mid_side = true, do_exhaustive_model_search = false, do_qlp_coeff_prec_search = false;
+       bool do_mid_side = true, force_mid_side = false, do_exhaustive_model_search = false, do_qlp_coeff_prec_search = false;
        unsigned max_lpc_order = 8;
        unsigned qlp_coeff_precision = 0;
        uint64 skip = 0;
@@ -79,6 +79,10 @@ int main(int argc, char *argv[])
                        do_mid_side = true;
                else if(0 == strcmp(argv[i], "-m-"))
                        do_mid_side = false;
+               else if(0 == strcmp(argv[i], "-M"))
+                       force_mid_side = do_mid_side = true;
+               else if(0 == strcmp(argv[i], "-M-"))
+                       force_mid_side = do_mid_side = false;
                else if(0 == strcmp(argv[i], "-p"))
                        do_qlp_coeff_prec_search = true;
                else if(0 == strcmp(argv[i], "-p-"))
@@ -110,6 +114,7 @@ int main(int argc, char *argv[])
                else if(0 == strcmp(argv[i], "-0")) {
                        do_exhaustive_model_search = false;
                        do_mid_side = false;
+                       force_mid_side = false;
                        qlp_coeff_precision = 0;
                        rice_optimization_level = 0;
                        max_lpc_order = 0;
@@ -117,6 +122,7 @@ int main(int argc, char *argv[])
                else if(0 == strcmp(argv[i], "-1")) {
                        do_exhaustive_model_search = false;
                        do_mid_side = true;
+                       force_mid_side = true;
                        qlp_coeff_precision = 0;
                        rice_optimization_level = 0;
                        max_lpc_order = 0;
@@ -124,12 +130,14 @@ int main(int argc, char *argv[])
                else if(0 == strcmp(argv[i], "-2")) {
                        do_exhaustive_model_search = false;
                        do_mid_side = true;
+                       force_mid_side = false;
                        qlp_coeff_precision = 0;
                        max_lpc_order = 0;
                }
                else if(0 == strcmp(argv[i], "-4")) {
                        do_exhaustive_model_search = false;
                        do_mid_side = false;
+                       force_mid_side = false;
                        qlp_coeff_precision = 0;
                        rice_optimization_level = 0;
                        max_lpc_order = 8;
@@ -137,6 +145,7 @@ int main(int argc, char *argv[])
                else if(0 == strcmp(argv[i], "-5")) {
                        do_exhaustive_model_search = false;
                        do_mid_side = true;
+                       force_mid_side = true;
                        qlp_coeff_precision = 0;
                        rice_optimization_level = 0;
                        max_lpc_order = 8;
@@ -144,18 +153,21 @@ int main(int argc, char *argv[])
                else if(0 == strcmp(argv[i], "-6")) {
                        do_exhaustive_model_search = false;
                        do_mid_side = true;
+                       force_mid_side = false;
                        qlp_coeff_precision = 0;
                        max_lpc_order = 8;
                }
                else if(0 == strcmp(argv[i], "-8")) {
                        do_exhaustive_model_search = false;
                        do_mid_side = true;
+                       force_mid_side = false;
                        qlp_coeff_precision = 0;
                        max_lpc_order = 32;
                }
                else if(0 == strcmp(argv[i], "-9")) {
                        do_exhaustive_model_search = true;
                        do_mid_side = true;
+                       force_mid_side = false;
                        do_qlp_coeff_prec_search = true;
                        rice_optimization_level = 99;
                        max_lpc_order = 32;
@@ -251,7 +263,7 @@ int main(int argc, char *argv[])
 
                if(!mode_decode) {
                        printf("options:%s -b %u%s -l %u%s%s -q %u -r %u%s\n",
-                               lax?" --lax":"", (unsigned)blocksize, do_mid_side?" -m":"", max_lpc_order,
+                               lax?" --lax":"", (unsigned)blocksize, force_mid_side?" -M":do_mid_side?" -m":"", max_lpc_order,
                                do_exhaustive_model_search?" -e":"", do_qlp_coeff_prec_search?" -p":"",
                                qlp_coeff_precision, (unsigned)rice_optimization_level,
                                verify? " -V":""
@@ -266,9 +278,9 @@ int main(int argc, char *argv[])
                        return decode_raw(argv[i], test_only? 0 : argv[i+1], analyze, verbose, skip, format_is_big_endian, format_is_unsigned_samples);
        else
                if(format_is_wave)
-                       return encode_wav(argv[i], argv[i+1], verbose, skip, verify, lax, do_mid_side, do_exhaustive_model_search, do_qlp_coeff_prec_search, rice_optimization_level, max_lpc_order, (unsigned)blocksize, qlp_coeff_precision);
+                       return encode_wav(argv[i], argv[i+1], verbose, skip, verify, lax, do_mid_side, force_mid_side, do_exhaustive_model_search, do_qlp_coeff_prec_search, rice_optimization_level, max_lpc_order, (unsigned)blocksize, qlp_coeff_precision);
                else
-                       return encode_raw(argv[i], argv[i+1], verbose, skip, verify, lax, do_mid_side, do_exhaustive_model_search, do_qlp_coeff_prec_search, rice_optimization_level, max_lpc_order, (unsigned)blocksize, qlp_coeff_precision, format_is_big_endian, format_is_unsigned_samples, format_channels, format_bps, format_sample_rate);
+                       return encode_raw(argv[i], argv[i+1], verbose, skip, verify, lax, do_mid_side, force_mid_side, do_exhaustive_model_search, do_qlp_coeff_prec_search, rice_optimization_level, max_lpc_order, (unsigned)blocksize, qlp_coeff_precision, format_is_big_endian, format_is_unsigned_samples, format_channels, format_bps, format_sample_rate);
 
        return 0;
 }
@@ -327,14 +339,15 @@ int usage(const char *message, ...)
        printf("  --lax : allow encoder to generate non-Subset files\n");
        printf("  -b blocksize : default is 1152 for -l 0, else 4608; should be 192/576/1152/2304/4608 (unless --lax is used)\n");
        printf("  -m : try mid-side coding for each frame (stereo input only)\n");
+       printf("  -M : force mid-side coding for all frames (stereo input only)\n");
        printf("  -0 .. -9 : fastest compression .. highest compression, default is -6\n");
        printf("             these are synonyms for other options:\n");
        printf("  -0 : synonymous with -l 0\n");
-       printf("  -1 : synonymous with -l 0 -m\n");
+       printf("  -1 : synonymous with -l 0 -M\n");
        printf("  -2 : synonymous with -l 0 -m -r # (# is automatically determined by the block size)\n");
        printf("  -3 : reserved\n");
        printf("  -4 : synonymous with -l 8\n");
-       printf("  -5 : synonymous with -l 8 -m\n");
+       printf("  -5 : synonymous with -l 8 -M\n");
        printf("  -6 : synonymous with -l 8 -m -r # (# is automatically determined by the block size)\n");
        printf("  -7 : reserved\n");
        printf("  -8 : synonymous with -l 32 -m -r # (# is automatically determined by the block size)\n");
@@ -345,7 +358,7 @@ int usage(const char *message, ...)
        printf("  -q bits : precision of the quantized linear-predictor coefficients, 0 => let encoder decide (min is %u, default is -q 0)\n", FLAC__MIN_QLP_COEFF_PRECISION);
        printf("  -r level : rice parameter optimization level (level is 0..99, 0 => none, default is -r 0, above 4 doesn't usually help much)\n");
        printf("  -V : verify a correct encoding by decoding the output in parallel and comparing to the original\n");
-       printf("  -m-, -e-, -p-, -V-, --lax- can all be used to turn off a particular option\n");
+       printf("  -m-, -M-, -e-, -p-, -V-, --lax- can all be used to turn off a particular option\n");
        printf("format options:\n");
        printf("  -fb | -fl : big-endian | little-endian byte order\n");
        printf("  -fc channels\n");