35
41
/* Define the supported formats here */
36
42
input_format formats[] = {
37
{wav_id, 12, wav_open, wav_close, "wav", "WAV file reader"},
38
{aiff_id, 12, aiff_open, wav_close, "aiff", "AIFF/AIFC file reader"},
43
{wav_id, 12, wav_open, wav_close, "wav", N_("WAV file reader")},
44
{aiff_id, 12, aiff_open, wav_close, "aiff", N_("AIFF/AIFC file reader")},
46
{flac_id, 4, flac_open, flac_close, "flac", N_("FLAC file reader")},
47
{oggflac_id, 32, flac_open, flac_close, "ogg", N_("Ogg FLAC file reader")},
39
49
{NULL, 0, NULL, NULL, NULL, NULL}
245
258
format.samplesize = READ_U16_BE(buffer+6);
246
259
format.rate = (int)read_IEEE80(buffer+8);
252
fprintf(stderr, "Warning: AIFF-C header truncated.\n");
267
fprintf(stderr, _("Warning: AIFF-C header truncated.\n"));
255
else if(memcmp(buffer+18, "NONE", 4))
257
fprintf(stderr, "Warning: Can't handle compressed AIFF-C\n");
271
if(!memcmp(buffer+18, "NONE", 4))
275
else if(!memcmp(buffer+18, "sowt", 4))
281
fprintf(stderr, _("Warning: Can't handle compressed AIFF-C (%c%c%c%c)\n"), *(buffer+18), *(buffer+19), *(buffer+20), *(buffer+21));
258
282
return 0; /* Compressed. Can't handle */
262
286
if(!find_aiff_chunk(in, "SSND", &len))
264
fprintf(stderr, "Warning: No SSND chunk found in AIFF file\n");
288
fprintf(stderr, _("Warning: No SSND chunk found in AIFF file\n"));
265
289
return 0; /* No SSND chunk -> no actual audio */
270
fprintf(stderr, "Warning: Corrupted SSND chunk in AIFF header\n");
294
fprintf(stderr, _("Warning: Corrupted SSND chunk in AIFF header\n"));
274
298
if(fread(buf2,1,8, in) < 8)
276
fprintf(stderr, "Warning: Unexpected EOF reading AIFF header\n");
300
fprintf(stderr, _("Warning: Unexpected EOF reading AIFF header\n"));
405
"ERROR: Wav file is unsupported type (must be standard PCM\n"
406
" or type 3 floating point PCM\n");
423
_("ERROR: Wav file is unsupported type (must be standard PCM\n"
424
" or type 3 floating point PCM\n"));
412
430
if( format.align == format.channels*samplesize &&
413
format.samplesize == samplesize*8)
431
format.samplesize == samplesize*8 &&
432
(format.samplesize == 24 || format.samplesize == 16 ||
433
format.samplesize == 8 ||
434
(format.samplesize == 32 && format.format == 3)))
415
if(format.samplerate != 44100 && format.samplerate != 48000)
416
fprintf(stderr, "Warning: Vorbis is not currently tuned for this input (%.3f kHz).\n"
417
" At other than 44.1/48 kHz quality will be degraded.\n",
418
(float)format.samplerate * 1.0e-3);
420
436
/* OK, good - we have the one supported format,
421
437
now we want to find the size of the file */
422
438
opt->rate = format.samplerate;
567
605
format.align = format.bytespersec;
569
607
wav->samplesread = 0;
608
wav->bigendian = opt->endianness;
571
609
wav->channels = format.channels;
572
610
wav->samplesize = opt->samplesize;
611
wav->totalsamples = 0;
574
613
opt->read_samples = wav_read;
575
614
opt->readdata = (void *)wav;
576
615
opt->total_samples_per_channel = 0; /* raw mode, don't bother */
621
audio_read_func real_reader;
629
static long read_resampled(void *d, float **buffer, int samples)
635
in_samples = res_push_max_input(&rs->resampler, samples);
636
if(in_samples > rs->bufsize)
637
in_samples = rs->bufsize;
639
in_samples = rs->real_reader(rs->real_readdata, rs->bufs, in_samples);
641
if(in_samples <= 0) {
644
out_samples = res_drain(&rs->resampler, buffer);
650
out_samples = res_push(&rs->resampler, buffer, (float const **)rs->bufs, in_samples);
652
if(out_samples <= 0) {
653
fprintf(stderr, _("BUG: Got zero samples from resampler: your file will be truncated. Please report this.\n"));
659
int setup_resample(oe_enc_opt *opt) {
660
resampler *rs = calloc(1, sizeof(resampler));
663
rs->bufsize = 4096; /* Shrug */
664
rs->real_reader = opt->read_samples;
665
rs->real_readdata = opt->readdata;
666
rs->bufs = malloc(sizeof(float *) * opt->channels);
667
rs->channels = opt->channels;
669
if(res_init(&rs->resampler, rs->channels, opt->resamplefreq, opt->rate, RES_END))
671
fprintf(stderr, _("Couldn't initialise resampler\n"));
675
for(c=0; c < opt->channels; c++)
676
rs->bufs[c] = malloc(sizeof(float) * rs->bufsize);
678
opt->read_samples = read_resampled;
680
if(opt->total_samples_per_channel)
681
opt->total_samples_per_channel = (int)((float)opt->total_samples_per_channel *
682
((float)opt->resamplefreq/(float)opt->rate));
683
opt->rate = opt->resamplefreq;
688
void clear_resample(oe_enc_opt *opt) {
689
resampler *rs = opt->readdata;
692
opt->read_samples = rs->real_reader;
693
opt->readdata = rs->real_readdata;
694
res_clear(&rs->resampler);
696
for(i = 0; i < rs->channels; i++)
705
audio_read_func real_reader;
711
static long read_scaler(void *data, float **buffer, int samples) {
713
long in_samples = d->real_reader(d->real_readdata, buffer, samples);
716
for(i=0; i < d->channels; i++) {
717
for(j=0; j < in_samples; j++) {
718
buffer[i][j] *= d->scale_factor;
726
void setup_scaler(oe_enc_opt *opt, float scale) {
727
scaler *d = calloc(1, sizeof(scaler));
729
d->real_reader = opt->read_samples;
730
d->real_readdata = opt->readdata;
732
opt->read_samples = read_scaler;
734
d->channels = opt->channels;
735
d->scale_factor = scale;
738
void clear_scaler(oe_enc_opt *opt) {
739
scaler *d = opt->readdata;
741
opt->read_samples = d->real_reader;
742
opt->readdata = d->real_readdata;
748
audio_read_func real_reader;
753
static long read_downmix(void *data, float **buffer, int samples)
756
long in_samples = d->real_reader(d->real_readdata, d->bufs, samples);
759
for(i=0; i < in_samples; i++) {
760
buffer[0][i] = (d->bufs[0][i] + d->bufs[1][i])*0.5f;
766
void setup_downmix(oe_enc_opt *opt) {
767
downmix *d = calloc(1, sizeof(downmix));
769
if(opt->channels != 2) {
770
fprintf(stderr, "Internal error! Please report this bug.\n");
774
d->bufs = malloc(2 * sizeof(float *));
775
d->bufs[0] = malloc(4096 * sizeof(float));
776
d->bufs[1] = malloc(4096 * sizeof(float));
777
d->real_reader = opt->read_samples;
779
d->real_readdata = opt->readdata;
781
opt->read_samples = read_downmix;
786
void clear_downmix(oe_enc_opt *opt) {
787
downmix *d = opt->readdata;
789
opt->read_samples = d->real_reader;
790
opt->readdata = d->real_readdata;
791
opt->channels = 2; /* other things in cleanup rely on this */