Audacity  2.2.2
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 <wx/intl.h>
38 #include <math.h>
39 #include <stdio.h>
40 #include <stdlib.h>
41 #include <string.h>
42 
43 #include "SampleFormat.h"
44 #include "Prefs.h"
45 #include "Dither.h"
46 #include "Internat.h"
47 #include "prefs/QualityPrefs.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 _("16-bit PCM");
66  case int24Sample:
67  /* i18n-hint: Audio data bit depth (precision): 24-bit integers */
68  return _("24-bit PCM");
69  case floatSample:
70  /* i18n-hint: Audio data bit depth (precision): 32-bit floating point */
71  return _("32-bit float");
72  }
73  return wxT("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 
102 void CopySamples(samplePtr src, sampleFormat srcFormat,
103  samplePtr dst, sampleFormat dstFormat,
104  unsigned int len,
105  bool highQuality, /* = true */
106  unsigned int srcStride /* = 1 */,
107  unsigned int dstStride /* = 1 */)
108 {
109  gDitherAlgorithm.Apply(
110  highQuality ? gHighQualityDither : gLowQualityDither,
111  src, srcFormat, dst, dstFormat, len, srcStride, dstStride);
112 }
113 
115  samplePtr dst, sampleFormat dstFormat,
116  unsigned int len,
117  unsigned int srcStride /* = 1 */,
118  unsigned int dstStride /* = 1 */)
119 {
120  gDitherAlgorithm.Apply(
122  src, srcFormat, dst, dstFormat, len, srcStride, dstStride);
123 }
void ReverseSamples(samplePtr dst, sampleFormat format, int start, int len)
static DitherType BestDitherChoice()
void Apply(DitherType ditherType, const samplePtr source, sampleFormat sourceFormat, samplePtr dest, sampleFormat destFormat, unsigned int len, unsigned int sourceStride=1, unsigned int destStride=1)
Definition: Dither.cpp:236
void CopySamples(samplePtr src, sampleFormat srcFormat, samplePtr dst, sampleFormat dstFormat, unsigned int len, bool highQuality, unsigned int srcStride, unsigned int dstStride)
static DitherType FastDitherChoice()
#define SAMPLE_SIZE(SampleFormat)
Definition: Types.h:198
Definition: Dither.h:18
This class implements various functions for dithering and is derived from the dither code in the Ardo...
Definition: Dither.h:20
void InitDitherers()
int format
Definition: ExportPCM.cpp:56
static DitherType gHighQualityDither
void CopySamplesNoDither(samplePtr src, sampleFormat srcFormat, samplePtr dst, sampleFormat dstFormat, unsigned int len, unsigned int srcStride, unsigned int dstStride)
sampleFormat
Definition: Types.h:188
char * samplePtr
Definition: Types.h:203
const wxChar * GetSampleFormatStr(sampleFormat format)
_("Move Track &Down")+wxT("\t")+(GetActiveProject() -> GetCommandManager() ->GetKeyFromName(wxT("TrackMoveDown")).Raw()), OnMoveTrack) POPUP_MENU_ITEM(OnMoveTopID, _("Move Track to &Top")+wxT("\t")+(GetActiveProject() ->GetCommandManager() ->GetKeyFromName(wxT("TrackMoveTop")).Raw()), OnMoveTrack) POPUP_MENU_ITEM(OnMoveBottomID, _("Move Track to &Bottom")+wxT("\t")+(GetActiveProject() ->GetCommandManager() ->GetKeyFromName(wxT("TrackMoveBottom")).Raw()), OnMoveTrack)#define SET_TRACK_NAME_PLUGIN_SYMBOLclass SetTrackNameCommand:public AudacityCommand
DitherType
These ditherers are currently available:
Definition: Dither.h:17
void ClearSamples(samplePtr dst, sampleFormat format, size_t start, size_t len)
static Dither gDitherAlgorithm
static DitherType gLowQualityDither