1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-08-09 08:31:13 +02:00
audacity/src/effects/Echo.cpp
Steve Daulton d9f3c432d4 Fix for bugs 943, 942, 941, 843 and 775.
Non-linear effects now process tracks before mixing.
This will be slower when multiple tracks are selected
but the preview should now match the applied effect.
SetLinearEffectFlag(true) allows linear effects to
preview more quickly when multiple tracks selected, by
pre-mixing selected tracks.
Simple generators like Tone and Noise may be marked as
'linear' so that they only preview a few seconds.
Generators that vary over time (such as Chirp) must use
the full duration that is set. As this currently
requires calculating the full duration, preview for
'non-linear' generators are not limited to the preview
length.
2015-05-15 12:51:51 +01:00

176 lines
3.5 KiB
C++

/**********************************************************************
Audacity: A Digital Audio Editor
Echo.cpp
Dominic Mazzoni
Vaughan Johnson (dialog)
*******************************************************************//**
\class EffectEcho
\brief An Effect that causes an echo, variable delay and volume.
*//****************************************************************//**
\class EchoDialog
\brief EchoDialog used with EffectEcho
*//*******************************************************************/
#include "../Audacity.h"
#include <float.h>
#include <wx/intl.h>
#include "../widgets/valnum.h"
#include "Echo.h"
// Define keys, defaults, minimums, and maximums for the effect parameters
//
// Name Type Key Def Min Max Scale
Param( Delay, float, XO("Delay"), 1.0f, 0.001f, FLT_MAX, 1.0f );
Param( Decay, float, XO("Decay"), 0.5f, 0.0f, FLT_MAX, 1.0f );
EffectEcho::EffectEcho()
{
delay = DEF_Delay;
decay = DEF_Decay;
SetLinearEffectFlag(true);
}
EffectEcho::~EffectEcho()
{
}
// IdentInterface implementation
wxString EffectEcho::GetSymbol()
{
return ECHO_PLUGIN_SYMBOL;
}
wxString EffectEcho::GetDescription()
{
return XO("Repeats the selected audio again and again");
}
// EffectIdentInterface implementation
EffectType EffectEcho::GetType()
{
return EffectTypeProcess;
}
// EffectClientInterface implementation
int EffectEcho::GetAudioInCount()
{
return 1;
}
int EffectEcho::GetAudioOutCount()
{
return 1;
}
bool EffectEcho::ProcessInitialize(sampleCount WXUNUSED(totalLen), ChannelNames WXUNUSED(chanMap))
{
if (delay == 0.0)
{
return false;
}
histPos = 0;
histLen = (sampleCount) (mSampleRate * delay);
history = new float[histLen];
memset(history, 0, sizeof(float) * histLen);
return history != NULL;
}
bool EffectEcho::ProcessFinalize()
{
delete [] history;
return true;
}
sampleCount EffectEcho::ProcessBlock(float **inBlock, float **outBlock, sampleCount blockLen)
{
float *ibuf = inBlock[0];
float *obuf = outBlock[0];
for (sampleCount i = 0; i < blockLen; i++, histPos++)
{
if (histPos == histLen)
{
histPos = 0;
}
history[histPos] = obuf[i] = ibuf[i] + history[histPos] * decay;
}
return blockLen;
}
bool EffectEcho::GetAutomationParameters(EffectAutomationParameters & parms)
{
parms.WriteFloat(KEY_Delay, delay);
parms.WriteFloat(KEY_Decay, decay);
return true;
}
bool EffectEcho::SetAutomationParameters(EffectAutomationParameters & parms)
{
ReadAndVerifyFloat(Delay);
ReadAndVerifyFloat(Decay);
delay = Delay;
decay = Decay;
return true;
}
void EffectEcho::PopulateOrExchange(ShuttleGui & S)
{
S.AddSpace(0, 5);
S.StartMultiColumn(2, wxALIGN_CENTER);
{
FloatingPointValidator<double> vldDelay(3, &delay, NUM_VAL_NO_TRAILING_ZEROES);
vldDelay.SetRange(MIN_Delay, MAX_Delay);
S.AddTextBox(_("Delay time (seconds):"), wxT(""), 10)->SetValidator(vldDelay);
FloatingPointValidator<double> vldDecay(3, &decay, NUM_VAL_NO_TRAILING_ZEROES);
vldDecay.SetRange(MIN_Decay, MAX_Decay);
S.AddTextBox(_("Decay factor:"), wxT(""), 10)->SetValidator(vldDecay);
}
S.EndMultiColumn();
}
bool EffectEcho::TransferDataToWindow()
{
if (!mUIParent->TransferDataToWindow())
{
return false;
}
return true;
}
bool EffectEcho::TransferDataFromWindow()
{
if (!mUIParent->Validate() || !mUIParent->TransferDataFromWindow())
{
return false;
}
return true;
}