![]() |
Audacity 3.2.0
|
Functions that work with Dither and initialise it. More...
#include "SampleFormat.h"#include "Dither.h"#include <math.h>#include <stdlib.h>#include <string.h>#include "Prefs.h"#include "Internat.h"Go to the source code of this file.
Functions | |
| void | InitDitherers () |
| TranslatableString | GetSampleFormatStr (sampleFormat format) |
| void | ClearSamples (samplePtr dst, sampleFormat format, size_t start, size_t len) |
| void | ReverseSamples (samplePtr dst, sampleFormat format, int start, int len) |
| void | SamplesToFloats (constSamplePtr src, sampleFormat srcFormat, float *dst, size_t len, size_t srcStride, size_t dstStride) |
| Copy samples from any format into the widest format, which is 32 bit float, with no dithering. More... | |
| void | CopySamples (constSamplePtr src, sampleFormat srcFormat, samplePtr dst, sampleFormat dstFormat, size_t len, DitherType ditherType, unsigned int srcStride, unsigned int dstStride) |
| Copy samples from any format to any other format; apply dithering only if narrowing the format. More... | |
Variables | |
| DitherType | gLowQualityDither = DitherType::none |
| These global variables are assigned at application startup or after change of preferences. More... | |
| DitherType | gHighQualityDither = DitherType::shaped |
| static Dither | gDitherAlgorithm |
Functions that work with Dither and initialise it.
This file handles converting between all of the different sample formats that Audacity supports, such as 16-bit, 24-bit (packed into a 32-bit int), and 32-bit float.
Floating-point samples use the range -1.0...1.0, inclusive. Integer formats use the full signed range of their data type, for example 16-bit samples use the range -32768...32767. This means that reading in a wav file and writing it out again ('round tripping'), via floats, is lossless; -32768 equates to -1.0f and 32767 equates to +1.0f - (a little bit). It also means (unfortunately) that writing out +1.0f leads to clipping by 1 LSB. This creates some distortion, but I (MJS) have not been able to measure it, it's so small. Zero is preserved.
http://limpet.net/audacity/bugzilla/show_bug.cgi?id=200 leads to some of the discussions that were held about this.
Note: These things are now handled by the Dither class, which also replaces the CopySamples() method (msmeyer)
Definition in file SampleFormat.cpp.
| void ClearSamples | ( | samplePtr | dst, |
| sampleFormat | format, | ||
| size_t | start, | ||
| size_t | len | ||
| ) |
Definition at line 75 of file SampleFormat.cpp.
References anonymous_namespace{ExportPCM.cpp}::format, SAMPLE_SIZE, and size.
Referenced by RingBuffer::Clear(), AudioIO::DrainRecordBuffers(), Sequence::Get(), WideSampleSequence::GetFloats(), WaveTrack::GetOne(), SampleBlock::GetSamples(), RingBuffer::Put(), and Sequence::SetSamples().
| void CopySamples | ( | constSamplePtr | src, |
| sampleFormat | srcFormat, | ||
| samplePtr | dst, | ||
| sampleFormat | dstFormat, | ||
| size_t | len, | ||
| DitherType | ditherType = gHighQualityDither, |
||
| unsigned int | srcStride = 1, |
||
| unsigned int | dstStride = 1 |
||
| ) |
Copy samples from any format to any other format; apply dithering only if narrowing the format.
| src | address of source samples |
| srcFormat | format of source samples, determines sizeof each one |
| dst | address of floating-point numbers |
| len | count of samples to copy |
| srcStride | how many samples to advance src after copying each one |
| dstString | how many samples to advance dst after copying each one |
| dstFormat | format of destination samples, determines sizeof each one |
| ditherType | choice of dithering algorithm to use if narrowing the format |
| ditherType | default is loaded from a global variable |
Definition at line 109 of file SampleFormat.cpp.
References Dither::Apply(), and gDitherAlgorithm.
Referenced by AUPImportFileHandle::AddSamples(), Sequence::Append(), Sequence::ConvertToSampleFormat(), Sequence::DoAppend(), RingBuffer::Get(), SqliteSampleBlock::GetBlob(), PCMExportProcessor::Process(), Mixer::Process(), RingBuffer::Put(), SamplesToFloats(), and Sequence::SetSamples().
| TranslatableString GetSampleFormatStr | ( | sampleFormat | format | ) |
Definition at line 58 of file SampleFormat.cpp.
References floatSample, anonymous_namespace{ExportPCM.cpp}::format, int16Sample, int24Sample, and XO().
Referenced by FormatMenuTable::OnFormatChange(), and Sequence::Paste().
| void InitDitherers | ( | ) |
Definition at line 51 of file SampleFormat.cpp.
References Dither::BestDitherChoice(), Dither::FastDitherChoice(), gHighQualityDither, and gLowQualityDither.
Referenced by QualityPrefs::Commit(), and AudacityApp::InitPart2().
| void ReverseSamples | ( | samplePtr | dst, |
| sampleFormat | format, | ||
| int | start, | ||
| int | len | ||
| ) |
Definition at line 82 of file SampleFormat.cpp.
References floatSample, anonymous_namespace{ExportPCM.cpp}::format, SAMPLE_SIZE, and size.
Referenced by WaveTrack::GetOne(), and ClipTimeAndPitchSource::Pull().
| void SamplesToFloats | ( | constSamplePtr | src, |
| sampleFormat | srcFormat, | ||
| float * | dst, | ||
| size_t | len, | ||
| size_t | srcStride = 1, |
||
| size_t | dstStride = 1 |
||
| ) |
Copy samples from any format into the widest format, which is 32 bit float, with no dithering.
| src | address of source samples |
| srcFormat | format of source samples, determines sizeof each one |
| dst | address of floating-point numbers |
| len | count of samples to copy |
| srcStride | how many samples to advance src after copying each one |
| dstString | how many samples to advance dst after copying each one |
Definition at line 100 of file SampleFormat.cpp.
References CopySamples(), floatSample, and none.
Referenced by AudioIoCallback::AudioCallback(), SqliteSampleBlock::CalcSummary(), and DoSoftwarePlaythrough().
|
static |
Definition at line 49 of file SampleFormat.cpp.
Referenced by CopySamples().
| DitherType gHighQualityDither = DitherType::shaped |
Definition at line 48 of file SampleFormat.cpp.
Referenced by AUPImportFileHandle::AddSamples(), Sequence::Append(), Sequence::ConvertToSampleFormat(), InitDitherers(), PCMExportProcessor::Process(), Mixer::Process(), and Sequence::SetSamples().
| DitherType gLowQualityDither = DitherType::none |
These global variables are assigned at application startup or after change of preferences.
Definition at line 47 of file SampleFormat.cpp.
Referenced by InitDitherers(), and Mixer::Process().