chiark / gitweb /
(Slightly scrappy) new playlist box
[disorder] / lib / resample.c
index 11cb6960f359a187d91cde94110efae43c90b5f7..c4c814e738c0fc16a3006fe31ce1dbbd10df2538 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,7 +259,7 @@ 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 */
@@ -274,7 +272,7 @@ size_t resample_convert(const struct resampler *rs,
     data.input_frames = nframesin;
     data.output_frames = maxframesout;
     data.end_of_input = eof;
-    data.src_ratio = rs->output_rate / rs->input_rate;
+    data.src_ratio = (double)rs->output_rate / rs->input_rate;
     int error_ = src_process(rs->state, &data);
     if(error_)
       disorder_fatal(0, "calling src_process: %s", src_strerror(error_));
@@ -303,6 +301,7 @@ size_t resample_convert(const struct resampler *rs,
   xfree(input);
   eof = 0;             /* quieten compiler */
   /* Report how many input bytes were actually consumed */
+  //fprintf(stderr, "converted %zu frames\n", nframesin);
   return nframesin * rs->input_bytes_per_frame;
 }