Skip to content

Commit

Permalink
Fix analyze mode trying to get positions from stdin (#720)
Browse files Browse the repository at this point in the history
  • Loading branch information
ktmf01 authored Jul 11, 2024
1 parent 9977773 commit 15ea6ef
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 7 deletions.
7 changes: 5 additions & 2 deletions src/flac/analyze.c
Original file line number Diff line number Diff line change
Expand Up @@ -62,15 +62,18 @@ void flac__analyze_init(analysis_options aopts)
}
}

void flac__analyze_frame(const FLAC__Frame *frame, uint32_t frame_number, FLAC__uint64 frame_offset, FLAC__uint64 frame_bytes, analysis_options aopts, FILE *fout)
void flac__analyze_frame(const FLAC__Frame *frame, uint32_t frame_number, FLAC__bool decode_position_valid, FLAC__uint64 frame_offset, FLAC__uint64 frame_bytes, analysis_options aopts, FILE *fout)
{
const uint32_t channels = frame->header.channels;
char outfilename[1024];
subframe_stats_t stats;
uint32_t i, channel, partitions;

/* do the human-readable part first */
fprintf(fout, "frame=%u\toffset=%" PRIu64 "\tbits=%" PRIu64 "\tblocksize=%u\tsample_rate=%u\tchannels=%u\tchannel_assignment=%s\n", frame_number, frame_offset, frame_bytes*8, frame->header.blocksize, frame->header.sample_rate, channels, FLAC__ChannelAssignmentString[frame->header.channel_assignment]);
if(decode_position_valid)
fprintf(fout, "frame=%u\toffset=%" PRIu64 "\tbits=%" PRIu64 "\tblocksize=%u\tsample_rate=%u\tchannels=%u\tchannel_assignment=%s\n", frame_number, frame_offset, frame_bytes*8, frame->header.blocksize, frame->header.sample_rate, channels, FLAC__ChannelAssignmentString[frame->header.channel_assignment]);
else
fprintf(fout, "frame=%u\toffset=?\tbits=?\tblocksize=%u\tsample_rate=%u\tchannels=%u\tchannel_assignment=%s\n", frame_number, frame->header.blocksize, frame->header.sample_rate, channels, FLAC__ChannelAssignmentString[frame->header.channel_assignment]);
for(channel = 0; channel < channels; channel++) {
const FLAC__Subframe *subframe = frame->subframes+channel;
const FLAC__bool is_rice2 = subframe->data.fixed.entropy_coding_method.type == FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2;
Expand Down
2 changes: 1 addition & 1 deletion src/flac/analyze.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ typedef struct {
} analysis_options;

void flac__analyze_init(analysis_options aopts);
void flac__analyze_frame(const FLAC__Frame *frame, uint32_t frame_number, FLAC__uint64 frame_offset, FLAC__uint64 frame_bytes, analysis_options aopts, FILE *fout);
void flac__analyze_frame(const FLAC__Frame *frame, uint32_t frame_number, FLAC__bool decode_position_valid, FLAC__uint64 frame_offset, FLAC__uint64 frame_bytes, analysis_options aopts, FILE *fout);
void flac__analyze_finish(analysis_options aopts);

#endif
12 changes: 8 additions & 4 deletions src/flac/decode.c
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ typedef struct {

/* these are used only in analyze mode */
FLAC__uint64 decode_position;
FLAC__bool decode_position_valid;

FLAC__StreamDecoder *decoder;

Expand Down Expand Up @@ -249,6 +250,7 @@ FLAC__bool DecoderSession_construct(DecoderSession *d, FLAC__bool is_ogg, FLAC__
d->channel_mask = 0;

d->decode_position = 0;
d->decode_position_valid = true;

d->decoder = 0;

Expand Down Expand Up @@ -401,7 +403,8 @@ FLAC__bool DecoderSession_process(DecoderSession *d)
}

if(d->analysis_mode)
FLAC__stream_decoder_get_decode_position(d->decoder, &d->decode_position);
if(!FLAC__stream_decoder_get_decode_position(d->decoder, &d->decode_position))
d->decode_position_valid = false;

if(d->abort_flag)
return false;
Expand Down Expand Up @@ -1231,9 +1234,10 @@ FLAC__StreamDecoderWriteStatus write_callback(const FLAC__StreamDecoder *decoder
}
}

if(decoder_session->analysis_mode) {
if(decoder_session->analysis_mode && decoder_session->decode_position_valid) {
FLAC__uint64 dpos;
FLAC__stream_decoder_get_decode_position(decoder_session->decoder, &dpos);
if(!FLAC__stream_decoder_get_decode_position(decoder_session->decoder, &dpos))
decoder_session->decode_position_valid = false;
frame_bytes = (dpos-decoder_session->decode_position);
decoder_session->decode_position = dpos;
}
Expand Down Expand Up @@ -1280,7 +1284,7 @@ FLAC__StreamDecoderWriteStatus write_callback(const FLAC__StreamDecoder *decoder


if(decoder_session->analysis_mode) {
flac__analyze_frame(frame, decoder_session->frame_counter-1, decoder_session->decode_position-frame_bytes, frame_bytes, decoder_session->aopts, fout);
flac__analyze_frame(frame, decoder_session->frame_counter-1, decoder_session->decode_position_valid, decoder_session->decode_position_valid?(decoder_session->decode_position-frame_bytes):0, frame_bytes, decoder_session->aopts, fout);
}
else if(!decoder_session->test_only) {
if(shift && !decoder_session->replaygain.apply) {
Expand Down

0 comments on commit 15ea6ef

Please sign in to comment.