2010-01-23 19:44:49 +00:00
|
|
|
/**********************************************************************
|
|
|
|
|
|
|
|
Audacity: A Digital Audio Editor
|
|
|
|
|
|
|
|
FindClipping.cpp
|
|
|
|
|
|
|
|
Leland Lucius
|
|
|
|
|
|
|
|
*******************************************************************//**
|
|
|
|
|
|
|
|
\class EffectFindClipping
|
|
|
|
\brief Locates clipping and inserts labels when found
|
|
|
|
|
|
|
|
*//****************************************************************//**
|
|
|
|
|
|
|
|
\class FindClippingDialog
|
|
|
|
\brief FindClippingDialog used with EffectFindClipping
|
|
|
|
|
|
|
|
*//*******************************************************************/
|
|
|
|
|
|
|
|
|
2021-05-09 15:16:56 +00:00
|
|
|
|
2015-06-18 14:24:36 +00:00
|
|
|
#include "FindClipping.h"
|
2019-01-17 23:31:08 +00:00
|
|
|
#include "LoadEffects.h"
|
2010-01-23 19:44:49 +00:00
|
|
|
|
2015-04-17 03:53:42 +00:00
|
|
|
#include <math.h>
|
2010-01-23 19:44:49 +00:00
|
|
|
|
|
|
|
#include <wx/intl.h>
|
2015-04-17 03:53:42 +00:00
|
|
|
|
2019-02-06 18:44:52 +00:00
|
|
|
#include "../Shuttle.h"
|
2015-06-18 14:24:36 +00:00
|
|
|
#include "../ShuttleGui.h"
|
2015-04-17 03:53:42 +00:00
|
|
|
#include "../widgets/valnum.h"
|
2019-05-20 18:27:11 +00:00
|
|
|
#include "../widgets/AudacityMessageBox.h"
|
2010-01-23 19:44:49 +00:00
|
|
|
|
2015-07-04 17:58:01 +00:00
|
|
|
#include "../LabelTrack.h"
|
2015-07-28 14:48:21 +00:00
|
|
|
#include "../WaveTrack.h"
|
2015-07-03 04:20:21 +00:00
|
|
|
|
2015-04-19 03:49:05 +00:00
|
|
|
// Define keys, defaults, minimums, and maximums for the effect parameters
|
|
|
|
//
|
Automation: AudacityCommand
This is a squash of 50 commits.
This merges the capabilities of BatchCommands and Effects using a new
AudacityCommand class. AudacityCommand provides one function to specify the
parameters, and then we leverage that one function in automation, whether by chains,
mod-script-pipe or (future) Nyquist.
- Now have AudacityCommand which is using the same mechanism as Effect
- Has configurable parameters
- Has data-entry GUI (built using shuttle GUI)
- Registers with PluginManager.
- Menu commands now provided in chains, and to python batch.
- Tested with Zoom Toggle.
- ShuttleParams now can set, get, set defaults, validate and specify
the parameters.
- Bugfix: Don't overwrite values with defaults first time out.
- Add DefineParams function for all built-in effects.
- Extend CommandContext to carry output channels for results.
We abuse EffectsManager. It handles both Effects and
AudacityCommands now. In time an Effect should become a special case of
AudacityCommand and we'll split and rename the EffectManager class.
- Don't use 'default' as a parameter name.
- Massive renaming for CommandDefinitionInterface
- EffectIdentInterface becomes EffectDefinitionInterface
- EffectAutomationParameters becomes CommandAutomationParameters
- PluginType is now a bit field.
This way we can search for related types at the same time.
- Most old batch commands made into AudacityCommands.
The ones that weren't are for a reason. They are used by mod-script-pipe
to carry commands and responses across from a non-GUI thread to the GUI
thread.
- Major tidy up of ScreenshotCommand
- Reworking of SelectCommand
- GetPreferenceCommand and SetPreferenceCommand
- GetTrackInfo and SetTrackInfo
- GetInfoCommand
- Help, Open, Save, Import and Export commands.
- Removed obsolete commands ExecMenu, GetProjectInfo and SetProjectInfo
which are now better handled by other commands.
- JSONify "GetInfo: Commands" output, i.e. commas in the right places.
- General work on better Doxygen.
- Lyrics -> LyricsPanel
- Meter -> MeterPanel
- Updated Linux makefile.
- Scripting commands added into Extra menu.
- Distinct names for previously duplicated find-clipping parameters.
- Fixed longstanding error with erroneous status field number which
previously caused an ASSERT in debug.
- Sensible formatting of numbers in Chains, 0.1 not 0.1000000000137
2018-01-14 18:51:41 +00:00
|
|
|
// Name Type Key Def Min Max Scale
|
|
|
|
Param( Start, int, wxT("Duty Cycle Start"), 3, 1, INT_MAX, 1 );
|
|
|
|
Param( Stop, int, wxT("Duty Cycle End"), 3, 1, INT_MAX, 1 );
|
2010-01-23 19:44:49 +00:00
|
|
|
|
2019-01-17 22:33:49 +00:00
|
|
|
const ComponentInterfaceSymbol EffectFindClipping::Symbol
|
|
|
|
{ XO("Find Clipping") };
|
|
|
|
|
2019-01-17 23:31:08 +00:00
|
|
|
namespace{ BuiltinEffectsModule::Registration< EffectFindClipping > reg; }
|
|
|
|
|
2010-01-23 19:44:49 +00:00
|
|
|
EffectFindClipping::EffectFindClipping()
|
|
|
|
{
|
2015-04-17 03:53:42 +00:00
|
|
|
mStart = DEF_Start;
|
|
|
|
mStop = DEF_Stop;
|
2010-01-23 19:44:49 +00:00
|
|
|
}
|
|
|
|
|
2015-04-17 03:53:42 +00:00
|
|
|
EffectFindClipping::~EffectFindClipping()
|
2010-01-23 19:44:49 +00:00
|
|
|
{
|
2014-06-03 20:30:19 +00:00
|
|
|
}
|
2010-01-23 19:44:49 +00:00
|
|
|
|
2018-11-02 15:31:44 +00:00
|
|
|
// ComponentInterface implementation
|
2015-04-17 03:53:42 +00:00
|
|
|
|
2018-11-02 15:31:44 +00:00
|
|
|
ComponentInterfaceSymbol EffectFindClipping::GetSymbol()
|
2010-01-23 19:44:49 +00:00
|
|
|
{
|
2019-01-17 22:33:49 +00:00
|
|
|
return Symbol;
|
2015-04-17 03:53:42 +00:00
|
|
|
}
|
2010-01-23 19:44:49 +00:00
|
|
|
|
2019-12-08 18:53:48 +00:00
|
|
|
TranslatableString EffectFindClipping::GetDescription()
|
2015-04-17 03:53:42 +00:00
|
|
|
{
|
2019-12-08 18:53:48 +00:00
|
|
|
return XO("Creates labels where clipping is detected");
|
2015-04-17 03:53:42 +00:00
|
|
|
}
|
|
|
|
|
2021-06-06 16:18:35 +00:00
|
|
|
ManualPageID EffectFindClipping::ManualPage()
|
2017-05-20 13:40:09 +00:00
|
|
|
{
|
2021-06-06 16:18:35 +00:00
|
|
|
return L"Find_Clipping";
|
2017-05-20 13:40:09 +00:00
|
|
|
}
|
|
|
|
|
Automation: AudacityCommand
This is a squash of 50 commits.
This merges the capabilities of BatchCommands and Effects using a new
AudacityCommand class. AudacityCommand provides one function to specify the
parameters, and then we leverage that one function in automation, whether by chains,
mod-script-pipe or (future) Nyquist.
- Now have AudacityCommand which is using the same mechanism as Effect
- Has configurable parameters
- Has data-entry GUI (built using shuttle GUI)
- Registers with PluginManager.
- Menu commands now provided in chains, and to python batch.
- Tested with Zoom Toggle.
- ShuttleParams now can set, get, set defaults, validate and specify
the parameters.
- Bugfix: Don't overwrite values with defaults first time out.
- Add DefineParams function for all built-in effects.
- Extend CommandContext to carry output channels for results.
We abuse EffectsManager. It handles both Effects and
AudacityCommands now. In time an Effect should become a special case of
AudacityCommand and we'll split and rename the EffectManager class.
- Don't use 'default' as a parameter name.
- Massive renaming for CommandDefinitionInterface
- EffectIdentInterface becomes EffectDefinitionInterface
- EffectAutomationParameters becomes CommandAutomationParameters
- PluginType is now a bit field.
This way we can search for related types at the same time.
- Most old batch commands made into AudacityCommands.
The ones that weren't are for a reason. They are used by mod-script-pipe
to carry commands and responses across from a non-GUI thread to the GUI
thread.
- Major tidy up of ScreenshotCommand
- Reworking of SelectCommand
- GetPreferenceCommand and SetPreferenceCommand
- GetTrackInfo and SetTrackInfo
- GetInfoCommand
- Help, Open, Save, Import and Export commands.
- Removed obsolete commands ExecMenu, GetProjectInfo and SetProjectInfo
which are now better handled by other commands.
- JSONify "GetInfo: Commands" output, i.e. commas in the right places.
- General work on better Doxygen.
- Lyrics -> LyricsPanel
- Meter -> MeterPanel
- Updated Linux makefile.
- Scripting commands added into Extra menu.
- Distinct names for previously duplicated find-clipping parameters.
- Fixed longstanding error with erroneous status field number which
previously caused an ASSERT in debug.
- Sensible formatting of numbers in Chains, 0.1 not 0.1000000000137
2018-01-14 18:51:41 +00:00
|
|
|
// EffectDefinitionInterface implementation
|
2015-04-17 03:53:42 +00:00
|
|
|
|
|
|
|
EffectType EffectFindClipping::GetType()
|
|
|
|
{
|
|
|
|
return EffectTypeAnalyze;
|
|
|
|
}
|
|
|
|
|
|
|
|
// EffectClientInterface implementation
|
Automation: AudacityCommand
This is a squash of 50 commits.
This merges the capabilities of BatchCommands and Effects using a new
AudacityCommand class. AudacityCommand provides one function to specify the
parameters, and then we leverage that one function in automation, whether by chains,
mod-script-pipe or (future) Nyquist.
- Now have AudacityCommand which is using the same mechanism as Effect
- Has configurable parameters
- Has data-entry GUI (built using shuttle GUI)
- Registers with PluginManager.
- Menu commands now provided in chains, and to python batch.
- Tested with Zoom Toggle.
- ShuttleParams now can set, get, set defaults, validate and specify
the parameters.
- Bugfix: Don't overwrite values with defaults first time out.
- Add DefineParams function for all built-in effects.
- Extend CommandContext to carry output channels for results.
We abuse EffectsManager. It handles both Effects and
AudacityCommands now. In time an Effect should become a special case of
AudacityCommand and we'll split and rename the EffectManager class.
- Don't use 'default' as a parameter name.
- Massive renaming for CommandDefinitionInterface
- EffectIdentInterface becomes EffectDefinitionInterface
- EffectAutomationParameters becomes CommandAutomationParameters
- PluginType is now a bit field.
This way we can search for related types at the same time.
- Most old batch commands made into AudacityCommands.
The ones that weren't are for a reason. They are used by mod-script-pipe
to carry commands and responses across from a non-GUI thread to the GUI
thread.
- Major tidy up of ScreenshotCommand
- Reworking of SelectCommand
- GetPreferenceCommand and SetPreferenceCommand
- GetTrackInfo and SetTrackInfo
- GetInfoCommand
- Help, Open, Save, Import and Export commands.
- Removed obsolete commands ExecMenu, GetProjectInfo and SetProjectInfo
which are now better handled by other commands.
- JSONify "GetInfo: Commands" output, i.e. commas in the right places.
- General work on better Doxygen.
- Lyrics -> LyricsPanel
- Meter -> MeterPanel
- Updated Linux makefile.
- Scripting commands added into Extra menu.
- Distinct names for previously duplicated find-clipping parameters.
- Fixed longstanding error with erroneous status field number which
previously caused an ASSERT in debug.
- Sensible formatting of numbers in Chains, 0.1 not 0.1000000000137
2018-01-14 18:51:41 +00:00
|
|
|
bool EffectFindClipping::DefineParams( ShuttleParams & S ){
|
|
|
|
S.SHUTTLE_PARAM( mStart, Start );
|
|
|
|
S.SHUTTLE_PARAM( mStop, Stop );
|
|
|
|
return true;
|
|
|
|
}
|
2015-04-17 03:53:42 +00:00
|
|
|
|
2018-02-21 14:24:25 +00:00
|
|
|
bool EffectFindClipping::GetAutomationParameters(CommandParameters & parms)
|
2015-04-17 03:53:42 +00:00
|
|
|
{
|
2015-04-19 03:49:05 +00:00
|
|
|
parms.Write(KEY_Start, mStart);
|
|
|
|
parms.Write(KEY_Stop, mStop);
|
2010-01-23 19:44:49 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2018-02-21 14:24:25 +00:00
|
|
|
bool EffectFindClipping::SetAutomationParameters(CommandParameters & parms)
|
2014-06-03 20:30:19 +00:00
|
|
|
{
|
2015-04-19 03:49:05 +00:00
|
|
|
ReadAndVerifyInt(Start);
|
|
|
|
ReadAndVerifyInt(Stop);
|
2015-04-17 03:53:42 +00:00
|
|
|
|
2015-04-19 03:49:05 +00:00
|
|
|
mStart = Start;
|
|
|
|
mStop = Stop;
|
2010-01-23 19:44:49 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-04-17 03:53:42 +00:00
|
|
|
// Effect implementation
|
|
|
|
|
2010-01-23 19:44:49 +00:00
|
|
|
bool EffectFindClipping::Process()
|
|
|
|
{
|
2016-03-07 06:29:26 +00:00
|
|
|
std::shared_ptr<AddedAnalysisTrack> addedTrack;
|
2020-01-19 14:51:50 +00:00
|
|
|
Optional<ModifiedAnalysisTrack> modifiedTrack;
|
2016-02-27 19:24:57 +00:00
|
|
|
const wxString name{ _("Clipping") };
|
2010-01-23 19:44:49 +00:00
|
|
|
|
2016-12-31 09:33:35 +00:00
|
|
|
auto clt = *inputTracks()->Any< const LabelTrack >().find_if(
|
|
|
|
[&]( const Track *track ){ return track->GetName() == name; } );
|
2014-06-03 20:30:19 +00:00
|
|
|
|
2016-12-31 09:33:35 +00:00
|
|
|
LabelTrack *lt{};
|
|
|
|
if (!clt)
|
2016-03-07 06:29:26 +00:00
|
|
|
addedTrack = (AddAnalysisTrack(name)), lt = addedTrack->get();
|
2016-02-27 19:24:57 +00:00
|
|
|
else
|
2020-01-19 14:51:50 +00:00
|
|
|
modifiedTrack.emplace(ModifyAnalysisTrack(clt, name)),
|
2016-12-31 09:33:35 +00:00
|
|
|
lt = modifiedTrack->get();
|
2010-01-23 19:44:49 +00:00
|
|
|
|
|
|
|
int count = 0;
|
|
|
|
|
|
|
|
// JC: Only process selected tracks.
|
2016-12-31 09:33:35 +00:00
|
|
|
for (auto t : inputTracks()->Selected< const WaveTrack >()) {
|
2010-01-23 19:44:49 +00:00
|
|
|
double trackStart = t->GetStartTime();
|
|
|
|
double trackEnd = t->GetEndTime();
|
|
|
|
double t0 = mT0 < trackStart ? trackStart : mT0;
|
|
|
|
double t1 = mT1 > trackEnd ? trackEnd : mT1;
|
|
|
|
|
|
|
|
if (t1 > t0) {
|
2016-08-24 15:24:26 +00:00
|
|
|
auto start = t->TimeToLongSamples(t0);
|
|
|
|
auto end = t->TimeToLongSamples(t1);
|
|
|
|
auto len = end - start;
|
2010-01-23 19:44:49 +00:00
|
|
|
|
2016-02-27 19:24:57 +00:00
|
|
|
if (!ProcessOne(lt, count, t, start, len)) {
|
2010-01-23 19:44:49 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
count++;
|
|
|
|
}
|
|
|
|
|
2016-02-27 19:24:57 +00:00
|
|
|
// No cancellation, so commit the addition of the track.
|
|
|
|
if (addedTrack)
|
|
|
|
addedTrack->Commit();
|
|
|
|
if (modifiedTrack)
|
|
|
|
modifiedTrack->Commit();
|
2010-01-23 19:44:49 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-02-27 19:24:57 +00:00
|
|
|
bool EffectFindClipping::ProcessOne(LabelTrack * lt,
|
2010-01-23 19:44:49 +00:00
|
|
|
int count,
|
2016-02-27 19:24:57 +00:00
|
|
|
const WaveTrack * wt,
|
2010-01-23 19:44:49 +00:00
|
|
|
sampleCount start,
|
|
|
|
sampleCount len)
|
|
|
|
{
|
|
|
|
bool bGoodResult = true;
|
2016-09-06 13:19:27 +00:00
|
|
|
size_t blockSize = (mStart * 1000);
|
2014-06-03 20:30:19 +00:00
|
|
|
|
2010-01-23 19:44:49 +00:00
|
|
|
if (len < mStart) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-04-14 16:35:15 +00:00
|
|
|
Floats buffer;
|
2016-08-28 19:49:55 +00:00
|
|
|
try {
|
2017-12-08 11:26:09 +00:00
|
|
|
// mStart should be positive.
|
|
|
|
// if we are throwing bad_alloc and mStart is negative, find out why.
|
2018-01-23 11:49:15 +00:00
|
|
|
if (mStart < 0 || (int)blockSize < mStart)
|
2016-08-28 19:49:55 +00:00
|
|
|
// overflow
|
|
|
|
throw std::bad_alloc{};
|
2016-04-14 16:35:15 +00:00
|
|
|
buffer.reinit(blockSize);
|
2016-08-28 19:49:55 +00:00
|
|
|
}
|
|
|
|
catch( const std::bad_alloc & ) {
|
2019-12-19 19:19:51 +00:00
|
|
|
Effect::MessageBox( XO("Requested value exceeds memory capacity.") );
|
2016-08-28 19:49:55 +00:00
|
|
|
return false;
|
|
|
|
}
|
2010-01-23 19:44:49 +00:00
|
|
|
|
2016-04-14 16:35:15 +00:00
|
|
|
float *ptr = buffer.get();
|
2010-01-23 19:44:49 +00:00
|
|
|
|
2016-08-24 15:24:26 +00:00
|
|
|
decltype(len) s = 0, startrun = 0, stoprun = 0, samps = 0;
|
2016-08-24 11:56:33 +00:00
|
|
|
decltype(blockSize) block = 0;
|
2010-01-23 19:44:49 +00:00
|
|
|
double startTime = -1.0;
|
2014-06-03 20:30:19 +00:00
|
|
|
|
2010-01-23 19:44:49 +00:00
|
|
|
while (s < len) {
|
|
|
|
if (block == 0) {
|
2016-08-25 12:53:59 +00:00
|
|
|
if (TrackProgress(count,
|
|
|
|
s.as_double() /
|
|
|
|
len.as_double() )) {
|
2010-01-23 19:44:49 +00:00
|
|
|
bGoodResult = false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2016-08-21 22:05:43 +00:00
|
|
|
block = limitSampleBufferSize( blockSize, len - s );
|
2010-01-23 19:44:49 +00:00
|
|
|
|
2021-05-23 21:43:38 +00:00
|
|
|
wt->GetFloats(buffer.get(), start + s, block);
|
2016-04-14 16:35:15 +00:00
|
|
|
ptr = buffer.get();
|
2010-01-23 19:44:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
float v = fabs(*ptr++);
|
|
|
|
if (v >= MAX_AUDIO) {
|
|
|
|
if (startrun == 0) {
|
2016-02-27 19:24:57 +00:00
|
|
|
startTime = wt->LongSamplesToTime(start + s);
|
2010-01-23 19:44:49 +00:00
|
|
|
samps = 0;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
stoprun = 0;
|
|
|
|
}
|
|
|
|
startrun++;
|
|
|
|
samps++;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (startrun >= mStart) {
|
|
|
|
stoprun++;
|
|
|
|
samps++;
|
|
|
|
|
|
|
|
if (stoprun >= mStop) {
|
2016-02-27 19:24:57 +00:00
|
|
|
lt->AddLabel(SelectedRegion(startTime,
|
|
|
|
wt->LongSamplesToTime(start + s - mStop)),
|
2018-12-05 21:16:31 +00:00
|
|
|
wxString::Format(wxT("%lld of %lld"), startrun.as_long_long(), (samps - mStop).as_long_long()));
|
2010-01-23 19:44:49 +00:00
|
|
|
startrun = 0;
|
|
|
|
stoprun = 0;
|
|
|
|
samps = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
startrun = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
s++;
|
|
|
|
block--;
|
|
|
|
}
|
|
|
|
|
|
|
|
return bGoodResult;
|
|
|
|
}
|
|
|
|
|
2015-04-17 03:53:42 +00:00
|
|
|
void EffectFindClipping::PopulateOrExchange(ShuttleGui & S)
|
2010-01-23 19:44:49 +00:00
|
|
|
{
|
|
|
|
S.StartMultiColumn(2, wxALIGN_CENTER);
|
|
|
|
{
|
2017-10-30 16:23:41 +00:00
|
|
|
S.Validator<IntegerValidator<int>>(
|
|
|
|
&mStart, NumValidatorStyle::DEFAULT, MIN_Start)
|
2020-05-11 15:28:14 +00:00
|
|
|
.TieTextBox(XXO("&Start threshold (samples):"), mStart, 10);
|
2017-10-30 16:23:41 +00:00
|
|
|
|
|
|
|
S.Validator<IntegerValidator<int>>(
|
|
|
|
&mStop, NumValidatorStyle::DEFAULT, MIN_Stop)
|
2020-05-11 15:28:14 +00:00
|
|
|
.TieTextBox(XXO("St&op threshold (samples):"), mStop, 10);
|
2010-01-23 19:44:49 +00:00
|
|
|
}
|
|
|
|
S.EndMultiColumn();
|
|
|
|
}
|
|
|
|
|
2015-04-17 03:53:42 +00:00
|
|
|
bool EffectFindClipping::TransferDataToWindow()
|
2010-01-23 19:44:49 +00:00
|
|
|
{
|
2015-04-17 03:53:42 +00:00
|
|
|
ShuttleGui S(mUIParent, eIsSettingToDialog);
|
|
|
|
PopulateOrExchange(S);
|
2010-01-23 19:44:49 +00:00
|
|
|
|
2015-04-17 03:53:42 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool EffectFindClipping::TransferDataFromWindow()
|
|
|
|
{
|
|
|
|
if (!mUIParent->Validate())
|
|
|
|
{
|
2010-01-23 19:44:49 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-04-17 03:53:42 +00:00
|
|
|
ShuttleGui S(mUIParent, eIsGettingFromDialog);
|
|
|
|
PopulateOrExchange(S);
|
|
|
|
|
2010-01-23 19:44:49 +00:00
|
|
|
return true;
|
|
|
|
}
|