Commit 02da5ace authored by Josh Coalson's avatar Josh Coalson
Browse files

fix handling of aiff ssnd offset; do not try and recreate offset or block align when writing aiff

parent fed9dc91
......@@ -418,9 +418,9 @@ FLAC__bool DecoderSession_process(DecoderSession *d)
if(flac__utils_fwrite("\000", 1, 1, d->fout) != 1) {
print_error_with_state(
d,
d->format == FORMAT_WAVE? "ERROR writing pad byte to WAVE data chunk" :
d->format == FORMAT_WAVE64? "ERROR writing pad bytes to WAVE64 data chunk" :
d->format == FORMAT_RF64? "ERROR writing pad byte to RF64 data chunk" :
d->format == FORMAT_WAVE? "ERROR writing pad byte to WAVE data chunk" :
d->format == FORMAT_WAVE64? "ERROR writing pad bytes to WAVE64 data chunk" :
d->format == FORMAT_RF64? "ERROR writing pad byte to RF64 data chunk" :
"ERROR writing pad byte to AIFF SSND chunk"
);
return false;
......@@ -605,8 +605,7 @@ FLAC__bool write_iff_headers(FILE *f, DecoderSession *decoder_session, FLAC__uin
/* +16+8 for data chunk header (GUID and size field) */
iff_size = 16+8 + 16 + 16+8+(is_waveformatextensible?40:16) + 16+8 + foreign_metadata_size + aligned_data_size;
else /* AIFF */
/* @@@@@@ can ssnd_offset_size be odd and hence screw up our alignment logic? */
iff_size = 46 + foreign_metadata_size + aligned_data_size + (fm? fm->ssnd_offset_size : 0);
iff_size = 46 + foreign_metadata_size + aligned_data_size;
if(format != FORMAT_WAVE64 && format != FORMAT_RF64 && iff_size >= 0xFFFFFFF4) {
flac__utils_printf(stderr, 1, "%s: ERROR: stream is too big to fit in a single %s file\n", decoder_session->inbasefilename, fmt_desc);
......@@ -727,8 +726,6 @@ FLAC__bool write_iff_headers(FILE *f, DecoderSession *decoder_session, FLAC__uin
decoder_session->fm_offset3 = ftello(f) + aligned_data_size;
}
else {
FLAC__uint32 ssnd_offset_size = (fm? fm->ssnd_offset_size : 0);
if(flac__utils_fwrite("FORM", 1, 4, f) != 4)
return false;
......@@ -768,23 +765,15 @@ FLAC__bool write_iff_headers(FILE *f, DecoderSession *decoder_session, FLAC__uin
if(flac__utils_fwrite("SSND", 1, 4, f) != 4)
return false;
if(!write_big_endian_uint32(f, (FLAC__uint32)data_size + 8 + ssnd_offset_size)) /* data size */
if(!write_big_endian_uint32(f, (FLAC__uint32)data_size + 8)) /* data size */
return false;
if(!write_big_endian_uint32(f, ssnd_offset_size))
if(!write_big_endian_uint32(f, 0/*offset_size*/))
return false;
if(!write_big_endian_uint32(f, 0/*block_size*/))
return false;
if(ssnd_offset_size) {
/* seek forward to {allocate} or {skip over already-written} SSND offset */
if(fseeko(f, ssnd_offset_size, SEEK_CUR) < 0) {
flac__utils_printf(stderr, 1, "%s: ERROR: allocating/skipping \"SSND\" offset\n", decoder_session->inbasefilename);
return false;
}
}
decoder_session->fm_offset3 = ftello(f) + aligned_data_size;
}
......
......@@ -801,7 +801,7 @@ static FLAC__bool get_sample_info_aiff(EncoderSession *e, encode_options_t optio
else if(!memcmp(chunk_id, "SSND", 4) && !got_ssnd_chunk) { /* sound data chunk */
FLAC__uint32 xx;
FLAC__uint64 data_bytes;
unsigned offset = 0, block_size = 0;
unsigned offset = 0;
if(!got_comm_chunk) {
flac__utils_printf(stderr, 1, "%s: ERROR: got 'SSND' chunk before 'COMM' chunk\n", e->inbasefilename);
......@@ -838,21 +838,21 @@ static FLAC__bool get_sample_info_aiff(EncoderSession *e, encode_options_t optio
/* block size */
if(!read_uint32(e->fin, /*big_endian=*/true, &xx, e->inbasefilename))
return false;
else if(xx != 0) {
flac__utils_printf(stderr, 1, "%s: ERROR: block size is %u; must be 0\n", e->inbasefilename, (unsigned)xx);
return false;
if(xx && !options.ignore_chunk_sizes)
data_bytes -= (xx - (data_bytes % xx));
if(options.ignore_chunk_sizes) {
if(xx) {
flac__utils_printf(stderr, 1, "%s: WARNING: 'SSND' chunk has non-zero blocksize, using --ignore-chunk-sizes is probably a bad idea\n", e->inbasefilename, chunk_id);
if(e->treat_warnings_as_errors)
return false;
}
}
block_size = xx;
/* skip any SSND offset bytes */
if(!fskip_ahead(e->fin, offset)) {
flac__utils_printf(stderr, 1, "%s: ERROR: skipping offset in SSND chunk\n", e->inbasefilename);
return false;
}
if(data_bytes != (sample_frames * e->info.bytes_per_wide_sample)) {
flac__utils_printf(stderr, 1, "%s: ERROR: SSND chunk size inconsistent with sample frame count\n", e->inbasefilename);
return false;
}
e->fmt.iff.data_bytes = data_bytes;
......@@ -1068,6 +1068,7 @@ int flac__encode_file(FILE *infile, off_t infilesize, const char *infilename, co
case FORMAT_RF64:
case FORMAT_AIFF:
case FORMAT_AIFF_C:
/* truncation in the division removes any padding byte that was counted in encoder_session.fmt.iff.data_bytes */
total_samples_in_input = encoder_session.fmt.iff.data_bytes / encoder_session.info.bytes_per_wide_sample + *options.align_reservoir_samples;
break;
case FORMAT_FLAC:
......
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