add verbose option to analysis mode to dump residuals
authorJosh Coalson <jcoalson@users.sourceforce.net>
Thu, 15 Mar 2001 23:19:44 +0000 (23:19 +0000)
committerJosh Coalson <jcoalson@users.sourceforce.net>
Thu, 15 Mar 2001 23:19:44 +0000 (23:19 +0000)
src/flac/decode.c
src/flac/decode.h
src/flac/main.c

index d19854d..bf5688a 100644 (file)
@@ -32,6 +32,7 @@ typedef struct {
        FILE *fout;
        bool abort_flag;
        bool analysis_mode;
+       bool analyze_residual;
        bool test_only;
        bool is_wave_out;
        bool is_big_endian;
@@ -58,7 +59,7 @@ static void metadata_callback(const FLAC__FileDecoder *decoder, const FLAC__Stre
 static void error_callback(const FLAC__FileDecoder *decoder, FLAC__StreamDecoderErrorStatus status, void *client_data);
 static void print_stats(const stream_info_struct *stream_info);
 
-int decode_wav(const char *infile, const char *outfile, bool analysis_mode, bool verbose, uint64 skip)
+int decode_wav(const char *infile, const char *outfile, bool analysis_mode, bool analyze_residual, bool verbose, uint64 skip)
 {
        bool md5_failure = false;
        stream_info_struct stream_info;
@@ -66,6 +67,7 @@ int decode_wav(const char *infile, const char *outfile, bool analysis_mode, bool
        decoder = 0;
        stream_info.abort_flag = false;
        stream_info.analysis_mode = analysis_mode;
+       stream_info.analyze_residual = analyze_residual;
        stream_info.test_only = (outfile == 0);
        stream_info.is_wave_out = true;
        stream_info.verbose = verbose;
@@ -156,7 +158,7 @@ wav_abort_:
        return 1;
 }
 
-int decode_raw(const char *infile, const char *outfile, bool analysis_mode, bool verbose, uint64 skip, bool is_big_endian, bool is_unsigned_samples)
+int decode_raw(const char *infile, const char *outfile, bool analysis_mode, bool analyze_residual, bool verbose, uint64 skip, bool is_big_endian, bool is_unsigned_samples)
 {
        bool md5_failure = false;
        stream_info_struct stream_info;
@@ -164,6 +166,7 @@ int decode_raw(const char *infile, const char *outfile, bool analysis_mode, bool
        decoder = 0;
        stream_info.abort_flag = false;
        stream_info.analysis_mode = analysis_mode;
+       stream_info.analyze_residual = analyze_residual;
        stream_info.test_only = (outfile == 0);
        stream_info.is_wave_out = false;
        stream_info.is_big_endian = is_big_endian;
@@ -338,12 +341,20 @@ FLAC__StreamDecoderWriteStatus write_callback(const FLAC__FileDecoder *decoder,
                                case FLAC__SUBFRAME_TYPE_FIXED:
                                        fprintf(fout, "\torder=%u\tpartition_order=%u\n", subframe->data.fixed.order, subframe->data.fixed.entropy_coding_method.data.partitioned_rice.order); /*@@@ assumes method is partitioned-rice */
                                        for(i = 0; i < subframe->data.fixed.order; i++)
-                                               fprintf(fout, "\twarmup[%u]=%d\n", i, subframe->data.fixed.warmup[i]);
+                                               fprintf(fout, "\t\twarmup[%u]=%d\n", i, subframe->data.fixed.warmup[i]);
+                                       if(stream_info->analyze_residual) {
+                                               for(i = 0; i < frame->header.blocksize-subframe->data.fixed.order; i++)
+                                                       fprintf(fout, "\t\tresidual[%u]=%d\n", i, subframe->data.fixed.residual[i]);
+                                       }
                                        break;
                                case FLAC__SUBFRAME_TYPE_LPC:
                                        fprintf(fout, "\torder=%u\tpartition_order=%u\tqlp_coeff_precision=%u\tquantization_level=%d\n", subframe->data.lpc.order, subframe->data.lpc.entropy_coding_method.data.partitioned_rice.order, subframe->data.lpc.qlp_coeff_precision, subframe->data.lpc.quantization_level); /*@@@ assumes method is partitioned-rice */
                                        for(i = 0; i < subframe->data.lpc.order; i++)
-                                               fprintf(fout, "\twarmup[%u]=%d\n", i, subframe->data.lpc.warmup[i]);
+                                               fprintf(fout, "\t\twarmup[%u]=%d\n", i, subframe->data.lpc.warmup[i]);
+                                       if(stream_info->analyze_residual) {
+                                               for(i = 0; i < frame->header.blocksize-subframe->data.lpc.order; i++)
+                                                       fprintf(fout, "\t\tresidual[%u]=%d\n", i, subframe->data.lpc.residual[i]);
+                                       }
                                        break;
                                case FLAC__SUBFRAME_TYPE_VERBATIM:
                                        fprintf(fout, "\n");
index b698d34..85f8b68 100644 (file)
@@ -20,7 +20,7 @@
 #define flac__decode_h
 
 /* outfile == 0 => test only */
-int decode_wav(const char *infile, const char *outfile, bool analysis_mode, bool verbose, uint64 skip);
-int decode_raw(const char *infile, const char *outfile, bool analysis_mode, bool verbose, uint64 skip, bool is_big_endian, bool is_unsigned_samples);
+int decode_wav(const char *infile, const char *outfile, bool analysis_mode, bool analyze_residual, bool verbose, uint64 skip);
+int decode_raw(const char *infile, const char *outfile, bool analysis_mode, bool analyze_residual, bool verbose, uint64 skip, bool is_big_endian, bool is_unsigned_samples);
 
 #endif
index 76415f8..d8bab8a 100644 (file)
@@ -33,6 +33,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, loose_mid_side = false, do_exhaustive_model_search = false, do_qlp_coeff_prec_search = false;
+       bool analyze_residual = false;
        unsigned padding = 0;
        unsigned max_lpc_order = 8;
        unsigned qlp_coeff_precision = 0;
@@ -94,6 +95,10 @@ int main(int argc, char *argv[])
                        qlp_coeff_precision = atoi(argv[++i]);
                else if(0 == strcmp(argv[i], "-r"))
                        rice_optimization_level = atoi(argv[++i]);
+               else if(0 == strcmp(argv[i], "-v"))
+                       analyze_residual = true;
+               else if(0 == strcmp(argv[i], "-v-"))
+                       analyze_residual = false;
                else if(0 == strcmp(argv[i], "-V"))
                        verify = true;
                else if(0 == strcmp(argv[i], "-V-"))
@@ -276,9 +281,9 @@ int main(int argc, char *argv[])
 
        if(mode_decode)
                if(format_is_wave)
-                       return decode_wav(argv[i], test_only? 0 : argv[i+1], analyze, verbose, skip);
+                       return decode_wav(argv[i], test_only? 0 : argv[i+1], analyze, analyze_residual, verbose, skip);
                else
-                       return decode_raw(argv[i], test_only? 0 : argv[i+1], analyze, verbose, skip, format_is_big_endian, format_is_unsigned_samples);
+                       return decode_raw(argv[i], test_only? 0 : argv[i+1], analyze, analyze_residual, 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, loose_mid_side, do_exhaustive_model_search, do_qlp_coeff_prec_search, rice_optimization_level, max_lpc_order, (unsigned)blocksize, qlp_coeff_precision, padding);
@@ -339,6 +344,8 @@ int usage(const char *message, ...)
        printf("  -a : analyze (same as -d except an analysis file is written)\n");
        printf("  -s : silent (do not write runtime encode/decode statistics to stdout)\n");
        printf("  --skip samples : can be used both for encoding and decoding\n");
+       printf("analyze options:\n");
+       printf("  -v : verbose (include residual signal in output)\n");
        printf("encoding options:\n");
        printf("  --lax : allow encoder to generate non-Subset files\n");
        printf("  -P bytes : write a PADDING block of the given length (0 => no PADDING block, default is -P 0)\n");