1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-07-26 09:28:07 +02:00

CopySamples gives more than binary choice of dither algorithm...

... And so a separate function CopySamplesNoDither is not needed
This commit is contained in:
Paul Licameli 2020-11-28 12:53:53 -05:00
parent 6eb5f3ac5b
commit 50a26d9caf
6 changed files with 31 additions and 41 deletions

View File

@ -691,7 +691,7 @@ size_t Mixer::Process(size_t maxToProcess)
mBuffer[0].ptr() + (c * SAMPLE_SIZE(mFormat)), mBuffer[0].ptr() + (c * SAMPLE_SIZE(mFormat)),
mFormat, mFormat,
maxOut, maxOut,
mHighQuality, mHighQuality ? gHighQualityDither : gLowQualityDither,
mNumChannels, mNumChannels,
mNumChannels); mNumChannels);
} }
@ -703,7 +703,7 @@ size_t Mixer::Process(size_t maxToProcess)
mBuffer[c].ptr(), mBuffer[c].ptr(),
mFormat, mFormat,
maxOut, maxOut,
mHighQuality); mHighQuality ? gHighQualityDither : gLowQualityDither);
} }
} }
// MB: this doesn't take warping into account, replaced with code based on mSamplePos // MB: this doesn't take warping into account, replaced with code based on mSamplePos

View File

@ -43,11 +43,10 @@
#include <string.h> #include <string.h>
#include "Prefs.h" #include "Prefs.h"
#include "Dither.h"
#include "Internat.h" #include "Internat.h"
static DitherType gLowQualityDither = DitherType::none; DitherType gLowQualityDither = DitherType::none;
static DitherType gHighQualityDither = DitherType::none; DitherType gHighQualityDither = DitherType::shaped;
static Dither gDitherAlgorithm; static Dither gDitherAlgorithm;
void InitDitherers() void InitDitherers()
@ -104,29 +103,17 @@ void SamplesToFloats(constSamplePtr src, sampleFormat srcFormat,
{ {
CopySamples( src, srcFormat, CopySamples( src, srcFormat,
reinterpret_cast<samplePtr>(dst), floatSample, len, reinterpret_cast<samplePtr>(dst), floatSample, len,
true, // doesn't matter, no dither happens when destination is float DitherType::none,
srcStride, dstStride); srcStride, dstStride);
} }
void CopySamples(constSamplePtr src, sampleFormat srcFormat, void CopySamples(constSamplePtr src, sampleFormat srcFormat,
samplePtr dst, sampleFormat dstFormat, samplePtr dst, sampleFormat dstFormat, size_t len,
unsigned int len, DitherType ditherType, /* = gHighQualityDither */
bool highQuality, /* = true */ unsigned int srcStride /* = 1 */,
unsigned int srcStride /* = 1 */, unsigned int dstStride /* = 1 */)
unsigned int dstStride /* = 1 */)
{ {
gDitherAlgorithm.Apply( gDitherAlgorithm.Apply(
highQuality ? gHighQualityDither : gLowQualityDither, ditherType,
src, srcFormat, dst, dstFormat, len, srcStride, dstStride);
}
void CopySamplesNoDither(samplePtr src, sampleFormat srcFormat,
samplePtr dst, sampleFormat dstFormat,
unsigned int len,
unsigned int srcStride /* = 1 */,
unsigned int dstStride /* = 1 */)
{
gDitherAlgorithm.Apply(
DitherType::none,
src, srcFormat, dst, dstFormat, len, srcStride, dstStride); src, srcFormat, dst, dstFormat, len, srcStride, dstStride);
} }

View File

@ -2,7 +2,7 @@
Audacity: A Digital Audio Editor Audacity: A Digital Audio Editor
SampleFormat.h @file SampleFormat.h
Dominic Mazzoni Dominic Mazzoni
@ -17,11 +17,15 @@
#include <wx/defs.h> #include <wx/defs.h>
#include "audacity/Types.h" #include "audacity/Types.h"
#include "Dither.h"
// //
// Definitions / Meta-Information // Definitions / Meta-Information
// //
//! These global variables are assigned at application startup or after change of preferences.
extern AUDACITY_DLL_API DitherType gLowQualityDither, gHighQualityDither;
#if 0 #if 0
// Moved to audacity/types.h // Moved to audacity/types.h
typedef enum { typedef enum {
@ -138,18 +142,16 @@ void SamplesToFloats(constSamplePtr src, sampleFormat srcFormat,
float *dst, size_t len, size_t srcStride = 1, size_t dstStride = 1); float *dst, size_t len, size_t srcStride = 1, size_t dstStride = 1);
AUDACITY_DLL_API AUDACITY_DLL_API
void CopySamples(constSamplePtr src, sampleFormat srcFormat, //! Copy samples from any format to any other format; apply dithering only if narrowing the format
samplePtr dst, sampleFormat dstFormat, /*!
unsigned int len, bool highQuality=true, @copydetails SamplesToFloats()
unsigned int srcStride=1, @param dstFormat format of destination samples, determines sizeof each one
unsigned int dstStride=1); @param ditherType choice of dithering algorithm to use if narrowing the format
*/
AUDACITY_DLL_API void CopySamples(constSamplePtr src, sampleFormat srcFormat,
void CopySamplesNoDither(samplePtr src, sampleFormat srcFormat, samplePtr dst, sampleFormat dstFormat, size_t len,
samplePtr dst, sampleFormat dstFormat, DitherType ditherType = gHighQualityDither, //!< default is loaded from a global variable
unsigned int len, unsigned int srcStride=1, unsigned int dstStride=1);
unsigned int srcStride=1,
unsigned int dstStride=1);
AUDACITY_DLL_API AUDACITY_DLL_API
void ClearSamples(samplePtr buffer, sampleFormat format, void ClearSamples(samplePtr buffer, sampleFormat format,

View File

@ -1248,7 +1248,7 @@ bool WaveClip::Append(constSamplePtr buffer, sampleFormat format,
mAppendBuffer.ptr() + mAppendBufferLen * SAMPLE_SIZE(seqFormat), mAppendBuffer.ptr() + mAppendBufferLen * SAMPLE_SIZE(seqFormat),
seqFormat, seqFormat,
toCopy, toCopy,
true, // high quality gHighQualityDither,
stride); stride);
mAppendBufferLen += toCopy; mAppendBufferLen += toCopy;

View File

@ -643,12 +643,13 @@ ProgressResult ExportPCM::Export(AudacityProject *project,
CopySamples( CopySamples(
mixed + (c * SAMPLE_SIZE(format)), format, mixed + (c * SAMPLE_SIZE(format)), format,
dither.data() + (c * SAMPLE_SIZE(int24Sample)), int24Sample, dither.data() + (c * SAMPLE_SIZE(int24Sample)), int24Sample,
numSamples, true, info.channels, info.channels numSamples, gHighQualityDither, info.channels, info.channels
); );
CopySamplesNoDither( // Copy back without dither
CopySamples(
dither.data() + (c * SAMPLE_SIZE(int24Sample)), int24Sample, dither.data() + (c * SAMPLE_SIZE(int24Sample)), int24Sample,
mixed + (c * SAMPLE_SIZE(format)), format, mixed + (c * SAMPLE_SIZE(format)), format,
numSamples, info.channels, info.channels); numSamples, DitherType::none, info.channels, info.channels);
} }
} }

View File

@ -1640,7 +1640,7 @@ bool AUPImportFileHandle::AddSamples(const FilePath &blockFilename,
bufptr, bufptr,
format, format,
framesRead, framesRead,
true /* high quality by default */, gHighQualityDither /* high quality by default */,
channels /* source stride */); channels /* source stride */);
} }