Commit de72274e authored by Josh Coalson's avatar Josh Coalson
Browse files

add analysis options, move analysis printout to analyze.c

parent 20f315da
......@@ -32,7 +32,7 @@ typedef struct {
FILE *fout;
bool abort_flag;
bool analysis_mode;
bool analyze_residual;
analysis_options aopts;
bool test_only;
bool is_wave_out;
bool is_big_endian;
......@@ -59,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 analyze_residual, bool verbose, uint64 skip)
int decode_wav(const char *infile, const char *outfile, bool analysis_mode, analysis_options aopts, bool verbose, uint64 skip)
{
bool md5_failure = false;
stream_info_struct stream_info;
......@@ -67,7 +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.aopts = aopts;
stream_info.test_only = (outfile == 0);
stream_info.is_wave_out = true;
stream_info.verbose = verbose;
......@@ -89,6 +89,9 @@ int decode_wav(const char *infile, const char *outfile, bool analysis_mode, bool
}
}
if(analysis_mode)
analyze_init();
if(!init(infile, &stream_info))
goto wav_abort_;
......@@ -136,6 +139,8 @@ int decode_wav(const char *infile, const char *outfile, bool analysis_mode, bool
if(verbose)
printf("\n");
fflush(stdout);
if(analysis_mode)
analyze_finish();
if(md5_failure) {
fprintf(stderr, "%s: WARNING, MD5 signature mismatch\n", infile);
return 1;
......@@ -155,10 +160,12 @@ wav_abort_:
fclose(stream_info.fout);
unlink(outfile);
}
if(analysis_mode)
analyze_finish();
return 1;
}
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)
int decode_raw(const char *infile, const char *outfile, bool analysis_mode, analysis_options aopts, bool verbose, uint64 skip, bool is_big_endian, bool is_unsigned_samples)
{
bool md5_failure = false;
stream_info_struct stream_info;
......@@ -166,7 +173,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.aopts = aopts;
stream_info.test_only = (outfile == 0);
stream_info.is_wave_out = false;
stream_info.is_big_endian = is_big_endian;
......@@ -190,6 +197,9 @@ int decode_raw(const char *infile, const char *outfile, bool analysis_mode, bool
}
}
if(analysis_mode)
analyze_init();
if(!init(infile, &stream_info))
goto raw_abort_;
......@@ -237,6 +247,8 @@ int decode_raw(const char *infile, const char *outfile, bool analysis_mode, bool
if(verbose)
printf("\n");
fflush(stdout);
if(analysis_mode)
analyze_finish();
if(md5_failure) {
fprintf(stderr, "%s: WARNING, MD5 signature mismatch\n", infile);
return 1;
......@@ -256,6 +268,8 @@ raw_abort_:
fclose(stream_info.fout);
unlink(outfile);
}
if(analysis_mode)
analyze_finish();
return 1;
}
......@@ -329,38 +343,7 @@ FLAC__StreamDecoderWriteStatus write_callback(const FLAC__FileDecoder *decoder,
print_stats(stream_info);
if(stream_info->analysis_mode) {
unsigned i;
fprintf(fout, "frame=%u\tblocksize=%u\tsample_rate=%u\tchannels=%u\tchannel_assignment=%s\n", stream_info->frame_counter-1, frame->header.blocksize, frame->header.sample_rate, frame->header.channels, FLAC__ChannelAssignmentString[frame->header.channel_assignment]);
for(channel = 0; channel < channels; channel++) {
const FLAC__Subframe *subframe = frame->subframes+channel;
fprintf(fout, "\tsubframe=%u\ttype=%s", channel, FLAC__SubframeTypeString[subframe->type]);
switch(subframe->type) {
case FLAC__SUBFRAME_TYPE_CONSTANT:
fprintf(fout, "\tvalue=%d\n", subframe->data.constant.value);
break;
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, "\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, "\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");
break;
}
}
analyze_frame(frame, stream_info->frame_counter-1, stream_info->aopts, fout);
}
else if(!stream_info->test_only) {
if(bps == 8) {
......
Supports Markdown
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