Audacity 3.2.0
Classes | Macros | Typedefs | Enumerations | Functions | Variables
SampleFormat.h File Reference
#include "MemoryX.h"
#include <cstdlib>
Include dependency graph for SampleFormat.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

class  SampleFormats
 Two sample formats, remembering format of original source and describing stored format. More...
 
class  SampleBuffer
 
class  GrowableSampleBuffer
 

Macros

#define SAMPLE_SIZE(SampleFormat)   (static_cast<unsigned>(SampleFormat) >> 16)
 
#define SAMPLE_SIZE_DISK(SampleFormat)
 Return the size on disk of one uncompressed sample (bytes) More...
 

Typedefs

using samplePtr = char *
 
using constSamplePtr = const char *
 
typedef enum FillFormat fillFormat
 
using Floats = ArrayOf< float >
 
using FloatBuffers = ArraysOf< float >
 
using Doubles = ArrayOf< double >
 

Enumerations

enum class  sampleFormat : unsigned {
  undefinedSample = 0 , int16Sample = 0x00020001 , int24Sample = 0x00040001 , floatSample = 0x0004000F ,
  narrowestSampleFormat = int16Sample , widestSampleFormat = floatSample
}
 The ordering of these values with operator < agrees with the order of increasing bit width. More...
 
enum class  FillFormat { fillZero = 0 , fillTwo = 2 }
 

Functions

MATH_API TranslatableString GetSampleFormatStr (sampleFormat format)
 
bool operator== (SampleFormats a, SampleFormats b)
 
bool operator!= (SampleFormats a, SampleFormats b)
 
MATH_API 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. More...
 
MATH_API 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. More...
 
MATH_API void ClearSamples (samplePtr buffer, sampleFormat format, size_t start, size_t len)
 
MATH_API void ReverseSamples (samplePtr buffer, sampleFormat format, int start, int len)
 
MATH_API void InitDitherers ()
 

Variables

MATH_API DitherType gLowQualityDither
 These global variables are assigned at application startup or after change of preferences. More...
 
MATH_API DitherType gHighQualityDither
 
constexpr sampleFormat undefinedSample = sampleFormat::undefinedSample
 
constexpr sampleFormat int16Sample = sampleFormat::int16Sample
 
constexpr sampleFormat int24Sample = sampleFormat::int24Sample
 
constexpr sampleFormat floatSample = sampleFormat::floatSample
 
constexpr sampleFormat narrowestSampleFormat = sampleFormat::narrowestSampleFormat
 
constexpr sampleFormat widestSampleFormat = sampleFormat::widestSampleFormat
 

Macro Definition Documentation

◆ SAMPLE_SIZE

#define SAMPLE_SIZE (   SampleFormat)    (static_cast<unsigned>(SampleFormat) >> 16)

Definition at line 52 of file SampleFormat.h.

◆ SAMPLE_SIZE_DISK

#define SAMPLE_SIZE_DISK (   SampleFormat)
Value:
size_t{ 3 } : SAMPLE_SIZE(SampleFormat) )
#define SampleFormat
Definition: Benchmark.cpp:50
constexpr sampleFormat int24Sample
Definition: SampleFormat.h:44
#define SAMPLE_SIZE(SampleFormat)
Definition: SampleFormat.h:52

Return the size on disk of one uncompressed sample (bytes)

Definition at line 67 of file SampleFormat.h.

Typedef Documentation

◆ constSamplePtr

using constSamplePtr = const char *

Definition at line 58 of file SampleFormat.h.

◆ Doubles

using Doubles = ArrayOf<double>

Definition at line 255 of file SampleFormat.h.

◆ fillFormat

typedef enum FillFormat fillFormat

◆ FloatBuffers

using FloatBuffers = ArraysOf<float>

Definition at line 254 of file SampleFormat.h.

◆ Floats

using Floats = ArrayOf<float>

Definition at line 253 of file SampleFormat.h.

◆ samplePtr

using samplePtr = char *

Definition at line 57 of file SampleFormat.h.

Enumeration Type Documentation

◆ FillFormat

enum class FillFormat
strong
Enumerator
fillZero 
fillTwo 

Definition at line 61 of file SampleFormat.h.

61 {
62 fillZero = 0,
63 fillTwo = 2
enum FillFormat fillFormat

◆ sampleFormat

enum class sampleFormat : unsigned
strong

The ordering of these values with operator < agrees with the order of increasing bit width.

These values persist in saved project files, so must not be changed in later program versions

Enumerator
undefinedSample 
int16Sample 
int24Sample 
floatSample 
narrowestSampleFormat 

Two synonyms for previous values that might change if more values were added.

widestSampleFormat 

Definition at line 30 of file SampleFormat.h.

30 : unsigned {
32 int16Sample = 0x00020001,
33 int24Sample = 0x00040001,
34 floatSample = 0x0004000F,
35
39};
constexpr sampleFormat int16Sample
Definition: SampleFormat.h:43
constexpr sampleFormat floatSample
Definition: SampleFormat.h:45
constexpr sampleFormat undefinedSample
Definition: SampleFormat.h:42
constexpr sampleFormat widestSampleFormat
Definition: SampleFormat.h:47
constexpr sampleFormat narrowestSampleFormat
Definition: SampleFormat.h:46

Function Documentation

◆ ClearSamples()

MATH_API void ClearSamples ( samplePtr  buffer,
sampleFormat  format,
size_t  start,
size_t  len 
)

Definition at line 75 of file SampleFormat.cpp.

77{
78 auto size = SAMPLE_SIZE(format);
79 memset(dst + start*size, 0, len*size);
80}

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().

Here is the caller graph for this function:

◆ CopySamples()

MATH_API 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.

Parameters
srcaddress of source samples
srcFormatformat of source samples, determines sizeof each one
dstaddress of floating-point numbers
lencount of samples to copy
srcStridehow many samples to advance src after copying each one
dstStringhow many samples to advance dst after copying each one
dstFormatformat of destination samples, determines sizeof each one
ditherTypechoice of dithering algorithm to use if narrowing the format
Parameters
ditherTypedefault is loaded from a global variable

Definition at line 109 of file SampleFormat.cpp.

114{
116 ditherType,
117 src, srcFormat, dst, dstFormat, len, srcStride, dstStride);
118}
static Dither gDitherAlgorithm
void Apply(DitherType ditherType, constSamplePtr source, sampleFormat sourceFormat, samplePtr dest, sampleFormat destFormat, unsigned int len, unsigned int sourceStride=1, unsigned int destStride=1)
Definition: Dither.cpp:216

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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GetSampleFormatStr()

MATH_API TranslatableString GetSampleFormatStr ( sampleFormat  format)

Definition at line 58 of file SampleFormat.cpp.

59{
60 switch(format) {
61 case int16Sample:
62 /* i18n-hint: Audio data bit depth (precision): 16-bit integers */
63 return XO("16-bit PCM");
64 case int24Sample:
65 /* i18n-hint: Audio data bit depth (precision): 24-bit integers */
66 return XO("24-bit PCM");
67 case floatSample:
68 /* i18n-hint: Audio data bit depth (precision): 32-bit floating point */
69 return XO("32-bit float");
70 }
71 return XO("Unknown format"); // compiler food
72}
XO("Cut/Copy/Paste")

References floatSample, anonymous_namespace{ExportPCM.cpp}::format, int16Sample, int24Sample, and XO().

Referenced by FormatMenuTable::OnFormatChange(), and Sequence::Paste().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ InitDitherers()

MATH_API void InitDitherers ( )

Definition at line 51 of file SampleFormat.cpp.

52{
53 // Read dither preferences
56}
DitherType gLowQualityDither
These global variables are assigned at application startup or after change of preferences.
DitherType gHighQualityDither
static DitherType FastDitherChoice()
Definition: Dither.cpp:410
static DitherType BestDitherChoice()
Definition: Dither.cpp:415

References Dither::BestDitherChoice(), Dither::FastDitherChoice(), gHighQualityDither, and gLowQualityDither.

Referenced by QualityPrefs::Commit(), and AudacityApp::InitPart2().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ operator!=()

bool operator!= ( SampleFormats  a,
SampleFormats  b 
)
inline

Definition at line 115 of file SampleFormat.h.

116{
117 return !(a == b);
118}

◆ operator==()

bool operator== ( SampleFormats  a,
SampleFormats  b 
)
inline

Definition at line 109 of file SampleFormat.h.

110{
111 return a.Effective() == b.Effective() &&
112 a.Stored() == b.Stored();
113}
sampleFormat Stored() const
Definition: SampleFormat.h:91
sampleFormat Effective() const
Definition: SampleFormat.h:90

References SampleFormats::Effective(), and SampleFormats::Stored().

Here is the call graph for this function:

◆ ReverseSamples()

MATH_API void ReverseSamples ( samplePtr  buffer,
sampleFormat  format,
int  start,
int  len 
)

Definition at line 82 of file SampleFormat.cpp.

84{
85 auto size = SAMPLE_SIZE(format);
86 samplePtr first = dst + start * size;
87 samplePtr last = dst + (start + len - 1) * size;
88 enum : size_t { fixedSize = SAMPLE_SIZE(floatSample) };
89 wxASSERT(static_cast<size_t>(size) <= fixedSize);
90 char temp[fixedSize];
91 while (first < last) {
92 memcpy(temp, first, size);
93 memcpy(first, last, size);
94 memcpy(last, temp, size);
95 first += size;
96 last -= size;
97 }
98}
char * samplePtr
Definition: SampleFormat.h:57

References floatSample, anonymous_namespace{ExportPCM.cpp}::format, SAMPLE_SIZE, and size.

Referenced by WaveTrack::GetOne(), and ClipTimeAndPitchSource::Pull().

Here is the caller graph for this function:

◆ SamplesToFloats()

MATH_API 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.

Parameters
srcaddress of source samples
srcFormatformat of source samples, determines sizeof each one
dstaddress of floating-point numbers
lencount of samples to copy
srcStridehow many samples to advance src after copying each one
dstStringhow many samples to advance dst after copying each one

Definition at line 100 of file SampleFormat.cpp.

102{
103 CopySamples( src, srcFormat,
104 reinterpret_cast<samplePtr>(dst), floatSample, len,
106 srcStride, dstStride);
107}
@ none
Definition: Dither.h:20
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.

References CopySamples(), floatSample, and none.

Referenced by AudioIoCallback::AudioCallback(), SqliteSampleBlock::CalcSummary(), and DoSoftwarePlaythrough().

Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ floatSample

constexpr sampleFormat floatSample = sampleFormat::floatSample
constexpr

◆ gHighQualityDither

MATH_API DitherType gHighQualityDither

Definition at line 23 of file SampleFormat.h.

◆ gLowQualityDither

MATH_API DitherType gLowQualityDither
extern

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().

◆ int16Sample

constexpr sampleFormat int16Sample = sampleFormat::int16Sample
constexpr

◆ int24Sample

constexpr sampleFormat int24Sample = sampleFormat::int24Sample
constexpr

◆ narrowestSampleFormat

constexpr sampleFormat narrowestSampleFormat = sampleFormat::narrowestSampleFormat
constexpr

◆ undefinedSample

constexpr sampleFormat undefinedSample = sampleFormat::undefinedSample
constexpr

◆ widestSampleFormat

constexpr sampleFormat widestSampleFormat = sampleFormat::widestSampleFormat
constexpr