Audacity 3.2.0
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 or later. 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
32Resample::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
54static 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
61static 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
87std::pair<size_t, size_t>
88 Resample::Process(double factor,
89 const 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
114void Resample::SetMethod(const bool useBestMethod)
115{
116 if (useBestMethod)
118 else
120}
wxT("CloseDown"))
XO("Cut/Copy/Paste")
static const std::initializer_list< EnumValueSymbol > methodNames
Definition: Resample.cpp:54
static auto intChoicesMethod
Definition: Resample.cpp:61
Enum ReadEnum() const
Definition: Prefs.h:534
Resample(const bool useBestMethod, const double dMinFactor, const double dMaxFactor)
Definition: Resample.cpp:32
~Resample()
Definition: Resample.cpp:49
bool mbWantConstRateResampling
Definition: Resample.h:87
static EnumSetting< int > FastMethodSetting
Definition: Resample.h:48
void SetMethod(const bool useBestMethod)
Definition: Resample.cpp:114
soxrHandle mHandle
Definition: Resample.h:86
int mMethod
Definition: Resample.h:85
std::pair< size_t, size_t > Process(double factor, const 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
static EnumSetting< int > BestMethodSetting
Definition: Resample.h:49