Audacity  3.0.3
Resample.cpp
Go to the documentation of this file.
1 /**********************************************************************
2 
3  Audacity: A Digital Audio Editor
4  Audacity(R) is copyright (c) 1999-2012 Audacity Team.
5  License: GPL v2. See License.txt.
6 
7  Resample.cpp
8  Dominic Mazzoni, Rob Sykes, Vaughan Johnson
9 
10 ******************************************************************//*******************************************************************/
24 
25 #include "Resample.h"
26 #include "Prefs.h"
27 #include "Internat.h"
28 #include "ComponentInterface.h"
29 
30 #include <soxr.h>
31 
32 Resample::Resample(const bool useBestMethod, const double dMinFactor, const double dMaxFactor)
33 {
34  this->SetMethod(useBestMethod);
35  soxr_quality_spec_t q_spec;
36  if (dMinFactor == dMaxFactor)
37  {
38  mbWantConstRateResampling = true; // constant rate resampling
39  q_spec = soxr_quality_spec("\0\1\4\6"[mMethod], 0);
40  }
41  else
42  {
43  mbWantConstRateResampling = false; // variable rate resampling
44  q_spec = soxr_quality_spec(SOXR_HQ, SOXR_VR);
45  }
46  mHandle.reset(soxr_create(1, dMinFactor, 1, 0, 0, &q_spec, 0));
47 }
48 
50 {
51 }
52 
54 static const std::initializer_list<EnumValueSymbol> methodNames{
55  { wxT("LowQuality"), XO("Low Quality (Fastest)") },
56  { wxT("MediumQuality"), XO("Medium Quality") },
57  { wxT("HighQuality"), XO("High Quality") },
58  { wxT("BestQuality"), XO("Best Quality (Slowest)") }
59 };
60 
61 static auto intChoicesMethod = {
62  0, 1, 2, 3
63 };
64 
66  wxT("/Quality/LibsoxrSampleRateConverterChoice"),
68  1, // Medium Quality
69 
70  // for migrating old preferences:
72  wxT("/Quality/LibsoxrSampleRateConverter")
73 };
74 
76 {
77  wxT("/Quality/LibsoxrHQSampleRateConverterChoice"),
79  3, // Best Quality,
80 
81  // for migrating old preferences:
83  wxT("/Quality/LibsoxrHQSampleRateConverter")
84 };
85 
87 std::pair<size_t, size_t>
88  Resample::Process(double factor,
89  float *inBuffer,
90  size_t inBufferLen,
91  bool lastFlag,
92  float *outBuffer,
93  size_t outBufferLen)
94 {
95  size_t idone, odone;
97  {
98  soxr_process(mHandle.get(),
99  inBuffer , (lastFlag? ~inBufferLen : inBufferLen), &idone,
100  outBuffer, outBufferLen, &odone);
101  }
102  else
103  {
104  soxr_set_io_ratio(mHandle.get(), 1/factor, 0);
105 
106  inBufferLen = lastFlag? ~inBufferLen : inBufferLen;
107  soxr_process(mHandle.get(),
108  inBuffer , inBufferLen , &idone,
109  outBuffer, outBufferLen, &odone);
110  }
111  return { idone, odone };
112 }
113 
114 void Resample::SetMethod(const bool useBestMethod)
115 {
116  if (useBestMethod)
118  else
120 }
Resample::Resample
Resample(const bool useBestMethod, const double dMinFactor, const double dMaxFactor)
Definition: Resample.cpp:32
Resample::FastMethodSetting
static EnumSetting< int > FastMethodSetting
Definition: Resample.h:42
Resample::mMethod
int mMethod
Definition: Resample.h:79
XO
#define XO(s)
Definition: Internat.h:31
Resample::mHandle
soxrHandle mHandle
Definition: Resample.h:80
Resample::~Resample
~Resample()
Definition: Resample.cpp:49
ComponentInterface.h
Resample::mbWantConstRateResampling
bool mbWantConstRateResampling
Definition: Resample.h:81
Internat.h
EnumSetting::ReadEnum
Enum ReadEnum() const
Definition: Prefs.h:370
intChoicesMethod
static auto intChoicesMethod
Definition: Resample.cpp:61
Resample::SetMethod
void SetMethod(const bool useBestMethod)
Definition: Resample.cpp:114
EnumSetting< int >
Resample::Process
std::pair< size_t, size_t > Process(double factor, float *inBuffer, size_t inBufferLen, bool lastFlag, float *outBuffer, size_t outBufferLen)
Main processing function. Resamples from the input buffer to the output buffer.
Definition: Resample.cpp:88
Prefs.h
methodNames
static const std::initializer_list< EnumValueSymbol > methodNames
Definition: Resample.cpp:54
Resample::BestMethodSetting
static EnumSetting< int > BestMethodSetting
Definition: Resample.h:43
Resample.h