Audacity  3.0.3
SampleFormat.cpp
Go to the documentation of this file.
1 /**********************************************************************
2 
3  Audacity: A Digital Audio Editor
4 
5  SampleFormat.h
6 
7  Dominic Mazzoni
8 
9 *******************************************************************//*******************************************************************/
36 
37 #include "SampleFormat.h"
38 #include "Dither.h" // CYCLE
39 
40 #include <wx/intl.h>
41 #include <math.h>
42 #include <stdio.h>
43 #include <stdlib.h>
44 #include <string.h>
45 
46 #include "Prefs.h"
47 #include "Internat.h"
48 
52 
54 {
55  // Read dither preferences
58 }
59 
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 }
75 
76 // TODO: Risky? Assumes 0.0f is represented by 0x00000000;
78  size_t start, size_t len)
79 {
80  auto size = SAMPLE_SIZE(format);
81  memset(dst + start*size, 0, len*size);
82 }
83 
85  int start, int len)
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 }
101 
103  float *dst, size_t len, size_t srcStride, size_t dstStride)
104 {
105  CopySamples( src, srcFormat,
106  reinterpret_cast<samplePtr>(dst), floatSample, len,
108  srcStride, dstStride);
109 }
110 
112  samplePtr dst, sampleFormat dstFormat, size_t len,
113  DitherType ditherType, /* = gHighQualityDither */
114  unsigned int srcStride /* = 1 */,
115  unsigned int dstStride /* = 1 */)
116 {
118  ditherType,
119  src, srcFormat, dst, dstFormat, len, srcStride, dstStride);
120 }
size
size_t size
Definition: ffmpeg-2.3.6-single-header.h:412
Dither::BestDitherChoice
static DitherType BestDitherChoice()
Definition: Dither.cpp:415
ClearSamples
void ClearSamples(samplePtr dst, sampleFormat format, size_t start, size_t len)
Definition: SampleFormat.cpp:77
TranslatableString
Holds a msgid for the translation catalog; may also bind format arguments.
Definition: TranslatableString.h:32
Dither
This class implements various functions for dithering and is derived from the dither code in the Ardo...
Definition: Dither.h:23
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
ReverseSamples
void ReverseSamples(samplePtr dst, sampleFormat format, int start, int len)
Definition: SampleFormat.cpp:84
int24Sample
@ int24Sample
Definition: SampleFormat.h:33
shaped
@ shaped
Definition: Dither.h:20
SamplesToFloats
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.
Definition: SampleFormat.cpp:102
floatSample
@ floatSample
Definition: SampleFormat.h:34
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
constSamplePtr
const char * constSamplePtr
Definition: SampleFormat.h:50
none
@ none
Definition: Dither.h:20
format
int format
Definition: ExportPCM.cpp:56
Internat.h
sampleFormat
sampleFormat
Definition: SampleFormat.h:29
samplePtr
char * samplePtr
Definition: SampleFormat.h:49
DitherType
DitherType
These ditherers are currently available:
Definition: Dither.h:19
gDitherAlgorithm
static Dither gDitherAlgorithm
Definition: SampleFormat.cpp:51
InitDitherers
void InitDitherers()
Definition: SampleFormat.cpp:53
Dither::FastDitherChoice
static DitherType FastDitherChoice()
Definition: Dither.cpp:410
gLowQualityDither
DitherType gLowQualityDither
Definition: SampleFormat.cpp:49
gHighQualityDither
DitherType gHighQualityDither
Definition: SampleFormat.cpp:50
Prefs.h
GetSampleFormatStr
TranslatableString GetSampleFormatStr(sampleFormat format)
Definition: SampleFormat.cpp:60
SampleFormat.h
Dither.h