X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~mdw/git/disorder/blobdiff_plain/2d0a6606ee8899dfe372bbdc760fd15c14f3fceb..c0aec5a8c25c83def2a0515e7cf9b8111196b724:/lib/resample.c diff --git a/lib/resample.c b/lib/resample.c index c4c814e..0363d99 100644 --- a/lib/resample.c +++ b/lib/resample.c @@ -41,10 +41,12 @@ * @param input_channels Number of input channels * @param input_signed Whether input samples are signed or unsigned * @param input_rate Frames/second in input + * @param input_endian Input endianness (@c ENDIAN_BIG or @c ENDIAN_LITTLE) * @param output_bits Bits/sample in output * @param output_channels Number of output channels * @param output_rate Frames/second in output * @param output_signed Whether output samples are signed or unsigned + * @param output_endian Output endianness (@c ENDIAN_BIG or @c ENDIAN_LITTLE) * * For formats with more than two channels it's assume that the first * two channels are left and right. No particular meaning is attached @@ -97,7 +99,7 @@ void resample_close(struct resampler *rs) { if(rs->state) src_delete(rs->state); #else - rs = 0; /* quieten compiler */ + if(rs){} /* quieten compiler */ #endif } @@ -199,7 +201,7 @@ static size_t resample_put_sample(const struct resampler *rs, /** @brief Convert input samples to floats * @param rs Resampler state * @param bytes Input bytes - * @param nbytes Number of input bytes + * @param nframes Number of input frames * @param floats Where to store converted data * * @p floats must be big enough. As well as converting to floats this @@ -264,6 +266,7 @@ size_t resample_convert(const struct resampler *rs, if(rs->state) { /* A sample-rate conversion must be performed */ SRC_DATA data; + memset(&data, 0, sizeof data); /* Compute how many frames are expected to come out. */ size_t maxframesout = nframesin * rs->output_rate / rs->input_rate + 1; output = xcalloc(maxframesout * rs->output_channels, sizeof(float)); @@ -273,11 +276,16 @@ size_t resample_convert(const struct resampler *rs, data.output_frames = maxframesout; data.end_of_input = eof; data.src_ratio = (double)rs->output_rate / rs->input_rate; + D(("nframesin=%zu maxframesout=%zu eof=%d ratio=%d.%06d", + nframesin, maxframesout, eof, + (int)data.src_ratio, + ((int)(data.src_ratio * 1000000) % 1000000))); int error_ = src_process(rs->state, &data); if(error_) disorder_fatal(0, "calling src_process: %s", src_strerror(error_)); nframesin = data.input_frames_used; nsamplesout = data.output_frames_gen * rs->output_channels; + D(("new nframesin=%zu nsamplesout=%zu", nframesin, nsamplesout)); } #endif if(!output) { @@ -299,7 +307,7 @@ size_t resample_convert(const struct resampler *rs, if(output != input) xfree(output); xfree(input); - eof = 0; /* quieten compiler */ + if(eof){} /* quieten compiler */ /* Report how many input bytes were actually consumed */ //fprintf(stderr, "converted %zu frames\n", nframesin); return nframesin * rs->input_bytes_per_frame;