@@ -212,6 +212,10 @@ R3LiveShifter::createResamplers()
212
212
resamplerParameters.maxBufferSize = m_guideConfiguration.longestFftSize ;
213
213
resamplerParameters.dynamism = Resampler::RatioOftenChanging;
214
214
resamplerParameters.ratioChange = Resampler::SmoothRatioChange;
215
+
216
+ int debug = m_log.getDebugLevel ();
217
+ if (debug > 0 ) --debug;
218
+ resamplerParameters.debugLevel = debug;
215
219
216
220
m_inResampler = std::unique_ptr<Resampler>
217
221
(new Resampler (resamplerParameters, m_parameters.channels ));
@@ -235,15 +239,18 @@ R3LiveShifter::getFormantScale() const
235
239
size_t
236
240
R3LiveShifter::getPreferredStartPad () const
237
241
{
238
- // !!!???
239
242
return 0 ;
240
243
}
241
244
242
245
size_t
243
246
R3LiveShifter::getStartDelay () const
244
247
{
248
+ // !!! need a principled way - measure it in ctor perhaps
245
249
int resamplerDelay = 32 ;
246
- int fixed = getWindowSourceSize () / 2 + resamplerDelay;
250
+ #ifdef HAVE_LIBSAMPLERATE
251
+ resamplerDelay = 47 ;
252
+ #endif
253
+ int fixed = getWindowSourceSize () / 2 + resamplerDelay * 2 ;
247
254
int variable = getWindowSourceSize () / 2 ;
248
255
if (m_contractThenExpand) {
249
256
if (m_pitchScale < 1.0 ) {
@@ -305,7 +312,6 @@ R3LiveShifter::shift(const float *const *input, float *const *output)
305
312
m_log.log (2 , " R3LiveShifter::shift: initially in outbuf" , m_channelData[0 ]->outbuf ->getReadSpace ());
306
313
307
314
int pad = 0 ;
308
- int resamplerDelay = 32 ;
309
315
if (m_firstProcess) {
310
316
if (m_contractThenExpand) {
311
317
pad = getWindowSourceSize ();
@@ -315,7 +321,6 @@ R3LiveShifter::shift(const float *const *input, float *const *output)
315
321
} else {
316
322
pad = getWindowSourceSize () / 2 ;
317
323
}
318
- pad += resamplerDelay;
319
324
m_log.log (2 , " R3LiveShifter::shift: extending input with pre-pad" , incount, pad);
320
325
for (int c = 0 ; c < m_parameters.channels ; ++c) {
321
326
m_channelData[c]->inbuf ->zero (pad);
@@ -336,7 +341,7 @@ R3LiveShifter::shift(const float *const *input, float *const *output)
336
341
}
337
342
}
338
343
339
- int requiredInOutbuf = int (ceil (incount / outRatio)) + resamplerDelay ;
344
+ int requiredInOutbuf = int (ceil (incount / outRatio));
340
345
generate (requiredInOutbuf);
341
346
342
347
int got = readOut (output, incount, 0 );
@@ -417,8 +422,18 @@ R3LiveShifter::readIn(const float *const *input)
417
422
incount,
418
423
inRatio,
419
424
false );
420
-
425
+
421
426
m_log.log (2 , " R3LiveShifter::readIn: writing to inbuf from resampled data, former read space and samples being added" , m_channelData[0 ]->inbuf ->getReadSpace (), resampleOutput);
427
+
428
+ if (m_firstProcess) {
429
+ int expected = floor (incount * inRatio);
430
+ if (resampleOutput < expected) {
431
+ m_log.log (2 , " R3LiveShifter::readIn: resampler left us short on first process, pre-padding output: expected and obtained" , expected, resampleOutput);
432
+ for (int c = 0 ; c < m_parameters.channels ; ++c) {
433
+ m_channelData[c]->inbuf ->zero (expected - resampleOutput);
434
+ }
435
+ }
436
+ }
422
437
423
438
for (int c = 0 ; c < m_parameters.channels ; ++c) {
424
439
m_channelData[c]->inbuf ->write
@@ -646,7 +661,18 @@ R3LiveShifter::readOut(float *const *output, int outcount, int origin)
646
661
}
647
662
648
663
if (resampledCount < outcount) {
649
- m_log.log (0 , " R3LiveShifter::readOut: WARNING: Failed to obtain enough samples from resampler" , resampledCount, outcount);
664
+ if (m_firstProcess) {
665
+ m_log.log (2 , " R3LiveShifter::readOut: resampler left us short on first process, pre-padding output: expected and obtained" , outcount, resampledCount);
666
+ int prepad = outcount - resampledCount;
667
+ for (int c = 0 ; c < m_parameters.channels ; ++c) {
668
+ v_move (m_channelAssembly.mixdown .data ()[c] + prepad,
669
+ m_channelAssembly.mixdown .data ()[c], resampledCount);
670
+ v_zero (m_channelAssembly.mixdown .data ()[c], prepad);
671
+ }
672
+ resampledCount = outcount;
673
+ } else {
674
+ m_log.log (0 , " R3LiveShifter::readOut: WARNING: Failed to obtain enough samples from resampler" , resampledCount, outcount);
675
+ }
650
676
}
651
677
652
678
if (useMidSide ()) {
0 commit comments