Audacity 3.2.0
Public Member Functions | Static Public Member Functions | Private Types | Private Member Functions | Private Attributes | Static Private Attributes | List of all members
EffectToneGen Class Reference

An Effect that can generate a sine, square or sawtooth wave. An extended mode of EffectToneGen supports 'chirps' where the frequency changes smoothly during the tone. More...

#include <ToneGen.h>

Inheritance diagram for EffectToneGen:
[legend]
Collaboration diagram for EffectToneGen:
[legend]

Public Member Functions

 EffectToneGen (bool isChirp)
 
virtual ~EffectToneGen ()
 
ComponentInterfaceSymbol GetSymbol () const override
 
TranslatableString GetDescription () const override
 
ManualPageID ManualPage () const override
 Name of a page in the Audacity alpha manual, default is empty. More...
 
EffectType GetType () const override
 Type determines how it behaves. More...
 
unsigned GetAudioOutCount () const override
 How many output buffers to allocate at once. More...
 
bool ProcessInitialize (EffectSettings &settings, double sampleRate, sampleCount totalLen, ChannelNames chanMap) override
 
size_t ProcessBlock (EffectSettings &settings, const float *const *inBlock, float *const *outBlock, size_t blockLen) override
 Called for destructive effect computation. More...
 
std::unique_ptr< EffectUIValidatorPopulateOrExchange (ShuttleGui &S, EffectInstance &instance, EffectSettingsAccess &access) override
 Add controls to effect panel; always succeeds. More...
 
bool TransferDataToWindow (const EffectSettings &settings) override
 Update controls for the settings. More...
 
bool TransferDataFromWindow (EffectSettings &settings) override
 Update the given settings from controls. More...
 
- Public Member Functions inherited from StatefulPerTrackEffect
std::shared_ptr< EffectInstanceMakeInstance () const override
 Make an object maintaining short-term state of an Effect. More...
 
size_t SetBlockSize (size_t maxBlockSize) override
 
size_t GetBlockSize () const override
 
virtual sampleCount GetLatency ()
 
virtual bool ProcessInitialize (EffectSettings &settings, double sampleRate, sampleCount totalLen, ChannelNames chanMap=nullptr)
 
virtual bool ProcessFinalize ()
 
virtual size_t ProcessBlock (EffectSettings &settings, const float *const *inBlock, float *const *outBlock, size_t blockLen)
 Called for destructive effect computation. More...
 
- Public Member Functions inherited from StatefulEffectBase
virtual bool Init ()
 Call once to set up state for whole list of tracks to be processed. More...
 
virtual bool Process (EffectInstance &instance, EffectSettings &settings)=0
 Actually do the effect here. More...
 
virtual bool RealtimeInitialize (EffectSettings &settings, double sampleRate)
 
virtual bool RealtimeAddProcessor (EffectSettings &settings, unsigned numChannels, float sampleRate)
 
virtual bool RealtimeSuspend ()
 
virtual bool RealtimeResume ()
 
virtual bool RealtimeProcessStart (EffectSettings &settings)
 settings are possibly changed, since last call, by an asynchronous dialog More...
 
virtual size_t RealtimeProcess (size_t group, EffectSettings &settings, const float *const *inBuf, float *const *outBuf, size_t numSamples)
 
virtual bool RealtimeProcessEnd (EffectSettings &settings) noexcept
 settings can be updated to let a dialog change appearance at idle More...
 
virtual bool RealtimeFinalize (EffectSettings &settings) noexcept
 
virtual size_t SetBlockSize (size_t maxBlockSize)
 
virtual size_t GetBlockSize () const
 
- Public Member Functions inherited from PerTrackEffect
 ~PerTrackEffect () override
 
- Public Member Functions inherited from Effect
 Effect ()
 
virtual ~Effect ()
 
PluginPath GetPath () const override
 
bool VisitSettings (SettingsVisitor &visitor, EffectSettings &settings) override
 
bool VisitSettings (ConstSettingsVisitor &visitor, const EffectSettings &settings) const override
 
ComponentInterfaceSymbol GetSymbol () const override
 
VendorSymbol GetVendor () const override
 
wxString GetVersion () const override
 
TranslatableString GetDescription () const override
 
EffectType GetType () const override
 Type determines how it behaves. More...
 
EffectFamilySymbol GetFamily () const override
 Report identifier and user-visible name of the effect protocol. More...
 
bool IsInteractive () const override
 Whether the effect needs a dialog for entry of settings. More...
 
bool IsDefault () const override
 Whether the effect sorts "above the line" in the menus. More...
 
RealtimeSince RealtimeSupport () const override
 Since which version of Audacity has the effect supported realtime? More...
 
bool SupportsAutomation () const override
 Whether the effect has any automatable controls. More...
 
bool SaveSettings (const EffectSettings &settings, CommandParameters &parms) const override
 Store settings as keys and values. More...
 
bool LoadSettings (const CommandParameters &parms, EffectSettings &settings) const override
 Restore settings from keys and values. More...
 
bool LoadUserPreset (const RegistryPath &name, EffectSettings &settings) const override
 Change settings to a user-named preset. More...
 
bool SaveUserPreset (const RegistryPath &name, const EffectSettings &settings) const override
 Save settings in the configuration file as a user-named preset. More...
 
RegistryPaths GetFactoryPresets () const override
 Report names of factory presets. More...
 
bool LoadFactoryPreset (int id, EffectSettings &settings) const override
 Change settings to the preset whose name is GetFactoryPresets()[id] More...
 
bool LoadFactoryDefaults (EffectSettings &settings) const override
 Change settings back to "factory default". More...
 
unsigned GetAudioInCount () const override
 How many input buffers to allocate at once. More...
 
unsigned GetAudioOutCount () const override
 How many output buffers to allocate at once. More...
 
virtual const EffectParameterMethodsParameters () const
 
int ShowClientInterface (wxWindow &parent, wxDialog &dialog, bool forceModal=false) override
 
std::unique_ptr< EffectUIValidatorPopulateUI (ShuttleGui &S, EffectInstance &instance, EffectSettingsAccess &access) override
 Adds controls to a panel that is given as the parent window of S More...
 
bool IsGraphicalUI () override
 
bool ValidateUI (EffectSettings &) override
 
bool CloseUI () override
 
bool CanExportPresets () override
 
void ExportPresets (const EffectSettings &settings) const override
 
void ImportPresets (EffectSettings &settings) override
 
bool HasOptions () override
 
void ShowOptions () override
 
const EffectSettingsManagerGetDefinition () const override
 
virtual NumericFormatSymbol GetSelectionFormat ()
 
int ShowHostInterface (wxWindow &parent, const EffectDialogFactory &factory, std::shared_ptr< EffectInstance > &pInstance, EffectSettingsAccess &access, bool forceModal=false) override
 Usually applies factory to self and given access. More...
 
bool SaveSettingsAsString (const EffectSettings &settings, wxString &parms) const override
 
bool LoadSettingsFromString (const wxString &parms, EffectSettings &settings) const override
 
bool IsBatchProcessing () const override
 
void SetBatchProcessing () override
 
void UnsetBatchProcessing () override
 
bool TransferDataToWindow (const EffectSettings &settings) override
 Update controls for the settings. More...
 
bool TransferDataFromWindow (EffectSettings &settings) override
 Update the given settings from controls. More...
 
unsigned TestUIFlags (unsigned mask)
 
bool Delegate (Effect &delegate, EffectSettings &settings)
 Re-invoke DoEffect on another Effect object that implements the work. More...
 
int MessageBox (const TranslatableString &message, long style=DefaultMessageBoxStyle, const TranslatableString &titleStr={}) const
 
bool EnableApply (bool enable=true)
 
wxWindow * GetUIParent ()
 
- Public Member Functions inherited from EffectBase
 EffectBase ()
 
 ~EffectBase () override
 
- Public Member Functions inherited from EffectUIClientInterface
virtual ~EffectUIClientInterface ()
 
virtual int ShowClientInterface (wxWindow &parent, wxDialog &dialog, bool forceModal=false)=0
 
virtual bool IsGraphicalUI ()=0
 
virtual std::unique_ptr< EffectUIValidatorPopulateUI (ShuttleGui &S, EffectInstance &instance, EffectSettingsAccess &access)=0
 Adds controls to a panel that is given as the parent window of S More...
 
virtual bool CanExportPresets ()=0
 
virtual void ExportPresets (const EffectSettings &settings) const =0
 
virtual void ImportPresets (EffectSettings &settings)=0
 
virtual bool HasOptions ()=0
 
virtual void ShowOptions ()=0
 
- Public Member Functions inherited from EffectPlugin
EffectPluginoperator= (EffectPlugin &)=delete
 
virtual ~EffectPlugin ()
 
virtual const EffectSettingsManagerGetDefinition () const =0
 
virtual int ShowHostInterface (wxWindow &parent, const EffectDialogFactory &factory, std::shared_ptr< EffectInstance > &pInstance, EffectSettingsAccess &access, bool forceModal=false)=0
 Usually applies factory to self and given access. More...
 
virtual void Preview (EffectSettingsAccess &access, bool dryOnly)=0
 
virtual bool SaveSettingsAsString (const EffectSettings &settings, wxString &parms) const =0
 
virtual bool LoadSettingsFromString (const wxString &parms, EffectSettings &settings) const =0
 
virtual bool IsBatchProcessing () const =0
 
virtual void SetBatchProcessing ()=0
 
virtual void UnsetBatchProcessing ()=0
 
virtual bool DoEffect (EffectSettings &settings, double projectRate, TrackList *list, WaveTrackFactory *factory, NotifyingSelectedRegion &selectedRegion, unsigned flags, wxWindow *pParent=nullptr, const EffectDialogFactory &dialogFactory={}, const EffectSettingsAccessPtr &pAccess=nullptr)=0
 Unfortunately complicated dual-use function. More...
 
virtual bool TransferDataToWindow (const EffectSettings &settings)=0
 Update controls for the settings. More...
 
virtual bool TransferDataFromWindow (EffectSettings &settings)=0
 Update the given settings from controls. More...
 
- Public Member Functions inherited from EffectInstanceFactory
virtual ~EffectInstanceFactory ()
 
virtual std::shared_ptr< EffectInstanceMakeInstance () const =0
 Make an object maintaining short-term state of an Effect. More...
 
virtual unsigned GetAudioInCount () const =0
 How many input buffers to allocate at once. More...
 
virtual unsigned GetAudioOutCount () const =0
 How many output buffers to allocate at once. More...
 
virtual int GetMidiInCount () const
 Function that has not yet found a use. More...
 
virtual int GetMidiOutCount () const
 Function that has not yet found a use. More...
 
- Public Member Functions inherited from EffectSettingsManager
virtual ~EffectSettingsManager ()
 
virtual bool VisitSettings (SettingsVisitor &visitor, EffectSettings &settings)
 
virtual bool VisitSettings (ConstSettingsVisitor &visitor, const EffectSettings &settings) const
 
virtual EffectSettings MakeSettings () const
 
virtual bool CopySettingsContents (const EffectSettings &src, EffectSettings &dst) const
 Update one settings object from another. More...
 
- Public Member Functions inherited from EffectDefinitionInterface
virtual ~EffectDefinitionInterface ()
 
virtual EffectType GetType () const =0
 Type determines how it behaves. More...
 
virtual EffectType GetClassification () const
 Determines which menu it appears in; default same as GetType(). More...
 
virtual EffectFamilySymbol GetFamily () const =0
 Report identifier and user-visible name of the effect protocol. More...
 
virtual bool IsInteractive () const =0
 Whether the effect needs a dialog for entry of settings. More...
 
virtual bool IsDefault () const =0
 Whether the effect sorts "above the line" in the menus. More...
 
virtual RealtimeSince RealtimeSupport () const =0
 Since which version of Audacity has the effect supported realtime? More...
 
bool SupportsRealtime () const
 
virtual bool SupportsAutomation () const =0
 Whether the effect has any automatable controls. More...
 
virtual bool EnablesDebug () const
 Whether the effect dialog should have a Debug button; default, always false. More...
 
virtual ManualPageID ManualPage () const
 Name of a page in the Audacity alpha manual, default is empty. More...
 
virtual FilePath HelpPage () const
 Fully qualified local help file name, default is empty. More...
 
virtual bool IsHiddenFromMenus () const
 Default is false. More...
 
- Public Member Functions inherited from ComponentInterface
virtual ~ComponentInterface ()
 
virtual PluginPath GetPath () const =0
 
virtual ComponentInterfaceSymbol GetSymbol () const =0
 
virtual VendorSymbol GetVendor () const =0
 
virtual wxString GetVersion () const =0
 
virtual TranslatableString GetDescription () const =0
 
TranslatableString GetName () const
 

Static Public Member Functions

static EffectToneGenFetchParameters (EffectToneGen &e, EffectSettings &)
 
- Static Public Member Functions inherited from Effect
static EffectFetchParameters (Effect &e, EffectSettings &)
 
static void IncEffectCounter ()
 
- Static Public Member Functions inherited from EffectDefinitionInterface
static Identifier GetSquashedName (const Identifier &ident)
 A utility that strips spaces and CamelCases a name. More...
 

Private Types

enum  kWaveforms {
  kSine , kSquare , kSawtooth , kSquareNoAlias ,
  kTriangle , nWaveforms
}
 
enum  kInterpolations { kLinear , kLogarithmic , nInterpolations }
 

Private Member Functions

void OnControlUpdate (wxCommandEvent &evt)
 
void PostSet ()
 
const EffectParameterMethodsParameters () const override
 

Private Attributes

double mSampleRate {}
 
const bool mChirp
 
sampleCount mSample
 
double mPositionInCycles
 
int mWaveform
 
int mInterpolation
 
double mFrequency0
 
double mFrequency1
 
double mAmplitude0
 
double mAmplitude1
 
double mLogFrequency [2]
 
NumericTextCtrlmToneDurationT
 

Static Private Attributes

static const EnumValueSymbol kWaveStrings [nWaveforms]
 
static const EnumValueSymbol kInterStrings [nInterpolations]
 
static constexpr EffectParameter StartFreq
 
static constexpr EffectParameter EndFreq
 
static constexpr EffectParameter StartAmp
 
static constexpr EffectParameter EndAmp
 
static constexpr EffectParameter Frequency
 
static constexpr EffectParameter Amplitude
 
static constexpr EnumParameter Waveform
 
static constexpr EnumParameter Interp
 

Additional Inherited Members

- Public Types inherited from Effect
enum  : long { DefaultMessageBoxStyle = wxOK | wxCENTRE }
 
- Public Types inherited from EffectPlugin
using EffectSettingsAccessPtr = std::shared_ptr< EffectSettingsAccess >
 
- Public Types inherited from EffectDefinitionInterface
enum class  RealtimeSince : unsigned { Never , Since_3_2 , Always }
 In which versions of Audacity was an effect realtime capable? More...
 
- Static Public Attributes inherited from EffectPlugin
static const wxString kUserPresetIdent = wxT("User Preset:")
 
static const wxString kFactoryPresetIdent = wxT("Factory Preset:")
 
static const wxString kCurrentSettingsIdent = wxT("<Current Settings>")
 
static const wxString kFactoryDefaultsIdent = wxT("<Factory Defaults>")
 
- Protected Member Functions inherited from PerTrackEffect
bool DoPass1 () const
 
bool DoPass2 () const
 
bool Process (EffectInstance &instance, EffectSettings &settings) const
 
- Protected Member Functions inherited from Effect
bool EnablePreview (bool enable=true)
 
bool CheckWhetherSkipEffect (const EffectSettings &settings) const override
 Default implementation returns false. More...
 
double CalcPreviewInputLength (const EffectSettings &settings, double previewLength) const override
 Default implementation returns previewLength More...
 
virtual std::unique_ptr< EffectUIValidatorPopulateOrExchange (ShuttleGui &S, EffectInstance &instance, EffectSettingsAccess &access)
 Add controls to effect panel; always succeeds. More...
 
bool TotalProgress (double frac, const TranslatableString &={}) const
 
bool TrackProgress (int whichTrack, double frac, const TranslatableString &={}) const
 
bool TrackGroupProgress (int whichGroup, double frac, const TranslatableString &={}) const
 
int GetNumWaveTracks () const
 
int GetNumWaveGroups () const
 
void GetBounds (const WaveTrack &track, const WaveTrack *pRight, sampleCount *start, sampleCount *len)
 
void CopyInputTracks (bool allSyncLockSelected=false)
 
std::shared_ptr< AddedAnalysisTrackAddAnalysisTrack (const wxString &name=wxString())
 
ModifiedAnalysisTrack ModifyAnalysisTrack (const LabelTrack *pOrigTrack, const wxString &name=wxString())
 
TrackAddToOutputTracks (const std::shared_ptr< Track > &t)
 
- Protected Member Functions inherited from EffectBase
void Preview (EffectSettingsAccess &access, bool dryOnly) override
 
bool DoEffect (EffectSettings &settings, double projectRate, TrackList *list, WaveTrackFactory *factory, NotifyingSelectedRegion &selectedRegion, unsigned flags, wxWindow *pParent, const EffectDialogFactory &dialogFactory, const EffectSettingsAccessPtr &pAccess) override
 Unfortunately complicated dual-use function. More...
 
virtual bool CheckWhetherSkipEffect (const EffectSettings &settings) const =0
 After Init(), tell whether Process() should be skipped. More...
 
virtual double CalcPreviewInputLength (const EffectSettings &settings, double previewLength) const =0
 
void SetLinearEffectFlag (bool linearEffectFlag)
 
void SetPreviewFullSelectionFlag (bool previewDurationFlag)
 
bool IsPreviewing () const
 
void IncludeNotSelectedPreviewTracks (bool includeNotSelected)
 
void ReplaceProcessedTracks (const bool bGoodResult)
 
const TrackListinputTracks () const
 
const AudacityProjectFindProject () const
 
virtual bool ValidateUI (EffectSettings &settings)=0
 
virtual bool CloseUI ()=0
 
- Protected Attributes inherited from PerTrackEffect
sampleCount mSampleCnt {}
 
- Protected Attributes inherited from Effect
wxWeakRef< wxDialog > mHostUIDialog
 This smart pointer tracks the lifetime of the dialog. More...
 
wxWindow * mUIParent {}
 
- Protected Attributes inherited from EffectBase
BasicUI::ProgressDialogmProgress {}
 
double mProjectRate {}
 
WaveTrackFactorymFactory {}
 
std::shared_ptr< TrackListmOutputTracks
 
double mT0 {}
 
double mT1 {}
 
wxArrayString mPresetNames
 
unsigned mUIFlags { 0 }
 
- Protected Attributes inherited from EffectUIClientInterface
friend EffectUIValidator
 
friend DefaultEffectUIValidator
 
- Static Protected Attributes inherited from EffectBase
static int nEffectsDone = 0
 

Detailed Description

An Effect that can generate a sine, square or sawtooth wave. An extended mode of EffectToneGen supports 'chirps' where the frequency changes smoothly during the tone.

Definition at line 23 of file ToneGen.h.

Member Enumeration Documentation

◆ kInterpolations

Enumerator
kLinear 
kLogarithmic 
nInterpolations 

Definition at line 98 of file ToneGen.h.

99 {
100 kLinear,
103 };
@ nInterpolations
Definition: ToneGen.h:102

◆ kWaveforms

Enumerator
kSine 
kSquare 
kSawtooth 
kSquareNoAlias 
kTriangle 
nWaveforms 

Definition at line 86 of file ToneGen.h.

87 {
88 kSine,
89 kSquare,
94 };
@ kSquareNoAlias
Definition: ToneGen.h:91

Constructor & Destructor Documentation

◆ EffectToneGen()

EffectToneGen::EffectToneGen ( bool  isChirp)

Definition at line 91 of file ToneGen.cpp.

92 : mChirp{ isChirp }
93{
94 Parameters().Reset(*this);
95
96 wxASSERT(nWaveforms == WXSIZEOF(kWaveStrings));
97 wxASSERT(nInterpolations == WXSIZEOF(kInterStrings));
98
99 // Chirp varies over time so must use selected duration.
100 // TODO: When previewing, calculate only the first 'preview length'.
101 if (isChirp)
102 SetLinearEffectFlag(false);
103 else
105}
void SetLinearEffectFlag(bool linearEffectFlag)
Definition: EffectBase.cpp:218
virtual void Reset(Effect &effect) const =0
static const EnumValueSymbol kWaveStrings[nWaveforms]
Definition: ToneGen.h:96
static const EnumValueSymbol kInterStrings[nInterpolations]
Definition: ToneGen.h:105
const EffectParameterMethods & Parameters() const override
Definition: ToneGen.cpp:53
const bool mChirp
Definition: ToneGen.h:62

Referenced by Parameters().

Here is the caller graph for this function:

◆ ~EffectToneGen()

EffectToneGen::~EffectToneGen ( )
virtual

Definition at line 107 of file ToneGen.cpp.

108{
109}

Member Function Documentation

◆ FetchParameters()

static EffectToneGen * EffectToneGen::FetchParameters ( EffectToneGen e,
EffectSettings  
)
inlinestatic

Definition at line 27 of file ToneGen.h.

27{ return &e; }

◆ GetAudioOutCount()

unsigned EffectToneGen::GetAudioOutCount ( ) const
overridevirtual

How many output buffers to allocate at once.

Reimplemented from Effect.

Definition at line 141 of file ToneGen.cpp.

142{
143 return 1;
144}

◆ GetDescription()

TranslatableString EffectToneGen::GetDescription ( ) const
overridevirtual

Reimplemented from Effect.

Definition at line 120 of file ToneGen.cpp.

121{
122 return mChirp
123 ? XO("Generates an ascending or descending tone of one of four types")
124 : XO("Generates a constant frequency tone of one of four types");
125}
#define XO(s)
Definition: Internat.h:31

References mChirp, and XO.

◆ GetSymbol()

ComponentInterfaceSymbol EffectToneGen::GetSymbol ( ) const
overridevirtual

Reimplemented from Effect.

Definition at line 113 of file ToneGen.cpp.

114{
115 return mChirp
118}
static const ComponentInterfaceSymbol Symbol
Definition: ToneGen.h:129
static const ComponentInterfaceSymbol Symbol
Definition: ToneGen.h:138

References mChirp, EffectChirp::Symbol, and EffectTone::Symbol.

◆ GetType()

EffectType EffectToneGen::GetType ( ) const
overridevirtual

Type determines how it behaves.

Reimplemented from Effect.

Definition at line 136 of file ToneGen.cpp.

137{
138 return EffectTypeGenerate;
139}
@ EffectTypeGenerate

References EffectTypeGenerate.

◆ ManualPage()

ManualPageID EffectToneGen::ManualPage ( ) const
overridevirtual

Name of a page in the Audacity alpha manual, default is empty.

Reimplemented from EffectDefinitionInterface.

Definition at line 127 of file ToneGen.cpp.

128{
129 return mChirp
130 ? L"Chirp"
131 : L"Tone";
132}

References mChirp.

◆ OnControlUpdate()

void EffectToneGen::OnControlUpdate ( wxCommandEvent &  evt)
private

Definition at line 415 of file ToneGen.cpp.

416{
417 if (!EnableApply(mUIParent->TransferDataFromWindow()))
418 {
419 return;
420 }
421}
bool EnableApply(bool enable=true)
Definition: Effect.cpp:613
wxWindow * mUIParent
Definition: Effect.h:270

References Effect::EnableApply(), and Effect::mUIParent.

Here is the call graph for this function:

◆ Parameters()

const EffectParameterMethods & EffectToneGen::Parameters ( ) const
overrideprivatevirtual

Reimplemented from Effect.

Definition at line 53 of file ToneGen.cpp.

54{
55 static const auto postSet =
56 [](EffectToneGen &, EffectSettings &, EffectToneGen &e, bool updating) {
57 if (updating)
58 e.PostSet();
59 return true;
60 };
63 > chirpParameters{ postSet };
66 > toneParameters{ postSet };
67 if (mChirp)
68 return chirpParameters;
69 else
70 return toneParameters;
71}
Generates EffectParameterMethods overrides from variadic template arguments.
An Effect that can generate a sine, square or sawtooth wave. An extended mode of EffectToneGen suppor...
Definition: ToneGen.h:24
static constexpr EffectParameter Amplitude
Definition: ToneGen.h:118
static constexpr EffectParameter Frequency
Definition: ToneGen.h:116
static constexpr EffectParameter EndFreq
Definition: ToneGen.h:110
static constexpr EnumParameter Interp
Definition: ToneGen.h:122
static constexpr EnumParameter Waveform
Definition: ToneGen.h:120
EffectToneGen(bool isChirp)
Definition: ToneGen.cpp:91
static constexpr EffectParameter StartFreq
Definition: ToneGen.h:108
static constexpr EffectParameter StartAmp
Definition: ToneGen.h:112
static constexpr EffectParameter EndAmp
Definition: ToneGen.h:114
Externalized state of a plug-in.

References Amplitude, EffectToneGen(), EndAmp, EndFreq, Frequency, Interp, mChirp, StartAmp, StartFreq, and Waveform.

Here is the call graph for this function:

◆ PopulateOrExchange()

std::unique_ptr< EffectUIValidator > EffectToneGen::PopulateOrExchange ( ShuttleGui S,
EffectInstance instance,
EffectSettingsAccess access 
)
overridevirtual

Add controls to effect panel; always succeeds.

Returns
if not null, then return it from Effect::PopulateUI instead of a DefaultEffectUIValidator; default implementation returns null

Reimplemented from Effect.

Definition at line 273 of file ToneGen.cpp.

275{
276 wxTextCtrl *t;
277
278 S.StartMultiColumn(2, wxCENTER);
279 {
280 S.Validator<wxGenericValidator>(&mWaveform)
281 .AddChoice(XXO("&Waveform:"),
283
284 if (mChirp)
285 {
286 S.AddFixedText( {} );
287 S.StartHorizontalLay(wxEXPAND);
288 {
289 S.StartHorizontalLay(wxLEFT, 50);
290 {
291 S.AddTitle(XO("Start"));
292 }
293 S.EndHorizontalLay();
294
295 S.StartHorizontalLay(wxLEFT, 50);
296 {
297 S.AddTitle(XO("End"));
298 }
299 S.EndHorizontalLay();
300 }
301 S.EndHorizontalLay();
302
303 S.AddPrompt(XXO("&Frequency (Hz):"));
304 S.StartHorizontalLay(wxEXPAND);
305 {
306 S.StartHorizontalLay(wxLEFT, 50);
307 {
308 t = S.Name(XO("Frequency Hertz Start"))
309 .Validator<FloatingPointValidator<double>>(
310 6, &mFrequency0,
311 NumValidatorStyle::NO_TRAILING_ZEROES,
313 mProjectRate / 2.0 )
314 .AddTextBox( {}, L"", 12);
315 }
316 S.EndHorizontalLay();
317
318 S.StartHorizontalLay(wxLEFT, 50);
319 {
320 t = S.Name(XO("Frequency Hertz End"))
321 .Validator<FloatingPointValidator<double>>(
322 6, &mFrequency1,
323 NumValidatorStyle::NO_TRAILING_ZEROES,
324 EndFreq.min,
325 mProjectRate / 2.0 )
326 .AddTextBox( {}, L"", 12);
327 }
328 S.EndHorizontalLay();
329 }
330 S.EndHorizontalLay();
331
332 S.AddPrompt(XXO("&Amplitude (0-1):"));
333 S.StartHorizontalLay(wxEXPAND);
334 {
335 S.StartHorizontalLay(wxLEFT, 50);
336 {
337 t = S.Name(XO("Amplitude Start"))
338 .Validator<FloatingPointValidator<double>>(
339 6, &mAmplitude0, NumValidatorStyle::NO_TRAILING_ZEROES,
341 .AddTextBox( {}, L"", 12);
342 }
343 S.EndHorizontalLay();
344
345 S.StartHorizontalLay(wxLEFT, 50);
346 {
347 t = S.Name(XO("Amplitude End"))
348 .Validator<FloatingPointValidator<double>>(
349 6, &mAmplitude1, NumValidatorStyle::NO_TRAILING_ZEROES,
351 .AddTextBox( {}, L"", 12);
352 }
353 S.EndHorizontalLay();
354 }
355 S.EndHorizontalLay();
356
357 S.Validator<wxGenericValidator>(&mInterpolation)
358 .AddChoice(XXO("I&nterpolation:"),
360 }
361 else
362 {
363 t = S.Validator<FloatingPointValidator<double>>(
364 6, &mFrequency0, NumValidatorStyle::NO_TRAILING_ZEROES,
366 mProjectRate / 2.0 )
367 .AddTextBox(XXO("&Frequency (Hz):"), L"", 12);
368
369 t = S.Validator<FloatingPointValidator<double>>(
370 6, &mAmplitude0, NumValidatorStyle::NO_TRAILING_ZEROES,
372 .AddTextBox(XXO("&Amplitude (0-1):"), L"", 12);
373 }
374
375 S.AddPrompt(XXO("&Duration:"));
376 auto &extra = access.Get().extra;
378 NumericTextCtrl(S.GetParent(), wxID_ANY,
380 extra.GetDurationFormat(),
381 extra.GetDuration(),
384 .AutoPos(true));
385 S.Name(XO("Duration"))
386 .Position(wxALIGN_LEFT | wxALL)
387 .AddWindow(mToneDurationT);
388 }
389 S.EndMultiColumn();
390
391 return nullptr;
392}
#define XXO(s)
Definition: Internat.h:44
#define safenew
Definition: MemoryX.h:10
TranslatableStrings Msgids(const EnumValueSymbol strings[], size_t nStrings)
Convenience function often useful when adding choice controls.
#define S(N)
Definition: ToChars.cpp:64
double mProjectRate
Definition: EffectBase.h:99
virtual const EffectSettings & Get()=0
int mInterpolation
Definition: ToneGen.h:72
double mFrequency0
Definition: ToneGen.h:73
double mFrequency1
Definition: ToneGen.h:74
double mAmplitude0
Definition: ToneGen.h:75
NumericTextCtrl * mToneDurationT
Definition: ToneGen.h:79
double mAmplitude1
Definition: ToneGen.h:76
int mWaveform
Definition: ToneGen.h:71
A Validator is an object which checks whether a wxVariant satisfies a certain criterion....
Definition: Validators.h:53
const Type min
Minimum value.
Definition: Shuttle.h:30
const Type max
Maximum value.
Definition: Shuttle.h:31
EffectSettingsExtra extra
Options & AutoPos(bool enable)

References Amplitude, NumericTextCtrl::Options::AutoPos(), EndAmp, EndFreq, EffectSettings::extra, Frequency, EffectSettingsAccess::Get(), kInterStrings, kWaveStrings, mAmplitude0, mAmplitude1, EffectParameter< Structure, Member, Type, Value >::max, mChirp, mFrequency0, mFrequency1, EffectParameter< Structure, Member, Type, Value >::min, mInterpolation, EffectBase::mProjectRate, Msgids(), mToneDurationT, mWaveform, nInterpolations, nWaveforms, S, safenew, StartAmp, StartFreq, NumericConverter::TIME, XO, and XXO.

Here is the call graph for this function:

◆ PostSet()

void EffectToneGen::PostSet ( )
private

Definition at line 257 of file ToneGen.cpp.

258{
259 if (!mChirp) {
262 }
263// double freqMax =
264// (FindProject()
265// ? ProjectRate::Get( *FindProject() ).GetRate()
266// : 44100.0)
267// / 2.0;
268// mFrequency1 = std::clamp<double>(mFrequency1, EndFreq.min, freqMax);
269}

References mAmplitude0, mAmplitude1, mChirp, mFrequency0, and mFrequency1.

◆ ProcessBlock()

size_t EffectToneGen::ProcessBlock ( EffectSettings settings,
const float *const *  inBlock,
float *const *  outBlock,
size_t  blockLen 
)
overridevirtual

Called for destructive effect computation.

Reimplemented from StatefulPerTrackEffect.

Definition at line 155 of file ToneGen.cpp.

157{
158 float *buffer = outBlock[0];
159 double throwaway = 0; //passed to modf but never used
160 double f = 0.0;
161 double a, b;
162 int k;
163
164 double frequencyQuantum;
165 double BlendedFrequency;
166 double BlendedAmplitude;
167 double BlendedLogFrequency = 0.0;
168
169 // calculate delta, and reposition from where we left
170 auto doubleSampleCount = mSampleCnt.as_double();
171 auto doubleSample = mSample.as_double();
172 double amplitudeQuantum =
173 (mAmplitude1 - mAmplitude0) / doubleSampleCount;
174 BlendedAmplitude = mAmplitude0 +
175 amplitudeQuantum * doubleSample;
176
177 // precalculations:
178 double pre2PI = 2.0 * M_PI;
179 double pre4divPI = 4.0 / M_PI;
180
181 // initial setup should calculate deltas
183 {
184 // this for log interpolation
185 mLogFrequency[0] = log10(mFrequency0);
186 mLogFrequency[1] = log10(mFrequency1);
187 // calculate delta, and reposition from where we left
188 frequencyQuantum = (mLogFrequency[1] - mLogFrequency[0]) / doubleSampleCount;
189 BlendedLogFrequency = mLogFrequency[0] + frequencyQuantum * doubleSample;
190 BlendedFrequency = pow(10.0, BlendedLogFrequency);
191 }
192 else
193 {
194 // this for regular case, linear interpolation
195 frequencyQuantum = (mFrequency1 - mFrequency0) / doubleSampleCount;
196 BlendedFrequency = mFrequency0 + frequencyQuantum * doubleSample;
197 }
198
199 // synth loop
200 for (decltype(blockLen) i = 0; i < blockLen; i++)
201 {
202 switch (mWaveform)
203 {
204 case kSine:
205 f = sin(pre2PI * mPositionInCycles / mSampleRate);
206 break;
207 case kSquare:
208 f = (modf(mPositionInCycles / mSampleRate, &throwaway) < 0.5) ? 1.0 : -1.0;
209 break;
210 case kSawtooth:
211 f = (2.0 * modf(mPositionInCycles / mSampleRate + 0.5, &throwaway)) - 1.0;
212 break;
213 case kTriangle:
214 f = modf(mPositionInCycles / mSampleRate, &throwaway);
215 if(f < 0.25) {
216 f *= 4.0;
217 } else if(f > 0.75) {
218 f = (f - 1.0) * 4.0;
219 } else { /* f >= 0.25 || f <= 0.75 */
220 f = (0.5 - f) * 4.0;
221 }
222 break;
223 case kSquareNoAlias: // Good down to 110Hz @ 44100Hz sampling.
224 //do fundamental (k=1) outside loop
225 b = (1.0 + cos((pre2PI * BlendedFrequency) / mSampleRate)) / pre4divPI; //scaling
226 f = pre4divPI * sin(pre2PI * mPositionInCycles / mSampleRate);
227 for (k = 3; (k < 200) && (k * BlendedFrequency < mSampleRate / 2.0); k += 2)
228 {
229 //Hann Window in freq domain
230 a = 1.0 + cos((pre2PI * k * BlendedFrequency) / mSampleRate);
231 //calc harmonic, apply window, scale to amplitude of fundamental
232 f += a * sin(pre2PI * mPositionInCycles / mSampleRate * k) / (b * k);
233 }
234 }
235 // insert value in buffer
236 buffer[i] = (float) (BlendedAmplitude * f);
237 // update freq,amplitude
238 mPositionInCycles += BlendedFrequency;
239 BlendedAmplitude += amplitudeQuantum;
241 {
242 BlendedLogFrequency += frequencyQuantum;
243 BlendedFrequency = pow(10.0, BlendedLogFrequency);
244 }
245 else
246 {
247 BlendedFrequency += frequencyQuantum;
248 }
249 }
250
251 // update external placeholder
252 mSample += blockLen;
253
254 return blockLen;
255}
#define M_PI
Definition: Distortion.cpp:29
double mPositionInCycles
Definition: ToneGen.h:67
double mSampleRate
Definition: ToneGen.h:61
double mLogFrequency[2]
Definition: ToneGen.h:77
sampleCount mSample
Definition: ToneGen.h:66
sampleCount mSampleCnt
double as_double() const
Definition: SampleCount.h:45

References sampleCount::as_double(), kLogarithmic, kSawtooth, kSine, kSquare, kSquareNoAlias, kTriangle, M_PI, mAmplitude0, mAmplitude1, mFrequency0, mFrequency1, mInterpolation, mLogFrequency, mPositionInCycles, mSample, PerTrackEffect::mSampleCnt, mSampleRate, and mWaveform.

Here is the call graph for this function:

◆ ProcessInitialize()

bool EffectToneGen::ProcessInitialize ( EffectSettings settings,
double  sampleRate,
sampleCount  totalLen,
ChannelNames  chanMap 
)
overridevirtual

Called at start of destructive processing, for each (mono/stereo) track Default implementation does nothing, returns true

Reimplemented from StatefulPerTrackEffect.

Definition at line 146 of file ToneGen.cpp.

148{
149 mSampleRate = sampleRate;
150 mPositionInCycles = 0.0;
151 mSample = 0;
152 return true;
153}

References mPositionInCycles, mSample, and mSampleRate.

◆ TransferDataFromWindow()

bool EffectToneGen::TransferDataFromWindow ( EffectSettings settings)
overridevirtual

Update the given settings from controls.

Reimplemented from Effect.

Definition at line 400 of file ToneGen.cpp.

401{
402 if (!mChirp)
403 {
406 }
407
408 settings.extra.SetDuration(mToneDurationT->GetValue());
409
410 return true;
411}
static Settings & settings()
Definition: TrackInfo.cpp:87

References NumericConverter::GetValue(), mAmplitude0, mAmplitude1, mChirp, mFrequency0, mFrequency1, mToneDurationT, and settings().

Here is the call graph for this function:

◆ TransferDataToWindow()

bool EffectToneGen::TransferDataToWindow ( const EffectSettings settings)
overridevirtual

Update controls for the settings.

Reimplemented from Effect.

Definition at line 394 of file ToneGen.cpp.

395{
396 mToneDurationT->SetValue(settings.extra.GetDuration());
397 return true;
398}
void SetValue(double newValue)

References mToneDurationT, settings(), and NumericTextCtrl::SetValue().

Here is the call graph for this function:

Member Data Documentation

◆ Amplitude

constexpr EffectParameter EffectToneGen::Amplitude
staticconstexprprivate
Initial value:
L"Amplitude", 0.8, 0.0, 1.0, 1 }

Definition at line 118 of file ToneGen.h.

Referenced by Parameters(), and PopulateOrExchange().

◆ EndAmp

constexpr EffectParameter EffectToneGen::EndAmp
staticconstexprprivate
Initial value:
L"EndAmp", 0.1, 0.0, 1.0, 1 }

Definition at line 114 of file ToneGen.h.

Referenced by Parameters(), and PopulateOrExchange().

◆ EndFreq

constexpr EffectParameter EffectToneGen::EndFreq
staticconstexprprivate
Initial value:
L"EndFreq", 1320.0, 1.0, DBL_MAX, 1 }

Definition at line 110 of file ToneGen.h.

Referenced by Parameters(), and PopulateOrExchange().

◆ Frequency

constexpr EffectParameter EffectToneGen::Frequency
staticconstexprprivate
Initial value:
L"Frequency", 440.0, 1.0, DBL_MAX, 1 }

Definition at line 116 of file ToneGen.h.

Referenced by Parameters(), and PopulateOrExchange().

◆ Interp

constexpr EnumParameter EffectToneGen::Interp
staticconstexprprivate
Initial value:

Definition at line 122 of file ToneGen.h.

Referenced by Parameters().

◆ kInterStrings

const EnumValueSymbol EffectToneGen::kInterStrings
staticprivate
Initial value:
=
{
{ XO("Linear") },
{ XO("Logarithmic") }
}

Definition at line 105 of file ToneGen.h.

Referenced by PopulateOrExchange().

◆ kWaveStrings

const EnumValueSymbol EffectToneGen::kWaveStrings
staticprivate
Initial value:
=
{
{ XO("Sine") },
{ XO("Square") },
{ XO("Sawtooth") },
{ XO("Square, no alias") },
{ XC("Triangle", "waveform") }
}
#define XC(s, c)
Definition: Internat.h:37

Definition at line 96 of file ToneGen.h.

Referenced by PopulateOrExchange().

◆ mAmplitude0

double EffectToneGen::mAmplitude0
private

Definition at line 75 of file ToneGen.h.

Referenced by PopulateOrExchange(), PostSet(), ProcessBlock(), and TransferDataFromWindow().

◆ mAmplitude1

double EffectToneGen::mAmplitude1
private

Definition at line 76 of file ToneGen.h.

Referenced by PopulateOrExchange(), PostSet(), ProcessBlock(), and TransferDataFromWindow().

◆ mChirp

const bool EffectToneGen::mChirp
private

◆ mFrequency0

double EffectToneGen::mFrequency0
private

Definition at line 73 of file ToneGen.h.

Referenced by PopulateOrExchange(), PostSet(), ProcessBlock(), and TransferDataFromWindow().

◆ mFrequency1

double EffectToneGen::mFrequency1
private

Definition at line 74 of file ToneGen.h.

Referenced by PopulateOrExchange(), PostSet(), ProcessBlock(), and TransferDataFromWindow().

◆ mInterpolation

int EffectToneGen::mInterpolation
private

Definition at line 72 of file ToneGen.h.

Referenced by PopulateOrExchange(), and ProcessBlock().

◆ mLogFrequency

double EffectToneGen::mLogFrequency[2]
private

Definition at line 77 of file ToneGen.h.

Referenced by ProcessBlock().

◆ mPositionInCycles

double EffectToneGen::mPositionInCycles
private

Definition at line 67 of file ToneGen.h.

Referenced by ProcessBlock(), and ProcessInitialize().

◆ mSample

sampleCount EffectToneGen::mSample
private

Definition at line 66 of file ToneGen.h.

Referenced by ProcessBlock(), and ProcessInitialize().

◆ mSampleRate

double EffectToneGen::mSampleRate {}
private

Definition at line 61 of file ToneGen.h.

Referenced by ProcessBlock(), and ProcessInitialize().

◆ mToneDurationT

NumericTextCtrl* EffectToneGen::mToneDurationT
private

Definition at line 79 of file ToneGen.h.

Referenced by PopulateOrExchange(), TransferDataFromWindow(), and TransferDataToWindow().

◆ mWaveform

int EffectToneGen::mWaveform
private

Definition at line 71 of file ToneGen.h.

Referenced by PopulateOrExchange(), and ProcessBlock().

◆ StartAmp

constexpr EffectParameter EffectToneGen::StartAmp
staticconstexprprivate
Initial value:
L"StartAmp", 0.8, 0.0, 1.0, 1 }

Definition at line 112 of file ToneGen.h.

Referenced by Parameters(), and PopulateOrExchange().

◆ StartFreq

constexpr EffectParameter EffectToneGen::StartFreq
staticconstexprprivate
Initial value:
L"StartFreq", 440.0, 1.0, DBL_MAX, 1 }

Definition at line 108 of file ToneGen.h.

Referenced by Parameters(), and PopulateOrExchange().

◆ Waveform

constexpr EnumParameter EffectToneGen::Waveform
staticconstexprprivate
Initial value:
L"Waveform", 0, 0, nWaveforms - 1, 1, kWaveStrings, nWaveforms }

Definition at line 120 of file ToneGen.h.

Referenced by Parameters().


The documentation for this class was generated from the following files: