#include <windows.h>
#endif
#include "compat.h"
-#include "wav_reader.h"
-#include "caf_reader.h"
+#include "pcm_reader.h"
#include "aacenc.h"
#include "m4af.h"
#include "progress.h"
++encoded;
if (encoded == 1 || encoded == 3)
continue;
- obp = &obuf[flip];
- if (write_sample(params->output_fp, m4af, obp) < 0)
+
+ if (write_sample(params->output_fp, m4af, &obuf[flip]) < 0)
goto END;
++frames_written;
} while (remaining > 0);
+ /*
+ * When interrupted, we haven't pulled out last extrapolated frames
+ * from the reader. Therefore, we have to write the final outcome.
+ */
+ if (g_interrupted) {
+ if (write_sample(params->output_fp, m4af, &obp[flip^1]) < 0)
+ goto END;
+ ++frames_written;
+ }
}
DONE:
if (!params->silent)
if ((params->input_fp = aacenc_fopen(params->input_filename, "rb")) == 0) {
aacenc_fprintf(stderr, "ERROR: %s: %s\n", params->input_filename,
strerror(errno));
- goto END;
+ goto FAIL;
}
io.cookie = params->input_fp;
if (fstat(fileno(params->input_fp), &stb) == 0
pcm_sample_description_t desc = { 0 };
if (parse_raw_spec(params->raw_format, &desc) < 0) {
fprintf(stderr, "ERROR: invalid raw-format spec\n");
- goto END;
+ goto FAIL;
}
desc.sample_rate = params->raw_rate;
desc.channels_per_frame = params->raw_channels;
desc.bytes_per_frame = params->raw_channels * bytes_per_channel;
if ((reader = raw_open(&io, &desc)) == 0) {
fprintf(stderr, "ERROR: failed to open raw input\n");
- goto END;
+ goto FAIL;
}
} else {
int c;
case 'R':
if ((reader = wav_open(&io, params->ignore_length)) == 0) {
fprintf(stderr, "ERROR: broken / unsupported input file\n");
- goto END;
+ goto FAIL;
}
break;
case 'c':
aacenc_translate_generic_text_tag,
¶ms->source_tag_ctx)) == 0) {
fprintf(stderr, "ERROR: broken / unsupported input file\n");
- goto END;
+ goto FAIL;
}
break;
default:
fprintf(stderr, "ERROR: unsupported input file\n");
- goto END;
+ goto FAIL;
}
}
- if ((reader = pcm_open_sint16_converter(reader)) != 0)
+ reader = pcm_open_native_converter(reader);
+ if (reader && PCM_IS_FLOAT(pcm_get_format(reader)))
+ reader = limiter_open(reader);
+ if (reader && (reader = pcm_open_sint16_converter(reader)) != 0)
reader = extrapolater_open(reader);
return reader;
-END:
+FAIL:
return 0;
}
if ((m4af = m4af_create(M4AF_CODEC_MP4A, scale, &m4af_io,
params.output_fp)) < 0)
goto END;
+ m4af_set_num_channels(m4af, 0, sample_format->channels_per_frame);
m4af_set_decoder_specific_info(m4af, 0,
aacinfo.confBuf, aacinfo.confSize);
- m4af_set_fixed_frame_duration(m4af, 0,
- framelen >> scale_shift);
+ m4af_set_fixed_frame_duration(m4af, 0, framelen >> scale_shift);
m4af_set_vbr_mode(m4af, 0, params.bitrate_mode);
m4af_set_priming_mode(m4af, params.gapless_mode + 1);
m4af_begin_write(m4af);