Audacity  3.0.3
Classes | Macros | Typedefs | Enumerations | Functions
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  SampleBuffer
 
class  GrowableSampleBuffer
 

Macros

#define SAMPLE_SIZE(SampleFormat)   (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 *
 
using Floats = ArrayOf< float >
 
using FloatBuffers = ArraysOf< float >
 
using Doubles = ArrayOf< double >
 

Enumerations

enum  sampleFormat : unsigned {
  int16Sample = 0x00020001, int24Sample = 0x00040001, floatSample = 0x0004000F, narrowestSampleFormat = int16Sample,
  widestSampleFormat = floatSample
}
 
enum  fillFormat { fillZero = 0, fillTwo = 2 }
 

Functions

MATH_API TranslatableString GetSampleFormatStr (sampleFormat format)
 
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 ()
 

Macro Definition Documentation

◆ SAMPLE_SIZE

#define SAMPLE_SIZE (   SampleFormat)    (SampleFormat >> 16)

Definition at line 44 of file SampleFormat.h.

◆ SAMPLE_SIZE_DISK

#define SAMPLE_SIZE_DISK (   SampleFormat)
Value:
size_t{ 3 } : SAMPLE_SIZE(SampleFormat) )

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

Definition at line 59 of file SampleFormat.h.

Typedef Documentation

◆ constSamplePtr

using constSamplePtr = const char *

Definition at line 50 of file SampleFormat.h.

◆ Doubles

using Doubles = ArrayOf<double>

Definition at line 188 of file SampleFormat.h.

◆ FloatBuffers

using FloatBuffers = ArraysOf<float>

Definition at line 187 of file SampleFormat.h.

◆ Floats

using Floats = ArrayOf<float>

Definition at line 186 of file SampleFormat.h.

◆ samplePtr

using samplePtr = char *

Definition at line 49 of file SampleFormat.h.

Enumeration Type Documentation

◆ fillFormat

enum fillFormat
Enumerator
fillZero 
fillTwo 

Definition at line 53 of file SampleFormat.h.

53  {
54  fillZero = 0,
55  fillTwo = 2
56 }fillFormat;

◆ sampleFormat

enum sampleFormat : unsigned
Enumerator
int16Sample 

The increasing sequence of these enum values must correspond to the increasing data type width These values persist in saved project files, so must not be changed in later program versions

int24Sample 
floatSample 
narrowestSampleFormat 

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

widestSampleFormat 

Definition at line 28 of file SampleFormat.h.

29 {
32  int16Sample = 0x00020001,
33  int24Sample = 0x00040001,
34  floatSample = 0x0004000F,
35 
39 };

Function Documentation

◆ ClearSamples()

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

Definition at line 77 of file SampleFormat.cpp.

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

References format, SAMPLE_SIZE, and size.

Referenced by RingBuffer::Clear(), AudioIO::DrainRecordBuffers(), Sequence::Get(), WaveTrack::Get(), 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 111 of file SampleFormat.cpp.

116 {
118  ditherType,
119  src, srcFormat, dst, dstFormat, len, srcStride, dstStride);
120 }

References Dither::Apply(), and gDitherAlgorithm.

Referenced by AUPImportFileHandle::AddSamples(), WaveClip::Append(), Sequence::ConvertToSampleFormat(), Sequence::DoAppend(), ExportPCM::Export(), RingBuffer::Get(), SqliteSampleBlock::GetBlob(), 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 60 of file SampleFormat.cpp.

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

References floatSample, format, int16Sample, int24Sample, and XO.

Referenced by FormatMenuTable::OnFormatChange(), Sequence::Paste(), and anonymous_namespace{WaveTrackControls.cpp}::Status2DrawFunction().

Here is the caller graph for this function:

◆ InitDitherers()

MATH_API void InitDitherers ( )

Definition at line 53 of file SampleFormat.cpp.

54 {
55  // Read dither preferences
58 }

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:

◆ ReverseSamples()

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

Definition at line 84 of file SampleFormat.cpp.

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

References floatSample, format, SAMPLE_SIZE, and size.

Referenced by Mixer::MixSameRate(), and Mixer::MixVariableRates().

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 102 of file SampleFormat.cpp.

104 {
105  CopySamples( src, srcFormat,
106  reinterpret_cast<samplePtr>(dst), floatSample, len,
108  srcStride, dstStride);
109 }

References CopySamples(), floatSample, and none.

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

Here is the call graph for this function:
Here is the caller graph for this function:
size
size_t size
Definition: ffmpeg-2.3.6-single-header.h:412
narrowestSampleFormat
@ narrowestSampleFormat
Two synonyms for previous values that might change if more values were added.
Definition: SampleFormat.h:37
Dither::BestDitherChoice
static DitherType BestDitherChoice()
Definition: Dither.cpp:415
SampleFormat
#define SampleFormat
Definition: Benchmark.cpp:54
fillFormat
fillFormat
Definition: SampleFormat.h:53
fillTwo
@ fillTwo
Definition: SampleFormat.h:55
Dither::Apply
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
SAMPLE_SIZE
#define SAMPLE_SIZE(SampleFormat)
Definition: SampleFormat.h:44
XO
#define XO(s)
Definition: Internat.h:31
int24Sample
@ int24Sample
Definition: SampleFormat.h:33
fillZero
@ fillZero
Definition: SampleFormat.h:54
floatSample
@ floatSample
Definition: SampleFormat.h:34
widestSampleFormat
@ widestSampleFormat
Definition: SampleFormat.h:38
CopySamples
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.
Definition: SampleFormat.cpp:111
int16Sample
@ int16Sample
Definition: SampleFormat.h:32
none
@ none
Definition: Dither.h:20
format
int format
Definition: ExportPCM.cpp:56
samplePtr
char * samplePtr
Definition: SampleFormat.h:49
gDitherAlgorithm
static Dither gDitherAlgorithm
Definition: SampleFormat.cpp:51
Dither::FastDitherChoice
static DitherType FastDitherChoice()
Definition: Dither.cpp:410
gLowQualityDither
DitherType gLowQualityDither
Definition: SampleFormat.cpp:49
gHighQualityDither
DitherType gHighQualityDither
Definition: SampleFormat.cpp:50