1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-06-15 15:49:36 +02:00

Start work on new Loudness effect

This is based on my old loudness effect prototype which was included
in the Normalize effect.

Create all source files and add them to all build systems.
Currently, the effect only consists of a GUI mockup.
Create Octave+mod-script-pipe based dummy unit-test as well.
This commit is contained in:
Max Maisel 2019-03-15 15:56:17 +01:00
parent eb2161d3aa
commit 6da48db127
11 changed files with 733 additions and 2 deletions

View File

@ -284,6 +284,7 @@
1790B13F09883BFD008A330A /* LadspaEffect.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1790B02609883BFD008A330A /* LadspaEffect.cpp */; };
1790B14109883BFD008A330A /* Leveller.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1790B02A09883BFD008A330A /* Leveller.cpp */; };
1790B14209883BFD008A330A /* LoadEffects.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1790B02C09883BFD008A330A /* LoadEffects.cpp */; };
1790B14219883BFD008A330A /* Loudness.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1790B02D19883BFD008A330A /* Loudness.cpp */; };
1790B14309883BFD008A330A /* Noise.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1790B02E09883BFD008A330A /* Noise.cpp */; };
1790B14409883BFD008A330A /* NoiseRemoval.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1790B03009883BFD008A330A /* NoiseRemoval.cpp */; };
1790B14509883BFD008A330A /* Normalize.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1790B03209883BFD008A330A /* Normalize.cpp */; };
@ -2012,6 +2013,8 @@
1790B02B09883BFD008A330A /* Leveller.h */ = {isa = PBXFileReference; fileEncoding = 30; indentWidth = 3; lastKnownFileType = sourcecode.c.h; path = Leveller.h; sourceTree = "<group>"; tabWidth = 3; };
1790B02C09883BFD008A330A /* LoadEffects.cpp */ = {isa = PBXFileReference; fileEncoding = 30; indentWidth = 3; lastKnownFileType = sourcecode.cpp.cpp; path = LoadEffects.cpp; sourceTree = "<group>"; tabWidth = 3; };
1790B02D09883BFD008A330A /* LoadEffects.h */ = {isa = PBXFileReference; fileEncoding = 30; indentWidth = 3; lastKnownFileType = sourcecode.c.h; path = LoadEffects.h; sourceTree = "<group>"; tabWidth = 3; };
1790B02D19883BFD008A330A /* Loudness.cpp */ = {isa = PBXFileReference; fileEncoding = 30; indentWidth = 3; lastKnownFileType = sourcecode.cpp.cpp; path = Loudness.cpp; sourceTree = "<group>"; tabWidth = 3; };
1790B02D29883BFD008A330A /* Loudness.h */ = {isa = PBXFileReference; fileEncoding = 30; indentWidth = 3; lastKnownFileType = sourcecode.c.h; path = Loudness.h; sourceTree = "<group>"; tabWidth = 3; };
1790B02E09883BFD008A330A /* Noise.cpp */ = {isa = PBXFileReference; fileEncoding = 30; indentWidth = 3; lastKnownFileType = sourcecode.cpp.cpp; path = Noise.cpp; sourceTree = "<group>"; tabWidth = 3; };
1790B02F09883BFD008A330A /* Noise.h */ = {isa = PBXFileReference; fileEncoding = 30; indentWidth = 3; lastKnownFileType = sourcecode.c.h; path = Noise.h; sourceTree = "<group>"; tabWidth = 3; };
1790B03009883BFD008A330A /* NoiseRemoval.cpp */ = {isa = PBXFileReference; fileEncoding = 30; indentWidth = 3; lastKnownFileType = sourcecode.cpp.cpp; path = NoiseRemoval.cpp; sourceTree = "<group>"; tabWidth = 3; };
@ -4744,6 +4747,8 @@
1790B02B09883BFD008A330A /* Leveller.h */,
1790B02C09883BFD008A330A /* LoadEffects.cpp */,
1790B02D09883BFD008A330A /* LoadEffects.h */,
1790B02D19883BFD008A330A /* Loudness.cpp */,
1790B02D29883BFD008A330A /* Loudness.h */,
28D587C50E264CBB009C7DEA /* lv2 */,
1790B02E09883BFD008A330A /* Noise.cpp */,
1790B02F09883BFD008A330A /* Noise.h */,
@ -8442,6 +8447,7 @@
5E000A211EC7B5D500E8FD93 /* SampleHandle.cpp in Sources */,
1790B14109883BFD008A330A /* Leveller.cpp in Sources */,
1790B14209883BFD008A330A /* LoadEffects.cpp in Sources */,
1790B14219883BFD008A330A /* Loudness.cpp in Sources */,
5E0784311DF1E4F400CA76EA /* UserException.cpp in Sources */,
5E36A0A8217FA2430068E082 /* EditMenus.cpp in Sources */,
1790B14309883BFD008A330A /* Noise.cpp in Sources */,

View File

@ -252,6 +252,7 @@ set( EFFECTS_SOURCE
${CMAKE_SOURCE_DIRECTORY}effects/Invert.cpp
${CMAKE_SOURCE_DIRECTORY}effects/Leveller.cpp
${CMAKE_SOURCE_DIRECTORY}effects/LoadEffects.cpp
${CMAKE_SOURCE_DIRECTORY}effects/Loudness.cpp
${CMAKE_SOURCE_DIRECTORY}effects/Noise.cpp
${CMAKE_SOURCE_DIRECTORY}effects/NoiseReduction.cpp
${CMAKE_SOURCE_DIRECTORY}effects/NoiseRemoval.cpp

View File

@ -449,6 +449,8 @@ audacity_SOURCES = \
effects/Invert.h \
effects/LoadEffects.cpp \
effects/LoadEffects.h \
effects/Loudness.cpp \
effects/Loudness.h \
effects/Noise.cpp \
effects/Noise.h \
effects/NoiseReduction.cpp \

View File

@ -31,6 +31,7 @@
#include "Equalization.h"
#include "Fade.h"
#include "Invert.h"
#include "Loudness.h"
#include "Noise.h"
#ifdef EXPERIMENTAL_NOISE_REDUCTION
#include "NoiseReduction.h"
@ -122,6 +123,7 @@
EFFECT( FILTER_CURVE, EffectEqualization, (kEqOptionCurve) ) \
EFFECT( GRAPHIC_EQ, EffectEqualization, (kEqOptionGraphic) ) \
EFFECT( INVERT, EffectInvert, () ) \
EFFECT( LOUDNESS , EffectLoudness, () ) \
EFFECT( NORMALIZE, EffectNormalize, () ) \
EFFECT( PHASER, EffectPhaser, () ) \
EFFECT( REPAIR, EffectRepair, () ) \

297
src/effects/Loudness.cpp Normal file
View File

@ -0,0 +1,297 @@
/**********************************************************************
Audacity: A Digital Audio Editor
Loudness.cpp
Max Maisel
*******************************************************************//**
\class EffectLoudness
\brief An Effect to bring the loudness level up to a chosen level.
*//*******************************************************************/
#include "../Audacity.h" // for rint from configwin.h
#include "Loudness.h"
#include <math.h>
#include <wx/intl.h>
#include <wx/valgen.h>
#include "../Internat.h"
#include "../Prefs.h"
#include "../Shuttle.h"
#include "../ShuttleGui.h"
#include "../WaveTrack.h"
#include "../widgets/valnum.h"
enum kNormalizeTargets
{
kLoudness,
kRMS,
nAlgos
};
static const ComponentInterfaceSymbol kNormalizeTargetStrings[nAlgos] =
{
{ XO("perceived loudness") },
{ XO("RMS") }
};
// Define keys, defaults, minimums, and maximums for the effect parameters
//
// Name Type Key Def Min Max Scale
Param( StereoInd, bool, wxT("StereoIndependent"), false, false, true, 1 );
Param( LUFSLevel, double, wxT("LUFSLevel"), -23.0, -145.0, 0.0, 1 );
Param( RMSLevel, double, wxT("RMSLevel"), -20.0, -145.0, 0.0, 1 );
Param( DualMono, bool, wxT("DualMono"), true, false, true, 1 );
Param( NormalizeTo, int, wxT("NormalizeTo"), kLoudness , 0 , nAlgos-1, 1 );
BEGIN_EVENT_TABLE(EffectLoudness, wxEvtHandler)
EVT_CHOICE(wxID_ANY, EffectLoudness::OnUpdateUI)
EVT_CHECKBOX(wxID_ANY, EffectLoudness::OnUpdateUI)
EVT_TEXT(wxID_ANY, EffectLoudness::OnUpdateUI)
END_EVENT_TABLE()
EffectLoudness::EffectLoudness()
{
mStereoInd = DEF_StereoInd;
mLUFSLevel = DEF_LUFSLevel;
mRMSLevel = DEF_RMSLevel;
mDualMono = DEF_DualMono;
mNormalizeTo = DEF_NormalizeTo;
SetLinearEffectFlag(false);
}
EffectLoudness::~EffectLoudness()
{
}
// ComponentInterface implementation
ComponentInterfaceSymbol EffectLoudness::GetSymbol()
{
return LOUDNESS_PLUGIN_SYMBOL;
}
wxString EffectLoudness::GetDescription()
{
return _("Sets the loudness of one or more tracks");
}
wxString EffectLoudness::ManualPage()
{
return wxT("Loudness");
}
// EffectDefinitionInterface implementation
EffectType EffectLoudness::GetType()
{
return EffectTypeProcess;
}
// EffectClientInterface implementation
bool EffectLoudness::DefineParams( ShuttleParams & S )
{
S.SHUTTLE_PARAM( mStereoInd, StereoInd );
S.SHUTTLE_PARAM( mLUFSLevel, LUFSLevel );
S.SHUTTLE_PARAM( mRMSLevel, RMSLevel );
S.SHUTTLE_PARAM( mDualMono, DualMono );
S.SHUTTLE_PARAM( mNormalizeTo, NormalizeTo );
return true;
}
bool EffectLoudness::GetAutomationParameters(CommandParameters & parms)
{
parms.Write(KEY_StereoInd, mStereoInd);
parms.Write(KEY_LUFSLevel, mLUFSLevel);
parms.Write(KEY_RMSLevel, mRMSLevel);
parms.Write(KEY_DualMono, mDualMono);
parms.Write(KEY_NormalizeTo, mNormalizeTo);
return true;
}
bool EffectLoudness::SetAutomationParameters(CommandParameters & parms)
{
ReadAndVerifyBool(StereoInd);
ReadAndVerifyDouble(LUFSLevel);
ReadAndVerifyDouble(RMSLevel);
ReadAndVerifyBool(DualMono);
ReadAndVerifyBool(NormalizeTo);
mStereoInd = StereoInd;
mLUFSLevel = LUFSLevel;
mRMSLevel = RMSLevel;
mDualMono = DualMono;
mNormalizeTo = NormalizeTo;
return true;
}
// Effect implementation
bool EffectLoudness::CheckWhetherSkipEffect()
{
return false;
}
bool EffectLoudness::Startup()
{
wxString base = wxT("/Effects/Loudness/");
// Load the old "current" settings
if (gPrefs->Exists(base))
{
mStereoInd = true;
mDualMono = DEF_DualMono;
mNormalizeTo = kLoudness;
mLUFSLevel = DEF_LUFSLevel;
mRMSLevel = DEF_RMSLevel;
SaveUserPreset(GetCurrentSettingsGroup());
gPrefs->Flush();
}
return true;
}
bool EffectLoudness::Process()
{
// TODO
return true;
}
void EffectLoudness::PopulateOrExchange(ShuttleGui & S)
{
S.StartVerticalLay(0);
{
S.StartMultiColumn(2, wxALIGN_CENTER);
{
S.StartVerticalLay(false);
{
S.StartHorizontalLay(wxALIGN_LEFT, false);
{
S.AddVariableText(_("Normalize"), false,
wxALIGN_CENTER_VERTICAL | wxALIGN_LEFT);
auto targetChoices = LocalizedStrings(kNormalizeTargetStrings, nAlgos);
mNormalizeToCtl = S.AddChoice(wxEmptyString, targetChoices, mNormalizeTo);
mNormalizeToCtl->SetValidator(wxGenericValidator(&mNormalizeTo));
S.AddVariableText(_("to"), false,
wxALIGN_CENTER_VERTICAL | wxALIGN_LEFT);
FloatingPointValidator<double> vldLevel(2, &mLUFSLevel,
NumValidatorStyle::ONE_TRAILING_ZERO);
vldLevel.SetRange( MIN_LUFSLevel, MAX_LUFSLevel);
mLevelTextCtrl = S.AddTextBox( {}, wxT(""), 10);
/* i18n-hint: LUFS is a particular method for measuring loudnesss */
mLevelTextCtrl->SetName( _("Loudness LUFS"));
mLevelTextCtrl->SetValidator(vldLevel);
/* i18n-hint: LUFS is a particular method for measuring loudnesss */
mLeveldB = S.AddVariableText(_("LUFS"), false,
wxALIGN_CENTER_VERTICAL | wxALIGN_LEFT);
mWarning = S.AddVariableText( {}, false,
wxALIGN_CENTER_VERTICAL | wxALIGN_LEFT);
}
S.EndHorizontalLay();
mStereoIndCheckBox = S.AddCheckBox(_("Normalize stereo channels independently"),
mStereoInd ? wxT("true") : wxT("false"));
mStereoIndCheckBox->SetValidator(wxGenericValidator(&mStereoInd));
mDualMonoCheckBox = S.AddCheckBox(_("Treat mono as dual-mono (recommended)"),
mDualMono ? wxT("true") : wxT("false"));
mDualMonoCheckBox->SetValidator(wxGenericValidator(&mDualMono));
}
S.EndVerticalLay();
}
S.EndMultiColumn();
}
S.EndVerticalLay();
// To ensure that the UpdateUI on creation sets the prompts correctly.
mGUINormalizeTo = !mNormalizeTo;
}
bool EffectLoudness::TransferDataToWindow()
{
if (!mUIParent->TransferDataToWindow())
{
return false;
}
UpdateUI();
return true;
}
bool EffectLoudness::TransferDataFromWindow()
{
if (!mUIParent->Validate() || !mUIParent->TransferDataFromWindow())
{
return false;
}
return true;
}
// EffectLoudness implementation
// TODO
bool EffectLoudness::UpdateProgress()
{
mProgressVal += (double(1+mProcStereo) * double(mTrackBufferLen)
/ (double(GetNumWaveTracks()) * double(mSteps) * mTrackLen));
return !TotalProgress(mProgressVal, mProgressMsg);
}
void EffectLoudness::OnUpdateUI(wxCommandEvent & WXUNUSED(evt))
{
UpdateUI();
}
void EffectLoudness::UpdateUI()
{
if (!mUIParent->TransferDataFromWindow())
{
mWarning->SetLabel(_("(Maximum 0dB)"));
// TODO: recalculate layout here
EnableApply(false);
return;
}
mWarning->SetLabel(wxT(""));
EnableApply(true);
// Changing the prompts causes an unwanted UpdateUI event.
// This 'guard' stops that becoming an infinite recursion.
if (mNormalizeTo != mGUINormalizeTo)
{
mGUINormalizeTo = mNormalizeTo;
if(mNormalizeTo == kLoudness)
{
FloatingPointValidator<double> vldLevel(2, &mLUFSLevel, NumValidatorStyle::ONE_TRAILING_ZERO);
vldLevel.SetRange(MIN_LUFSLevel, MAX_LUFSLevel);
mLevelTextCtrl->SetValidator(vldLevel);
/* i18n-hint: LUFS is a particular method for measuring loudnesss */
mLevelTextCtrl->SetName(_("Loudness LUFS"));
mLevelTextCtrl->SetValue(wxString::FromDouble(mLUFSLevel));
/* i18n-hint: LUFS is a particular method for measuring loudnesss */
mLeveldB->SetLabel(_("LUFS"));
}
else // RMS
{
FloatingPointValidator<double> vldLevel(2, &mRMSLevel, NumValidatorStyle::ONE_TRAILING_ZERO);
vldLevel.SetRange(MIN_RMSLevel, MAX_RMSLevel);
mLevelTextCtrl->SetValidator(vldLevel);
mLevelTextCtrl->SetName(_("RMS dB"));
mLevelTextCtrl->SetValue(wxString::FromDouble(mRMSLevel));
mLeveldB->SetLabel(_("dB"));
}
}
mDualMonoCheckBox->Enable(mNormalizeTo == kLoudness);
}

99
src/effects/Loudness.h Normal file
View File

@ -0,0 +1,99 @@
/**********************************************************************
Audacity: A Digital Audio Editor
Loudness.h
Max Maisel
**********************************************************************/
#ifndef __AUDACITY_EFFECT_LOUDNESS__
#define __AUDACITY_EFFECT_LOUDNESS__
#include <wx/checkbox.h>
#include <wx/choice.h>
#include <wx/event.h>
#include <wx/stattext.h>
#include <wx/string.h>
#include <wx/textctrl.h>
#include "Effect.h"
#include "Biquad.h"
class ShuttleGui;
#define LOUDNESS_PLUGIN_SYMBOL ComponentInterfaceSymbol{ XO("Loudness") }
class EffectLoudness final : public Effect
{
public:
EffectLoudness();
virtual ~EffectLoudness();
// ComponentInterface implementation
ComponentInterfaceSymbol GetSymbol() override;
wxString GetDescription() override;
wxString ManualPage() override;
// EffectDefinitionInterface implementation
EffectType GetType() override;
// EffectClientInterface implementation
bool DefineParams( ShuttleParams & S ) override;
bool GetAutomationParameters(CommandParameters & parms) override;
bool SetAutomationParameters(CommandParameters & parms) override;
// Effect implementation
bool CheckWhetherSkipEffect() override;
bool Startup() override;
bool Process() override;
void PopulateOrExchange(ShuttleGui & S) override;
bool TransferDataToWindow() override;
bool TransferDataFromWindow() override;
private:
// EffectLoudness implementation
bool UpdateProgress();
void OnUpdateUI(wxCommandEvent & evt);
void UpdateUI();
private:
bool mStereoInd;
double mLUFSLevel;
double mRMSLevel;
bool mDualMono;
int mNormalizeTo;
int mGUINormalizeTo;
double mCurT0;
double mCurT1;
double mProgressVal;
int mSteps;
wxString mProgressMsg;
double mTrackLen;
double mCurRate;
sampleCount mCount;
wxTextCtrl *mLevelTextCtrl;
wxStaticText *mLeveldB;
wxStaticText *mWarning;
wxCheckBox *mStereoIndCheckBox;
wxChoice *mNormalizeToCtl;
wxCheckBox *mDualMonoCheckBox;
Floats mTrackBuffer[2]; // MM: must be increased once surround channels are supported
size_t mTrackBufferLen;
size_t mTrackBufferCapacity;
bool mProcStereo;
DECLARE_EVENT_TABLE()
};
#endif

16
tests/octave/README.md Normal file
View File

@ -0,0 +1,16 @@
# Unit tests for Audacity effects
These unit tests check the correctness of Audacity's effect calculations
against GNU octave. Therefore some simple deterministic and random
sample data is generated and passed to Audacity via mod-script-pipe.
To run a test, run: (replace `<desired_test.m>` with the correct filename)
```
./run_test.m <desired_test.m>
```
The tests will print the results to the terminal and will return 0 on
success and non-zero on error.
To run those tests you need a Linux system with GNU Octave,
octave-forge-signal and Audacity mod-script-pipe installed.

View File

@ -0,0 +1,126 @@
## Audacity Loudness effect unit test
#
# Max Maisel
#
# This tests the Loudness effect with 30 seconds long pseudo-random stereo
# noise sequences. The test sequences have different amplitudes per
# channel and sometimes a DC component. For best test coverage, irrelevant
# parameters for the current operation are randomly varied.
#
printf("Running Loudness effect tests.\n");
printf("This requires the octave-forge-signal package to be installed.\n");
pkg load signal;
EXPORT_TEST_SIGNALS = true;
TEST_LUFS_HELPER = true;
# LUFS need a higher epsilon because they are a logarithmic unit.
LUFS_epsilon = 0.02;
# A straightforward and simple LUFS implementation which can
# be easily compared with the specification ITU-R BS.1770-4.
function [gated_lufs] = calc_LUFS(x, fs)
# HSF
f0 = 38.13547087602444;
Q = 0.5003270373238773;
K = tan(pi * f0 / fs);
rb0 = 1.0;
rb1 = -2.0;
rb2 = 1.0;
ra0 = 1.0;
ra1 = 2.0 * (K * K - 1.0) / (1.0 + K / Q + K * K);
ra2 = (1.0 - K / Q + K * K) / (1.0 + K / Q + K * K);
rb = [rb0 rb1 rb2];
ra = [ra0 ra1 ra2];
# HPF
db = 3.999843853973347;
f0 = 1681.974450955533;
Q = 0.7071752369554196;
K = tan(pi * f0 / fs);
Vh = power(10.0, db / 20.0);
Vb = power(Vh, 0.4996667741545416);
pa0 = 1.0;
a0 = 1.0 + K / Q + K * K;
pb0 = (Vh + Vb * K / Q + K * K) / a0;
pb1 = 2.0 * (K * K - Vh) / a0;
pb2 = (Vh - Vb * K / Q + K * K) / a0;
pa1 = 2.0 * (K * K - 1.0) / a0;
pa2 = (1.0 - K / Q + K * K) / a0;
pb = [pb0 pb1 pb2];
pa = [pa0 pa1 pa2];
# Apply k-weighting
x = filter(rb, ra, x, [], 1);
x = filter(pb, pa, x, [], 1);
# - gating blocks (every 100 ms over 400 ms)
block_size = 0.4*fs;
block_overlap = 0.3*fs;
block_count = floor((size(x)(1)-block_size)/(block_size-block_overlap))+1+1;
x_blocked = zeros(block_size, block_count, size(x)(2));
for i=1:1:size(x)(2)
x_blocked(:,:,i) = buffer(x(:,i), block_size, 0.3*fs, 'nodelay');
end
lufs_blocked = 1/(block_size)*sum(x_blocked.^2, 1);
lufs_blocked = sum(lufs_blocked, 3);
# Apply absolute threshold
GAMMA_A = -70;
lufs_blocked = -0.691 + 10*log10(lufs_blocked);
valid_blocks = length(lufs_blocked);
valid_blocks = valid_blocks - length(lufs_blocked(lufs_blocked < GAMMA_A));
lufs_blocked(lufs_blocked < GAMMA_A) = -100;
lufs_blocked = 10.^((lufs_blocked+0.691)/10);
# Apply relative threshold
GAMMA_R = -0.691 + 10*log10(sum(lufs_blocked)/valid_blocks) - 10;
lufs_blocked = -0.691 + 10*log10(lufs_blocked);
valid_blocks = length(lufs_blocked);
valid_blocks = valid_blocks - length(lufs_blocked(lufs_blocked < GAMMA_R));
lufs_blocked(lufs_blocked < GAMMA_R) = -100;
lufs_blocked = 10.^((lufs_blocked+0.691)/10);
hold off
gated_lufs = -0.691 + 10*log10(sum(lufs_blocked)/valid_blocks);
end
if TEST_LUFS_HELPER
printf("Running calc_LUFS() selftest.\n");
printf("Compare the following results with a trusted LUFS calculator.\n");
fs = 44100;
k = 1:1:60*fs;
x = 0.3*sin(2*pi*1000/fs*k) + 0.2*sin(2*pi*1200/fs*k);
x = (x .* [1:1:30*fs, 30*fs:-1:1]./60./fs).';
audiowrite(cstrcat(pwd(), "/LUFS-selftest1.wav"), x, fs);
printf("LUFS-selftest1.wav should be %f LUFS\n", calc_LUFS(x, fs));
randn("seed", 1);
x = [0.2*randn(2, 10*fs) zeros(2, 10*fs) 0.1*randn(2, 10*fs)].';
x(:,1) = x(:,1) * 0.4 + 0.2;
audiowrite(cstrcat(pwd(), "/LUFS-selftest2.wav"), x, fs);
printf("LUFS-selftest2.wav should be %f LUFS\n", calc_LUFS(x, fs));
fs = 8000;
randn("seed", 2);
x = [0.2*randn(2, 10*fs) zeros(2, 10*fs) 0.1*randn(2, 10*fs)].';
x(:,1) = x(:,1) * 0.6 - 0.1;
# MMM: I'm not sure how trustworthy free loudness meters are
# in case of non-standard sample rates.
audiowrite(cstrcat(pwd(), "/LUFS-selftest3.wav"), x, fs);
printf("LUFS-selftest3.wav should be %f LUFS\n", calc_LUFS(x, fs));
end
# TODO: add tests here

174
tests/octave/run_test.m Executable file
View File

@ -0,0 +1,174 @@
#!/usr/bin/octave -qf
## Audacity Octave unit test runner
#
# Max Maisel
#
if !(nargin == 1 || nargin == 2)
printf("Usage: ./testbench.m <test-file.m> [-v]\n");
exit(2);
end
arg_list = argv();
if exist(arg_list{1}, "file") != 2
printf("Specified test file does not exist!\n");
exit(2);
end
global VERBOSE;
VERBOSE=0;
if nargin == 2
if strcmp(arg_list{2}, "-v") == 1
VERBOSE=1;
else
printf("Unknown argument %s. Abort!", arg_list{2});
exit(2);
end
end
## Initialization and helper functions
UID=num2str(getuid());
PIPE_TO_PATH=strcat("/tmp/audacity_script_pipe.to.", UID);
PIPE_FROM_PATH=strcat("/tmp/audacity_script_pipe.from.", UID);
TMP_FILENAME=strcat(pwd(), "/tmp.wav");
printf("Open scripting pipes, this may freeze if Audacity does not run...\n");
global PIPE_TO;
global PIPE_FROM;
global PRINT_COMMANDS;
PRINT_COMMANDS=false;
PIPE_TO=fopen(PIPE_TO_PATH, "w");
PIPE_FROM=fopen(PIPE_FROM_PATH, "r");
## aud-do helper function
function aud_do(command)
global PIPE_TO;
global PIPE_FROM;
global PRINT_COMMANDS;
if PRINT_COMMANDS
puts(command);
end
fwrite(PIPE_TO, command);
fflush(PIPE_TO);
do
string = fgets(PIPE_FROM);
if PRINT_COMMANDS
puts(string);
end
fflush(stdout);
until strncmp(string, "BatchCommand finished:", length("BatchCommand finished:"));
end
## Float equal comparison helper
function [ret] = float_eq(x, y, eps=0.001)
ret = abs(x - y) < eps;
end
## Test report helper
global TESTS_FAILED;
global TESTS_RUN;
global TESTS_SKIPPED;
global CURRENT_TEST;
TESTS_FAILED = 0;
TESTS_RUN = 0;
TESTS_SKIPPED = 0;
CURRENT_TEST="";
function plot_failure(x, y)
global VERBOSE;
if VERBOSE == 0
return;
end
figure(1)
plot(x, 'r')
hold on
plot(y, 'b')
plot(log10(abs(x-y)), 'g')
hold off
legend("Audacity", "Octave", "log-delta", "location", "southeast")
input("Press enter to continue", "s")
end
function do_test_equ(x, y, msg, eps=0.001, skip = false)
cmp = all(all(float_eq(x, y, eps)));
if do_test(cmp, msg, skip) == 0
plot_failure(x, y);
end
end
function do_test_neq(x, y, msg, eps=0.001, skip = false)
cmp = all(all(!float_eq(x, y, eps)));
if do_test(cmp, msg, skip) == 0
plot_failure(x, y);
end
end
function do_test_gte(x, y, msg, skip = false)
cmp = all(all(x >= y));
if do_test(cmp, msg, skip) == 0
plot_failure(x, y);
end
end
function do_test_lte(x, y, msg, skip = false)
cmp = all(all(x <= y));
if do_test(cmp, msg, skip) == 0
plot_failure(x, y);
end
end
function result = do_test(result, msg, skip = false)
global TESTS_RUN;
global TESTS_FAILED;
global TESTS_SKIPPED;
global CURRENT_TEST;
TESTS_RUN = TESTS_RUN + 1;
suffix = "";
if !strcmp(msg, "")
suffix = cstrcat(" - ", msg);
end
if skip
TESTS_SKIPPED = TESTS_SKIPPED + 1;
printf(cstrcat("[Skip]: ", CURRENT_TEST, suffix, "\n"));
result = 1;
else
if result
printf(cstrcat("[Success]: ", CURRENT_TEST, suffix, "\n"));
return;
else
TESTS_FAILED = TESTS_FAILED + 1;
printf(cstrcat("[Failed]: ", CURRENT_TEST, suffix, "\n"));
return;
end
end
end
## Run tests
printf("Starting tests...\n");
source(arg_list{1});
## Cleanup and result reporting
unlink(TMP_FILENAME);
fclose(PIPE_FROM);
fclose(PIPE_TO);
printf("%d tests run, %d tests failed, %d tests skipped\n", TESTS_RUN, TESTS_FAILED, TESTS_SKIPPED);
if TESTS_FAILED != 0
printf("Some tests failed!\n");
if VERBOSE == 0
printf("Re-run with -v option for details.\n");
end
exit(1);
elseif TESTS_SKIPPED != 0
printf("Some tests were skipped!\n");
else
printf("All tests succeeded!\n");
end
exit(0)

View File

@ -364,6 +364,7 @@
<ClCompile Include="..\..\..\src\effects\Generator.cpp" />
<ClCompile Include="..\..\..\src\effects\Invert.cpp" />
<ClCompile Include="..\..\..\src\effects\LoadEffects.cpp" />
<ClCompile Include="..\..\..\src\effects\Loudness.cpp" />
<ClCompile Include="..\..\..\src\effects\Noise.cpp" />
<ClCompile Include="..\..\..\src\effects\NoiseRemoval.cpp" />
<ClCompile Include="..\..\..\src\effects\Normalize.cpp" />
@ -764,6 +765,7 @@
<ClInclude Include="..\..\..\src\effects\Generator.h" />
<ClInclude Include="..\..\..\src\effects\Invert.h" />
<ClInclude Include="..\..\..\src\effects\LoadEffects.h" />
<ClInclude Include="..\..\..\src\effects\Loudness.h" />
<ClInclude Include="..\..\..\src\effects\Noise.h" />
<ClInclude Include="..\..\..\src\effects\NoiseRemoval.h" />
<ClInclude Include="..\..\..\src\effects\Normalize.h" />
@ -1348,4 +1350,4 @@
<ImportGroup Label="ExtensionTargets">
<Import Project="..\..\ny.targets" />
</ImportGroup>
</Project>
</Project>

View File

@ -452,6 +452,9 @@
<ClCompile Include="..\..\..\src\effects\LoadEffects.cpp">
<Filter>src\effects</Filter>
</ClCompile>
<ClCompile Include="..\..\..\src\effects\Loudness.cpp">
<Filter>src\effects</Filter>
</ClCompile>
<ClCompile Include="..\..\..\src\effects\Noise.cpp">
<Filter>src\effects</Filter>
</ClCompile>
@ -1609,6 +1612,9 @@
<ClInclude Include="..\..\..\src\effects\LoadEffects.h">
<Filter>src\effects</Filter>
</ClInclude>
<ClInclude Include="..\..\..\src\effects\Loudness.h">
<Filter>src\effects</Filter>
</ClInclude>
<ClInclude Include="..\..\..\src\effects\Noise.h">
<Filter>src\effects</Filter>
</ClInclude>
@ -2683,4 +2689,4 @@
<Filter>Resources</Filter>
</Manifest>
</ItemGroup>
</Project>
</Project>