Audacity  2.3.1
Functions | Variables
SampleFormat.cpp File Reference

Functions that work with Dither and initialise it. More...

#include <wx/intl.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "SampleFormat.h"
#include "Prefs.h"
#include "Dither.h"
#include "Internat.h"
#include "prefs/QualityPrefs.h"

Go to the source code of this file.

Functions

void InitDitherers ()
 
const wxChar * GetSampleFormatStr (sampleFormat format)
 
void ClearSamples (samplePtr dst, sampleFormat format, size_t start, size_t len)
 
void ReverseSamples (samplePtr dst, sampleFormat format, int start, int len)
 
void CopySamples (samplePtr src, sampleFormat srcFormat, samplePtr dst, sampleFormat dstFormat, unsigned int len, bool highQuality, unsigned int srcStride, unsigned int dstStride)
 
void CopySamplesNoDither (samplePtr src, sampleFormat srcFormat, samplePtr dst, sampleFormat dstFormat, unsigned int len, unsigned int srcStride, unsigned int dstStride)
 

Variables

static DitherType gLowQualityDither = DitherType::none
 
static DitherType gHighQualityDither = DitherType::none
 
static Dither gDitherAlgorithm
 

Detailed Description

Functions that work with Dither and initialise it.

This file handles converting between all of the different sample formats that Audacity supports, such as 16-bit, 24-bit (packed into a 32-bit int), and 32-bit float.

Floating-point samples use the range -1.0...1.0, inclusive. Integer formats use the full signed range of their data type, for example 16-bit samples use the range -32768...32767. This means that reading in a wav file and writing it out again ('round tripping'), via floats, is lossless; -32768 equates to -1.0f and 32767 equates to +1.0f - (a little bit). It also means (unfortunatly) that writing out +1.0f leads to clipping by 1 LSB. This creates some distortion, but I (MJS) have not been able to measure it, it's so small. Zero is preserved.

http://limpet.net/audacity/bugzilla/show_bug.cgi?id=200 leads to some of the discussions that were held about this.

Note: These things are now handled by the Dither class, which also replaces the CopySamples() method (msmeyer)

Definition in file SampleFormat.cpp.

Function Documentation

void ClearSamples ( samplePtr  dst,
sampleFormat  format,
size_t  start,
size_t  len 
)
void CopySamples ( samplePtr  src,
sampleFormat  srcFormat,
samplePtr  dst,
sampleFormat  dstFormat,
unsigned int  len,
bool  highQuality,
unsigned int  srcStride,
unsigned int  dstStride 
)

Definition at line 102 of file SampleFormat.cpp.

References Dither::Apply(), gHighQualityDither, and gLowQualityDither.

Referenced by Sequence::Append(), WaveClip::Append(), ODPCMAliasBlockFile::CalcSummary(), ODDecodeBlockFile::CalcSummary(), BlockFile::CalcSummary(), BlockFile::CommonReadData(), ComputeLegacySummaryInfo(), Sequence::ConvertToSampleFormat(), DoSoftwarePlaythrough(), RingBuffer::Get(), NyquistEffect::GetCallback(), WaveClip::GetWaveDisplay(), Mixer::Process(), RingBuffer::Put(), BlockFile::Read256(), BlockFile::Read64K(), SimpleBlockFile::ReadData(), AudioIoCallback::SendVuInputMeterData(), and Sequence::SetSamples().

108 {
110  highQuality ? gHighQualityDither : gLowQualityDither,
111  src, srcFormat, dst, dstFormat, len, srcStride, dstStride);
112 }
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
static DitherType gHighQualityDither
static Dither gDitherAlgorithm
static DitherType gLowQualityDither
void CopySamplesNoDither ( samplePtr  src,
sampleFormat  srcFormat,
samplePtr  dst,
sampleFormat  dstFormat,
unsigned int  len,
unsigned int  srcStride,
unsigned int  dstStride 
)

Definition at line 114 of file SampleFormat.cpp.

References Dither::Apply(), and none.

119 {
122  src, srcFormat, dst, dstFormat, len, srcStride, dstStride);
123 }
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
Definition: Dither.h:18
static Dither gDitherAlgorithm
const wxChar* GetSampleFormatStr ( sampleFormat  format)

Definition at line 60 of file SampleFormat.cpp.

References _(), floatSample, int16Sample, and int24Sample.

Referenced by Sequence::Paste(), and TrackInfo::Status2DrawFunction().

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 }
int format
Definition: ExportPCM.cpp:56
_("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
void InitDitherers ( )

Definition at line 53 of file SampleFormat.cpp.

References QualityPrefs::BestDitherChoice(), QualityPrefs::FastDitherChoice(), gHighQualityDither, and gLowQualityDither.

Referenced by QualityPrefs::Commit(), and AudacityApp::OnInit().

54 {
55  // Read dither preferences
58 }
static DitherType BestDitherChoice()
static DitherType FastDitherChoice()
static DitherType gHighQualityDither
static DitherType gLowQualityDither
void ReverseSamples ( samplePtr  dst,
sampleFormat  format,
int  start,
int  len 
)

Definition at line 84 of file SampleFormat.cpp.

References floatSample, and SAMPLE_SIZE.

Referenced by Mixer::MixSameRate(), and Mixer::MixVariableRates().

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 }
#define SAMPLE_SIZE(SampleFormat)
Definition: Types.h:198
int format
Definition: ExportPCM.cpp:56
char * samplePtr
Definition: Types.h:203

Variable Documentation

Dither gDitherAlgorithm
static

Definition at line 51 of file SampleFormat.cpp.

DitherType gHighQualityDither = DitherType::none
static

Definition at line 50 of file SampleFormat.cpp.

Referenced by CopySamples(), and InitDitherers().

DitherType gLowQualityDither = DitherType::none
static

Definition at line 49 of file SampleFormat.cpp.

Referenced by CopySamples(), and InitDitherers().