diff --git a/src/Mix.cpp b/src/Mix.cpp index 158343c88..8f8eff3c1 100644 --- a/src/Mix.cpp +++ b/src/Mix.cpp @@ -691,7 +691,7 @@ size_t Mixer::Process(size_t maxToProcess) mBuffer[0].ptr() + (c * SAMPLE_SIZE(mFormat)), mFormat, maxOut, - mHighQuality, + mHighQuality ? gHighQualityDither : gLowQualityDither, mNumChannels, mNumChannels); } @@ -703,7 +703,7 @@ size_t Mixer::Process(size_t maxToProcess) mBuffer[c].ptr(), mFormat, maxOut, - mHighQuality); + mHighQuality ? gHighQualityDither : gLowQualityDither); } } // MB: this doesn't take warping into account, replaced with code based on mSamplePos diff --git a/src/SampleFormat.cpp b/src/SampleFormat.cpp index 58f06d568..1d4e7baee 100644 --- a/src/SampleFormat.cpp +++ b/src/SampleFormat.cpp @@ -43,11 +43,10 @@ #include #include "Prefs.h" -#include "Dither.h" #include "Internat.h" -static DitherType gLowQualityDither = DitherType::none; -static DitherType gHighQualityDither = DitherType::none; +DitherType gLowQualityDither = DitherType::none; +DitherType gHighQualityDither = DitherType::shaped; static Dither gDitherAlgorithm; void InitDitherers() @@ -104,29 +103,17 @@ void SamplesToFloats(constSamplePtr src, sampleFormat srcFormat, { CopySamples( src, srcFormat, reinterpret_cast(dst), floatSample, len, - true, // doesn't matter, no dither happens when destination is float + DitherType::none, srcStride, dstStride); } void CopySamples(constSamplePtr src, sampleFormat srcFormat, - samplePtr dst, sampleFormat dstFormat, - unsigned int len, - bool highQuality, /* = true */ - unsigned int srcStride /* = 1 */, - unsigned int dstStride /* = 1 */) + samplePtr dst, sampleFormat dstFormat, size_t len, + DitherType ditherType, /* = gHighQualityDither */ + unsigned int srcStride /* = 1 */, + unsigned int dstStride /* = 1 */) { gDitherAlgorithm.Apply( - highQuality ? gHighQualityDither : gLowQualityDither, - 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, + ditherType, src, srcFormat, dst, dstFormat, len, srcStride, dstStride); } diff --git a/src/SampleFormat.h b/src/SampleFormat.h index 344c8add8..90e88ed1f 100644 --- a/src/SampleFormat.h +++ b/src/SampleFormat.h @@ -2,7 +2,7 @@ Audacity: A Digital Audio Editor - SampleFormat.h + @file SampleFormat.h Dominic Mazzoni @@ -17,11 +17,15 @@ #include #include "audacity/Types.h" +#include "Dither.h" // // 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 // Moved to audacity/types.h 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); AUDACITY_DLL_API -void CopySamples(constSamplePtr src, sampleFormat srcFormat, - samplePtr dst, sampleFormat dstFormat, - unsigned int len, bool highQuality=true, - unsigned int srcStride=1, - unsigned int dstStride=1); - -AUDACITY_DLL_API -void CopySamplesNoDither(samplePtr src, sampleFormat srcFormat, - samplePtr dst, sampleFormat dstFormat, - unsigned int len, - unsigned int srcStride=1, - unsigned int dstStride=1); +//! Copy samples from any format to any other format; apply dithering only if narrowing the format +/*! + @copydetails SamplesToFloats() + @param dstFormat format of destination samples, determines sizeof each one + @param ditherType choice of dithering algorithm to use if narrowing the format + */ +void CopySamples(constSamplePtr src, sampleFormat srcFormat, + samplePtr dst, sampleFormat dstFormat, size_t len, + DitherType ditherType = gHighQualityDither, //!< default is loaded from a global variable + unsigned int srcStride=1, unsigned int dstStride=1); AUDACITY_DLL_API void ClearSamples(samplePtr buffer, sampleFormat format, diff --git a/src/WaveClip.cpp b/src/WaveClip.cpp index 74f0eb53d..b8ba2576d 100644 --- a/src/WaveClip.cpp +++ b/src/WaveClip.cpp @@ -1248,7 +1248,7 @@ bool WaveClip::Append(constSamplePtr buffer, sampleFormat format, mAppendBuffer.ptr() + mAppendBufferLen * SAMPLE_SIZE(seqFormat), seqFormat, toCopy, - true, // high quality + gHighQualityDither, stride); mAppendBufferLen += toCopy; diff --git a/src/export/ExportPCM.cpp b/src/export/ExportPCM.cpp index 529bf3245..2a0258b9b 100644 --- a/src/export/ExportPCM.cpp +++ b/src/export/ExportPCM.cpp @@ -643,12 +643,13 @@ ProgressResult ExportPCM::Export(AudacityProject *project, CopySamples( mixed + (c * SAMPLE_SIZE(format)), format, 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, mixed + (c * SAMPLE_SIZE(format)), format, - numSamples, info.channels, info.channels); + numSamples, DitherType::none, info.channels, info.channels); } } diff --git a/src/import/ImportAUP.cpp b/src/import/ImportAUP.cpp index 0484c7a6c..6228bd6f5 100644 --- a/src/import/ImportAUP.cpp +++ b/src/import/ImportAUP.cpp @@ -1640,7 +1640,7 @@ bool AUPImportFileHandle::AddSamples(const FilePath &blockFilename, bufptr, format, framesRead, - true /* high quality by default */, + gHighQualityDither /* high quality by default */, channels /* source stride */); }