mirror of
https://github.com/cookiengineer/audacity
synced 2025-10-25 07:43:54 +02:00
Paul Licameli's Spectral Editing Patch.
This relies on three new nyquist scripts to actually do the editing. The peak-snapping code in FrequencyWindow has been extracted into a new class, SpectrumAnalyst, to provide peak-snapping in spectrogram too.
This commit is contained in:
@@ -6,26 +6,52 @@
|
||||
|
||||
Dominic Mazzoni
|
||||
|
||||
*******************************************************************//**
|
||||
|
||||
\class SelectedRegion
|
||||
\brief Defines a selected portion of a project
|
||||
|
||||
This includes starting and ending times, and other optional information
|
||||
such as a frequency range, but not the set of selected tracks.
|
||||
|
||||
Maintains the invariants that ending time is not less than starting time
|
||||
and that starting and ending frequencies, when both defined, are also
|
||||
correctly ordered.
|
||||
|
||||
*//****************************************************************//**
|
||||
|
||||
**********************************************************************/
|
||||
|
||||
#ifndef __AUDACITY_SELECTEDREGION__
|
||||
#define __AUDACITY_SELECTEDREGION__
|
||||
|
||||
#include "Audacity.h"
|
||||
#include "Experimental.h"
|
||||
|
||||
class AUDACITY_DLL_API SelectedRegion {
|
||||
|
||||
// Maintains the invariant: t1() >= t0()
|
||||
|
||||
public:
|
||||
|
||||
static const int UndefinedFrequency = -1;
|
||||
|
||||
SelectedRegion()
|
||||
: mT0(0.0)
|
||||
, mT1(0.0)
|
||||
#ifdef EXPERIMENTAL_SPECTRAL_EDITING
|
||||
, mF0(UndefinedFrequency)
|
||||
, mF1(UndefinedFrequency)
|
||||
#endif
|
||||
{}
|
||||
|
||||
SelectedRegion(double t0, double t1)
|
||||
: mT0(t0)
|
||||
, mT1(t1)
|
||||
#ifdef EXPERIMENTAL_SPECTRAL_EDITING
|
||||
, mF0(UndefinedFrequency)
|
||||
, mF1(UndefinedFrequency)
|
||||
#endif
|
||||
{ ensureOrdering(); }
|
||||
|
||||
|
||||
@@ -37,6 +63,10 @@ public:
|
||||
SelectedRegion(const SelectedRegion &x)
|
||||
: mT0(x.mT0)
|
||||
, mT1(x.mT1)
|
||||
#ifdef EXPERIMENTAL_SPECTRAL_EDITING
|
||||
, mF0(x.mF0)
|
||||
, mF1(x.mF1)
|
||||
#endif
|
||||
{}
|
||||
|
||||
SelectedRegion& operator=(const SelectedRegion& x)
|
||||
@@ -44,15 +74,34 @@ public:
|
||||
if (this != &x) {
|
||||
mT0 = x.mT0;
|
||||
mT1 = x.mT1;
|
||||
#ifdef EXPERIMENTAL_SPECTRAL_EDITING
|
||||
mF0 = x.mF0;
|
||||
mF1 = x.mF1;
|
||||
#endif
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
// Accessors
|
||||
|
||||
double t0() const { return mT0; }
|
||||
double t1() const { return mT1; }
|
||||
double duration() const { return mT1 - mT0; }
|
||||
bool isPoint() const { return mT1 <= mT0; }
|
||||
|
||||
#ifdef EXPERIMENTAL_SPECTRAL_EDITING
|
||||
double f0() const { return mF0; }
|
||||
double f1() const { return mF1; }
|
||||
double fc() const {
|
||||
if (mF0 == UndefinedFrequency ||
|
||||
mF1 == UndefinedFrequency)
|
||||
return UndefinedFrequency;
|
||||
else
|
||||
return sqrt(mF0 * mF1);
|
||||
};
|
||||
#endif
|
||||
|
||||
// Mutators
|
||||
// PRL: to do: more integrity checks
|
||||
|
||||
// Returns true iff the bounds got swapped
|
||||
@@ -105,6 +154,28 @@ public:
|
||||
|
||||
void collapseToT1() { mT0 = mT1; }
|
||||
|
||||
#ifdef EXPERIMENTAL_SPECTRAL_EDITING
|
||||
// Returns true iff the bounds got swapped
|
||||
bool setF0(double f) {
|
||||
mF0 = f;
|
||||
return ensureFrequencyOrdering();
|
||||
}
|
||||
|
||||
// Returns true iff the bounds got swapped
|
||||
bool setF1(double f) {
|
||||
mF1 = f;
|
||||
return ensureFrequencyOrdering();
|
||||
}
|
||||
|
||||
// Returns true iff the bounds got swapped
|
||||
bool setFrequencies(double f0, double f1)
|
||||
{
|
||||
mF0 = f0;
|
||||
mF1 = f1;
|
||||
return ensureFrequencyOrdering();
|
||||
}
|
||||
#endif
|
||||
|
||||
private:
|
||||
bool ensureOrdering()
|
||||
{
|
||||
@@ -118,8 +189,33 @@ private:
|
||||
return false;
|
||||
}
|
||||
|
||||
#ifdef EXPERIMENTAL_SPECTRAL_EDITING
|
||||
bool ensureFrequencyOrdering()
|
||||
{
|
||||
if (mF1 < 0)
|
||||
mF1 = UndefinedFrequency;
|
||||
if (mF0 < 0)
|
||||
mF0 = UndefinedFrequency;
|
||||
|
||||
if (mF0 != UndefinedFrequency &&
|
||||
mF1 != UndefinedFrequency &&
|
||||
mF1 < mF0) {
|
||||
const double t = mF1;
|
||||
mF1 = mF0;
|
||||
mF0 = t;
|
||||
return true;
|
||||
}
|
||||
else
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
|
||||
double mT0;
|
||||
double mT1;
|
||||
#ifdef EXPERIMENTAL_SPECTRAL_EDITING
|
||||
double mF0; // low frequency
|
||||
double mF1; // high frequency
|
||||
#endif
|
||||
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user