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 <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}
DitherType
These ditherers are currently available:
Definition: Dither.h:19
@ shaped
Definition: Dither.h:20
@ none
Definition: Dither.h:20
int format
Definition: ExportPCM.cpp:56
#define XO(s)
Definition: Internat.h:31
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()
sampleFormat
Definition: SampleFormat.h:29
@ floatSample
Definition: SampleFormat.h:34
@ int16Sample
Definition: SampleFormat.h:32
@ int24Sample
Definition: SampleFormat.h:33
char * samplePtr
Definition: SampleFormat.h:49
#define SAMPLE_SIZE(SampleFormat)
Definition: SampleFormat.h:44
const char * constSamplePtr
Definition: SampleFormat.h:50
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.