MCPcopy Create free account
hub / github.com/audacity/audacity / flush

Method flush

lib-src/soundtouch/source/SoundTouch/SoundTouch.cpp:345–385  ·  view source on GitHub ↗

Flushes the last samples from the processing pipeline to the output. Clears also the internal processing buffers. Note: This function is meant for extracting the last samples of a sound stream. This function may introduce additional blank samples in the end of the sound stream, and thus it's not recommended to call this function in the middle of a sound stream.

Source from the content-addressed store, hash-verified

343// of the sound stream, and thus it's not recommended to call this function
344// in the middle of a sound stream.
345void SoundTouch::flush()
346{
347 int i;
348 int nUnprocessed;
349 int nOut;
350 SAMPLETYPE buff[64*2]; // note: allocate 2*64 to cater 64 sample frames of stereo sound
351
352 // check how many samples still await processing, and scale
353 // that by tempo & rate to get expected output sample count
354 nUnprocessed = numUnprocessedSamples();
355 nUnprocessed = (int)((double)nUnprocessed / (tempo * rate) + 0.5);
356
357 nOut = numSamples(); // ready samples currently in buffer ...
358 nOut += nUnprocessed; // ... and how many we expect there to be in the end
359
360 memset(buff, 0, 64 * channels * sizeof(SAMPLETYPE));
361 // "Push" the last active samples out from the processing pipeline by
362 // feeding blank samples into the processing pipeline until new,
363 // processed samples appear in the output (not however, more than
364 // 8ksamples in any case)
365 for (i = 0; i < 128; i ++)
366 {
367 putSamples(buff, 64);
368 if ((int)numSamples() >= nOut)
369 {
370 // Enough new samples have appeared into the output!
371 // As samples come from processing with bigger chunks, now truncate it
372 // back to maximum "nOut" samples to improve duration accuracy
373 adjustAmountOfSamples(nOut);
374
375 // finish
376 break;
377 }
378 }
379
380 // Clear working buffers
381 pRateTransposer->clear();
382 pTDStretch->clearInput();
383 // yet leave the 'tempoChanger' output intouched as that's where the
384 // flushed samples are!
385}
386
387
388// Changes a setting controlling the processing system behaviour. See the

Callers 2

soundtouch_flushFunction · 0.45
processFunction · 0.45

Calls 2

clearInputMethod · 0.80
clearMethod · 0.45

Tested by

no test coverage detected