Eliminate CopySamples calls where destination is always float...

.. Call the function SamplesToFloats instead, or in one place, where source
is also always float, just do memcpy.

Dithering never happened in these cases.
This commit is contained in:
Paul Licameli 2020-11-27 21:06:39 -05:00
parent bdc5efc7ea
commit 6eb5f3ac5b
6 changed files with 34 additions and 18 deletions

View File

@ -3622,11 +3622,9 @@ static void DoSoftwarePlaythrough(const void *inputBuffer,
{
for (unsigned int i=0; i < inputChannels; i++) {
samplePtr inputPtr = ((samplePtr)inputBuffer) + (i * SAMPLE_SIZE(inputFormat));
samplePtr outputPtr = ((samplePtr)outputBuffer) + (i * SAMPLE_SIZE(floatSample));
CopySamples(inputPtr, inputFormat,
(samplePtr)outputPtr, floatSample,
len, true, inputChannels, 2);
SamplesToFloats(inputPtr, inputFormat,
outputBuffer + i, len, inputChannels, 2);
}
// One mono input channel goes to both output channels...
@ -4411,9 +4409,8 @@ int AudioIoCallback::AudioCallback(const void *inputBuffer, void *outputBuffer,
inputSamples = (float *) inputBuffer;
}
else {
CopySamples((samplePtr)inputBuffer, mCaptureFormat,
(samplePtr)tempFloats, floatSample,
framesPerBuffer * numCaptureChannels);
SamplesToFloats(reinterpret_cast<constSamplePtr>(inputBuffer),
mCaptureFormat, tempFloats, framesPerBuffer * numCaptureChannels);
inputSamples = tempFloats;
}

View File

@ -99,6 +99,15 @@ void ReverseSamples(samplePtr dst, sampleFormat format,
}
}
void SamplesToFloats(constSamplePtr src, sampleFormat srcFormat,
float *dst, size_t len, size_t srcStride, size_t dstStride)
{
CopySamples( src, srcFormat,
reinterpret_cast<samplePtr>(dst), floatSample, len,
true, // doesn't matter, no dither happens when destination is float
srcStride, dstStride);
}
void CopySamples(constSamplePtr src, sampleFormat srcFormat,
samplePtr dst, sampleFormat dstFormat,
unsigned int len,

View File

@ -124,6 +124,19 @@ private:
// Copying, Converting and Clearing Samples
//
AUDACITY_DLL_API
//! Copy samples from any format into the widest format, which is 32 bit float, with no dithering
/*!
@param src address of source samples
@param srcFormat format of source samples, determines sizeof each one
@param dst address of floating-point numbers
@param len count of samples to copy
@param srcStride how many samples to advance src after copying each one
@param dstString how many samples to advance dst after copying each one
*/
void SamplesToFloats(constSamplePtr src, sampleFormat srcFormat,
float *dst, size_t len, size_t srcStride = 1, size_t dstStride = 1);
AUDACITY_DLL_API
void CopySamples(constSamplePtr src, sampleFormat srcFormat,
samplePtr dst, sampleFormat dstFormat,

View File

@ -806,11 +806,8 @@ void SqliteSampleBlock::CalcSummary(Sizes sizes)
else
{
samplebuffer.reinit((unsigned) mSampleCount);
CopySamples(mSamples.get(),
mSampleFormat,
(samplePtr) samplebuffer.get(),
floatSample,
mSampleCount);
SamplesToFloats(mSamples.get(), mSampleFormat,
samplebuffer.get(), mSampleCount);
samples = samplebuffer.get();
}

View File

@ -525,9 +525,9 @@ bool WaveClip::GetWaveDisplay(WaveDisplay &display, double t0,
else {
b.reinit(len);
pb = b.get();
CopySamples(mAppendBuffer.ptr() + sLeft * SAMPLE_SIZE(seqFormat),
seqFormat,
(samplePtr)pb, floatSample, len);
SamplesToFloats(
mAppendBuffer.ptr() + sLeft * SAMPLE_SIZE(seqFormat),
seqFormat, pb, len);
}
float theMax, theMin, sumsq;

View File

@ -29,6 +29,7 @@ effects from this one class.
#include <algorithm>
#include <cmath>
#include <cstring>
#include <locale.h>
@ -2462,9 +2463,8 @@ int NyquistEffect::GetCallback(float *buffer, int ch,
// We have guaranteed above that this is nonnegative and bounded by
// mCurBufferLen[ch]:
auto offset = ( mCurStart[ch] + start - mCurBufferStart[ch] ).as_size_t();
CopySamples(mCurBuffer[ch].ptr() + offset*SAMPLE_SIZE(floatSample), floatSample,
(samplePtr)buffer, floatSample,
len);
const void *src = mCurBuffer[ch].ptr() + offset*SAMPLE_SIZE(floatSample);
std::memcpy(buffer, src, len * sizeof(float));
if (ch == 0) {
double progress = mScale *