23#include <wx/checkbox.h>
24#include <wx/stattext.h>
28#include "../ProjectFileManager.h"
31#include "../widgets/valnum.h"
54 Parameters().Reset(*
this);
55 SetLinearEffectFlag(
false);
71 return XO(
"Sets the peak amplitude of one or more tracks");
90 return ((
mGain ==
false) && (
mDC ==
false));
110 bool bGoodResult =
true;
114 topMsg =
XO(
"Removing DC offset and Normalizing...\n");
116 topMsg =
XO(
"Removing DC offset...\n");
118 topMsg =
XO(
"Normalizing without removing DC offset...\n");
120 topMsg =
XO(
"Not doing anything...\n");
122 for (
auto track : outputs.Get().Selected<
WaveTrack>()) {
124 double trackStart = track->GetStartTime();
125 double trackEnd = track->GetEndTime();
134 wxString trackName = track->GetName();
136 std::vector<float> extents;
137 float maxExtent{ std::numeric_limits<float>::lowest() };
138 std::vector<float> offsets;
140 const auto channels = track->Channels();
142 const bool oneChannel = (channels.size() == 1 ||
mStereoInd);
143 auto msg = oneChannel
145 XO(
"Analyzing: %s").Format(trackName)
148 XO(
"Analyzing first track of stereo pair: %s").Format(trackName);
150 const auto progressReport = [&](
double fraction){
156 for (
auto channel : channels) {
164 extents.push_back(extent);
165 maxExtent = std::max(maxExtent, extent);
166 offsets.push_back(offset);
170 XO(
"Analyzing second track of stereo pair: %s")
178 XO(
"Processing: %s").Format(trackName);
183 XO(
"Processing stereo channels independently: %s")
189 XO(
"Processing first track of stereo pair: %s")
193 auto pOffset = offsets.begin();
194 auto pExtent = extents.begin();
195 for (
const auto channel : channels) {
196 const auto extent = oneChannel ? *pExtent++: maxExtent;
197 if ((extent > 0) &&
mGain)
198 mMult = ratio / extent;
202 (bGoodResult =
ProcessOne(*channel, msg, progress, *pOffset++)))
206 XO(
"Processing second track of stereo pair: %s")
227 S.StartVerticalLay(0);
229 S.StartMultiColumn(2, wxALIGN_CENTER);
231 S.StartVerticalLay(
false);
234 .AddCheckBox(
XXO(
"&Remove DC offset (center on 0.0 vertically)"),
237 S.StartHorizontalLay(wxALIGN_LEFT,
false);
241 .Validator<wxGenericValidator>(&
mGain)
242 .AddCheckBox(
XXO(
"&Normalize peak amplitude to "),
246 .Name(
XO(
"Peak amplitude dB"))
247 .
Validator<FloatingPointValidator<double>>(
250 NumValidatorStyle::ONE_TRAILING_ZERO,
253 .AddTextBox( {}, L
"", 10);
255 wxALIGN_CENTER_VERTICAL | wxALIGN_LEFT);
257 wxALIGN_CENTER_VERTICAL | wxALIGN_LEFT);
259 S.EndHorizontalLay();
263 .AddCheckBox(
XXO(
"N&ormalize stereo channels independently"),
301 const bool gain,
const bool dc,
const double curT0,
const double curT1,
302 float &offset,
float &extent)
308 auto pair = track.
GetMinMax(curT0, curT1);
309 min = pair.first, max = pair.second;
318 min = -1.0, max = 1.0;
324 wxFAIL_MSG(
"Analysing Track when nothing to do!");
325 min = -1.0, max = 1.0;
328 extent = fmax(fabs(
min), fabs(max));
335 const ProgressReport &report,
const double curT0,
const double curT1,
347 auto len = (
end - start).as_double();
372 totalSamples += blockSamples;
381 if (!report((s - start).as_double() / len)) {
386 if (totalSamples > 0)
388 offset = -sum / totalSamples.
as_double();
412 auto len = (
end - start).as_double();
460 for(
decltype(len) i = 0; i < len; i++)
461 sum += (
double)buffer[i];
467 for(
decltype(len) i = 0; i < len; i++) {
468 float adjFrame = (buffer[i] + offset) *
mMult;
469 buffer[i] = adjFrame;
481 if (!
mUIParent->TransferDataFromWindow())
XXO("&Cut/Copy/Paste Toolbar")
size_t limitSampleBufferSize(size_t bufferSize, sampleCount limit)
Generates EffectParameterMethods overrides from variadic template arguments.
ComponentInterfaceSymbol pairs a persistent string identifier used internally with an optional,...
std::shared_ptr< TrackList > mTracks
static bool EnableApply(wxWindow *parent, bool enable=true)
Enable or disable the Apply button of the dialog that contains parent.
bool TotalProgress(double frac, const TranslatableString &={}) const
int GetNumWaveTracks() const
Performs effect computation.
An Effect to bring the peak level up to a chosen level.
static constexpr EffectParameter RemoveDC
bool TransferDataFromWindow(EffectSettings &settings) override
static double AnalyseDataDC(float *buffer, size_t len, double sum)
static bool AnalyseTrackData(const WaveChannel &track, const ProgressReport &report, double curT0, double curT1, float &offset)
EffectType GetType() const override
Type determines how it behaves.
static constexpr EffectParameter StereoInd
bool Process(EffectInstance &instance, EffectSettings &settings) override
std::unique_ptr< EffectEditor > PopulateOrExchange(ShuttleGui &S, EffectInstance &instance, EffectSettingsAccess &access, const EffectOutputs *pOutputs) override
Add controls to effect panel; always succeeds.
bool TransferDataToWindow(const EffectSettings &settings) override
const EffectParameterMethods & Parameters() const override
static constexpr EffectParameter PeakLevel
wxWeakRef< wxWindow > mUIParent
wxCheckBox * mGainCheckBox
ComponentInterfaceSymbol GetSymbol() const override
virtual ~EffectNormalize()
static const ComponentInterfaceSymbol Symbol
void OnUpdateUI(wxCommandEvent &evt)
static constexpr EffectParameter ApplyGain
bool ProcessOne(WaveChannel &track, const TranslatableString &msg, double &progress, float offset)
TranslatableString GetDescription() const override
wxTextCtrl * mLevelTextCtrl
wxCheckBox * mStereoIndCheckBox
static bool AnalyseTrack(const WaveChannel &track, const ProgressReport &report, bool gain, bool dc, double curT0, double curT1, float &offset, float &extent)
void ProcessData(float *buffer, size_t len, float offset)
bool CheckWhetherSkipEffect(const EffectSettings &settings) const override
After Init(), tell whether Process() should be skipped.
ManualPageID ManualPage() const override
Name of a page in the Audacity alpha manual, default is empty.
std::function< bool(double fraction)> ProgressReport
Use this object to copy the input tracks to tentative outputTracks.
Hold values to send to effect output meters.
Interface for manipulations of an Effect's settings.
Derived from ShuttleGuiBase, an Audacity specific class for shuttling data to and from GUI.
Holds a msgid for the translation catalog; may also bind format arguments.
A Validator is an object which checks whether a wxVariant satisfies a certain criterion....
std::pair< float, float > GetMinMax(double t0, double t1, bool mayThrow=true) const
bool Set(constSamplePtr buffer, sampleFormat format, sampleCount start, size_t len, sampleFormat effectiveFormat=widestSampleFormat)
Random-access assignment of a range of samples.
bool GetFloats(float *buffer, sampleCount start, size_t len, fillFormat fill=FillFormat::fillZero, bool mayThrow=true, sampleCount *pNumWithinClips=nullptr) const
"narrow" overload fetches from the unique channel
size_t GetBestBlockSize(sampleCount t) const
A hint for sizing of well aligned fetches.
size_t GetMaxBlockSize() const
A Track that contains audio waveform data.
sampleCount TimeToLongSamples(double t0) const
Positions or offsets within audio files need a wide type.
auto end(const Ptr< Type, BaseDeleter > &p)
Enables range-for.
BuiltinEffectsModule::Registration< EffectNormalize > reg
const Type min
Minimum value.
const Type max
Maximum value.
Externalized state of a plug-in.