Audacity 3.2.0
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 <math.h>
41#include <stdlib.h>
42#include <string.h>
43
44#include "Prefs.h"
45#include "Internat.h"
46
50
52{
53 // Read dither preferences
56}
57
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}
73
74// TODO: Risky? Assumes 0.0f is represented by 0x00000000;
76 size_t start, size_t len)
77{
78 auto size = SAMPLE_SIZE(format);
79 memset(dst + start*size, 0, len*size);
80}
81
83 int start, int len)
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}
99
101 float *dst, size_t len, size_t srcStride, size_t dstStride)
102{
103 CopySamples( src, srcFormat,
104 reinterpret_cast<samplePtr>(dst), floatSample, len,
106 srcStride, dstStride);
107}
108
110 samplePtr dst, sampleFormat dstFormat, size_t len,
111 DitherType ditherType, /* = gHighQualityDither */
112 unsigned int srcStride /* = 1 */,
113 unsigned int dstStride /* = 1 */)
114{
116 ditherType,
117 src, srcFormat, dst, dstFormat, len, srcStride, dstStride);
118}
DitherType
These ditherers are currently available:
Definition: Dither.h:19
@ shaped
Definition: Dither.h:20
@ none
Definition: Dither.h:20
XO("Cut/Copy/Paste")
TranslatableString GetSampleFormatStr(sampleFormat format)
DitherType gLowQualityDither
These global variables are assigned at application startup or after change of preferences.
void ReverseSamples(samplePtr dst, sampleFormat format, int start, int len)
DitherType gHighQualityDither
void ClearSamples(samplePtr dst, sampleFormat format, size_t start, size_t len)
static Dither gDitherAlgorithm
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.
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.
void InitDitherers()
constexpr sampleFormat int16Sample
Definition: SampleFormat.h:43
constexpr sampleFormat floatSample
Definition: SampleFormat.h:45
constexpr sampleFormat int24Sample
Definition: SampleFormat.h:44
sampleFormat
The ordering of these values with operator < agrees with the order of increasing bit width.
Definition: SampleFormat.h:30
char * samplePtr
Definition: SampleFormat.h:57
#define SAMPLE_SIZE(SampleFormat)
Definition: SampleFormat.h:52
const char * constSamplePtr
Definition: SampleFormat.h:58
This class implements various functions for dithering and is derived from the dither code in the Ardo...
Definition: Dither.h:23
static DitherType FastDitherChoice()
Definition: Dither.cpp:410
static DitherType BestDitherChoice()
Definition: Dither.cpp:415
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
Holds a msgid for the translation catalog; may also bind format arguments.