23#include <wx/checkbox.h>
24#include <wx/stattext.h>
28#include "../ProjectFileManager.h"
32#include "../widgets/valnum.h"
55 Parameters().Reset(*
this);
56 SetLinearEffectFlag(
false);
72 return XO(
"Sets the peak amplitude of one or more tracks");
91 return ((
mGain ==
false) && (
mDC ==
false));
111 bool bGoodResult =
true;
115 topMsg =
XO(
"Removing DC offset and Normalizing...\n");
117 topMsg =
XO(
"Removing DC offset...\n");
119 topMsg =
XO(
"Normalizing without removing DC offset...\n");
121 topMsg =
XO(
"Not doing anything...\n");
123 for (
auto track : outputs.Get().Selected<
WaveTrack>()) {
125 double trackStart = track->GetStartTime();
126 double trackEnd = track->GetEndTime();
135 wxString trackName = track->GetName();
137 std::vector<float> extents;
138 float maxExtent{ std::numeric_limits<float>::lowest() };
139 std::vector<float> offsets;
141 const auto channels = track->Channels();
143 const bool oneChannel = (channels.size() == 1 ||
mStereoInd);
144 auto msg = oneChannel
146 XO(
"Analyzing: %s").Format(trackName)
149 XO(
"Analyzing first track of stereo pair: %s").Format(trackName);
151 const auto progressReport = [&](
double fraction){
157 for (
auto channel : channels) {
165 extents.push_back(extent);
166 maxExtent = std::max(maxExtent, extent);
167 offsets.push_back(offset);
171 XO(
"Analyzing second track of stereo pair: %s")
176 if (track->NChannels() == 1)
179 XO(
"Processing: %s").Format(trackName);
184 XO(
"Processing stereo channels independently: %s")
190 XO(
"Processing first track of stereo pair: %s")
194 auto pOffset = offsets.begin();
195 auto pExtent = extents.begin();
196 for (
const auto channel : channels) {
197 const auto extent = oneChannel ? *pExtent++: maxExtent;
198 if ((extent > 0) &&
mGain)
199 mMult = ratio / extent;
203 (bGoodResult =
ProcessOne(*channel, msg, progress, *pOffset++)))
207 XO(
"Processing second track of stereo pair: %s")
228 S.StartVerticalLay(0);
230 S.StartMultiColumn(2, wxALIGN_CENTER);
232 S.StartVerticalLay(
false);
235 .AddCheckBox(
XXO(
"&Remove DC offset (center on 0.0 vertically)"),
238 S.StartHorizontalLay(wxALIGN_LEFT,
false);
242 .Validator<wxGenericValidator>(&
mGain)
243 .AddCheckBox(
XXO(
"&Normalize peak amplitude to "),
247 .Name(
XO(
"Peak amplitude dB"))
248 .
Validator<FloatingPointValidator<double>>(
251 NumValidatorStyle::ONE_TRAILING_ZERO,
254 .AddTextBox( {}, L
"", 10);
256 wxALIGN_CENTER_VERTICAL | wxALIGN_LEFT);
258 wxALIGN_CENTER_VERTICAL | wxALIGN_LEFT);
260 S.EndHorizontalLay();
264 .AddCheckBox(
XXO(
"N&ormalize stereo channels independently"),
302 const bool gain,
const bool dc,
const double curT0,
const double curT1,
303 float &offset,
float &extent)
311 min = pair.first, max = pair.second;
320 min = -1.0, max = 1.0;
326 wxFAIL_MSG(
"Analysing Track when nothing to do!");
327 min = -1.0, max = 1.0;
330 extent = fmax(fabs(
min), fabs(max));
337 const ProgressReport &report,
const double curT0,
const double curT1,
349 auto len = (
end - start).as_double();
374 totalSamples += blockSamples;
383 if (!report((s - start).as_double() / len)) {
388 if (totalSamples > 0)
390 offset = -sum / totalSamples.
as_double();
414 auto len = (
end - start).as_double();
438 if (!track.
SetFloats(buffer.get(), s, block)) {
462 for(
decltype(len) i = 0; i < len; i++)
463 sum += (
double)buffer[i];
469 for(
decltype(len) i = 0; i < len; i++) {
470 float adjFrame = (buffer[i] + offset) *
mMult;
471 buffer[i] = adjFrame;
483 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....
bool SetFloats(const float *buffer, 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.
WAVE_TRACK_API std::pair< float, float > GetMinMax(const WaveChannel &channel, double t0, double t1, bool mayThrow=true)
BuiltinEffectsModule::Registration< EffectNormalize > reg
const char * end(const char *str) noexcept
const Type min
Minimum value.
const Type max
Maximum value.
Externalized state of a plug-in.