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 
51 
53 {
54  // Read dither preferences
56  gPrefs->Read(wxT("/Quality/DitherAlgorithm"), (long)Dither::none);
57 
59  gPrefs->Read(wxT("/Quality/HQDitherAlgorithm"), (long)Dither::shaped);
60 }
61 
62 const wxChar *GetSampleFormatStr(sampleFormat format)
63 {
64  switch(format) {
65  case int16Sample:
66  /* i18n-hint: Audio data bit depth (precision): 16-bit integers */
67  return _("16-bit PCM");
68  case int24Sample:
69  /* i18n-hint: Audio data bit depth (precision): 24-bit integers */
70  return _("24-bit PCM");
71  case floatSample:
72  /* i18n-hint: Audio data bit depth (precision): 32-bit floating point */
73  return _("32-bit float");
74  }
75  return wxT("Unknown format"); // compiler food
76 }
77 
78 // TODO: Risky? Assumes 0.0f is represented by 0x00000000;
79 void ClearSamples(samplePtr dst, sampleFormat format,
80  size_t start, size_t len)
81 {
82  auto size = SAMPLE_SIZE(format);
83  memset(dst + start*size, 0, len*size);
84 }
85 
86 void ReverseSamples(samplePtr dst, sampleFormat format,
87  int start, int len)
88 {
89  auto size = SAMPLE_SIZE(format);
90  samplePtr first = dst + start * size;
91  samplePtr last = dst + (start + len - 1) * size;
92  enum : size_t { fixedSize = SAMPLE_SIZE(floatSample) };
93  wxASSERT(size <= fixedSize);
94  char temp[fixedSize];
95  while (first < last) {
96  memcpy(temp, first, size);
97  memcpy(first, last, size);
98  memcpy(last, temp, size);
99  first += size;
100  last -= size;
101  }
102 }
103 
104 void CopySamples(samplePtr src, sampleFormat srcFormat,
105  samplePtr dst, sampleFormat dstFormat,
106  unsigned int len,
107  bool highQuality, /* = true */
108  unsigned int srcStride /* = 1 */,
109  unsigned int dstStride /* = 1 */)
110 {
111  gDitherAlgorithm.Apply(
112  highQuality ? gHighQualityDither : gLowQualityDither,
113  src, srcFormat, dst, dstFormat, len, srcStride, dstStride);
114 }
115 
116 void CopySamplesNoDither(samplePtr src, sampleFormat srcFormat,
117  samplePtr dst, sampleFormat dstFormat,
118  unsigned int len,
119  unsigned int srcStride /* = 1 */,
120  unsigned int dstStride /* = 1 */)
121 {
122  gDitherAlgorithm.Apply(
123  Dither::none,
124  src, srcFormat, dst, dstFormat, len, srcStride, dstStride);
125 }
DitherType
These ditherers are currently available:
Definition: Dither.h:23
void ReverseSamples(samplePtr dst, sampleFormat format, int start, int len)
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)
This class implements various functions for dithering and is derived from the dither code in the Ardo...
Definition: Dither.h:16
void InitDitherers()
wxFileConfig * gPrefs
Definition: Prefs.cpp:72
int format
Definition: ExportPCM.cpp:56
static Dither::DitherType gLowQualityDither
void CopySamplesNoDither(samplePtr src, sampleFormat srcFormat, samplePtr dst, sampleFormat dstFormat, unsigned int len, unsigned int srcStride, unsigned int dstStride)
const wxChar * GetSampleFormatStr(sampleFormat format)
_("Move Track &Down")+wxT("\t")+(GetActiveProject() -> GetCommandManager() ->GetKeyFromName(wxT("TrackMoveDown"))), OnMoveTrack) POPUP_MENU_ITEM(OnMoveTopID, _("Move Track to &Top")+wxT("\t")+(GetActiveProject() ->GetCommandManager() ->GetKeyFromName(wxT("TrackMoveTop"))), OnMoveTrack) POPUP_MENU_ITEM(OnMoveBottomID, _("Move Track to &Bottom")+wxT("\t")+(GetActiveProject() ->GetCommandManager() ->GetKeyFromName(wxT("TrackMoveBottom"))), OnMoveTrack) void TrackMenuTable::OnSetName(wxCommandEvent &)
void ClearSamples(samplePtr dst, sampleFormat format, size_t start, size_t len)
static Dither gDitherAlgorithm
static Dither::DitherType gHighQualityDither