aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorPaul Adenot <[email protected]>2020-07-28 16:37:07 +0200
committerPaul Adenot <[email protected]>2020-09-09 14:30:03 +0200
commita7b68885cb7e5206c62fc86909cd25f3d391c74d (patch)
treea7325b6affd58e12ef1f1a8cc2753fbfb3bc34b1
parentbdc2040367fc49a3d7c80a48d77ac180b59231db (diff)
downloadcubeb-a7b68885cb7e5206c62fc86909cd25f3d391c74d.tar.gz
cubeb-a7b68885cb7e5206c62fc86909cd25f3d391c74d.zip
Pre-feed the resampler with zeros to compensate for its latency
-rw-r--r--src/cubeb_resampler_internal.h15
1 files changed, 15 insertions, 0 deletions
diff --git a/src/cubeb_resampler_internal.h b/src/cubeb_resampler_internal.h
index c497298..e676428 100644
--- a/src/cubeb_resampler_internal.h
+++ b/src/cubeb_resampler_internal.h
@@ -192,6 +192,21 @@ public:
speex_resampler = speex_resampler_init(channels, source_rate,
target_rate, quality, &r);
assert(r == RESAMPLER_ERR_SUCCESS && "resampler allocation failure");
+
+ uint32_t ratio_num, ratio_den;
+ speex_resampler_get_ratio(speex_resampler, &ratio_num, &ratio_den);
+ uint32_t input_latency = speex_resampler_get_input_latency(speex_resampler);
+ int64_t skip_frac_num = input_latency * ratio_den;
+ T input_buffer[8192] = {};
+ T output_buffer[8192] = {};
+ uint32_t input_frame_count, output_frame_count;
+ input_frame_count = input_latency;
+ output_frame_count = 8192;
+ speex_resample(
+ input_buffer,
+ &input_frame_count,
+ output_buffer,
+ &output_frame_count);
}
/** Destructor, deallocate the resampler */