chiark / gitweb /
WAV hands-off reading.
[disorder] / lib / resample.c
index 99879a4a87423558d3da1ff50364eadbc6e03442..39514ed37c3cf6497ba05a1e530053932db39d57 100644 (file)
@@ -214,10 +214,8 @@ static size_t resample_put_sample(const struct resampler *rs,
  */
 static void resample_prepare_input(const struct resampler *rs,
                                    const uint8_t *bytes,
-                                   size_t nbytes,
+                                   size_t nframes,
                                    float *floats) {
-  size_t nframes = nbytes / (rs->input_bytes_per_frame);
-
   while(nframes > 0) {
     int n;
 
@@ -261,11 +259,12 @@ size_t resample_convert(const struct resampler *rs,
   float *input = xcalloc(nframesin * rs->output_channels, sizeof (float));
   float *output = 0;
 
-  resample_prepare_input(rs, bytes, nbytes, input);
+  resample_prepare_input(rs, bytes, nframesin, input);
 #if HAVE_SAMPLERATE_H
   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));
@@ -275,11 +274,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) {