mirror of
https://github.com/cookiengineer/audacity
synced 2025-06-16 08:09:32 +02:00
Bug 1275 - No preview in Spectral edit effects
Introduces a new type 'spectral' t Nyquist plug-ins
This commit is contained in:
parent
0d4b58ba1c
commit
6663f406d3
@ -1,13 +1,13 @@
|
|||||||
;nyquist plug-in
|
;nyquist plug-in
|
||||||
;version 4
|
;version 4
|
||||||
;type process
|
;type process spectral
|
||||||
;name "Spectral edit multi tool"
|
;name "Spectral edit multi tool"
|
||||||
;action "Filtering..."
|
;action "Filtering..."
|
||||||
;author "Paul Licameli"
|
;author "Paul Licameli"
|
||||||
;copyright "Released under terms of the GNU General Public License version 2"
|
;copyright "Released under terms of the GNU General Public License version 2"
|
||||||
|
|
||||||
;; SpectralEditMulti.ny by Paul Licameli, November 2014.
|
;; SpectralEditMulti.ny by Paul Licameli, November 2014.
|
||||||
;; Updated to version 4 by Steve Daulton November 2014.
|
;; Updated by Steve Daulton 2014 / 2015.
|
||||||
;; Released under terms of the GNU General Public License version 2:
|
;; Released under terms of the GNU General Public License version 2:
|
||||||
;; http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
;; http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
||||||
|
|
||||||
@ -22,6 +22,7 @@
|
|||||||
(let* ((f0 (get '*selection* 'low-hz))
|
(let* ((f0 (get '*selection* 'low-hz))
|
||||||
(f1 (get '*selection* 'high-hz))
|
(f1 (get '*selection* 'high-hz))
|
||||||
(fc (get '*selection* 'center-hz))
|
(fc (get '*selection* 'center-hz))
|
||||||
|
(bw (get '*selection* 'bandwidth))
|
||||||
(tn (truncate len))
|
(tn (truncate len))
|
||||||
(rate (snd-srate sig))
|
(rate (snd-srate sig))
|
||||||
(transition (truncate (* 0.01 rate))) ; 10 ms
|
(transition (truncate (* 0.01 rate))) ; 10 ms
|
||||||
@ -30,14 +31,27 @@
|
|||||||
(breakpoints (list t1 1.0 t2 1.0 tn))
|
(breakpoints (list t1 1.0 t2 1.0 tn))
|
||||||
(env (snd-pwl 0.0 rate breakpoints)))
|
(env (snd-pwl 0.0 rate breakpoints)))
|
||||||
(cond
|
(cond
|
||||||
((not (or f0 f1)) (throw 'error-message "Please select frequencies."))
|
((not (or f0 f1)) ; This should never happen for a 'spectral' effect.
|
||||||
((and f0 f1 (= f0 f1)) (throw 'error-message
|
(throw 'error-message "Please select frequencies."))
|
||||||
"Bandwidth is zero.\nPlease select a frequency range."))
|
((and f0 f1 (= f0 f1))
|
||||||
|
(throw 'error-message
|
||||||
|
(format nil "~aBandwidth is zero (the upper and lower~%~
|
||||||
|
frequencies are both ~a Hz).~%~
|
||||||
|
Please select a frequency range."
|
||||||
|
p-err f0)))
|
||||||
|
;; Biqud filter fails if centre frequency is very low and bandwidth very high.
|
||||||
|
;; 'Magic numbers' 10 Hz and 10 octaves are experimental.
|
||||||
|
((and f0 (< f0 10) (or (not bw)(> bw 10)))
|
||||||
|
(throw 'error-message
|
||||||
|
(format nil "~aNotch filter parameters cannot be applied.~%~
|
||||||
|
Try increasing the low frequency bound~%~
|
||||||
|
or reduce the filter 'Width'."
|
||||||
|
p-err)))
|
||||||
;; low pass frequency is above Nyquist so do nothing
|
;; low pass frequency is above Nyquist so do nothing
|
||||||
((and (not f1) (>= f0 (/ *sound-srate* 2.0)))
|
((and (not f1) (>= f0 (/ *sound-srate* 2.0)))
|
||||||
nil)
|
nil)
|
||||||
;; notch frequency is above Nyquist so do nothing
|
;; notch frequency is above Nyquist so do nothing
|
||||||
((and (and f0 f1) (>= fc (/ *sound-srate* 2.0)))
|
((and f0 f1 (>= fc (/ *sound-srate* 2.0)))
|
||||||
nil)
|
nil)
|
||||||
;; high-pass above Nyquist so fade to silence
|
;; high-pass above Nyquist so fade to silence
|
||||||
((and (not f0) (>= f1 (/ *sound-srate* 2.0)))
|
((and (not f0) (>= f1 (/ *sound-srate* 2.0)))
|
||||||
@ -46,4 +60,5 @@
|
|||||||
(prod (diff 1.0 env) sig))))))
|
(prod (diff 1.0 env) sig))))))
|
||||||
|
|
||||||
(catch 'error-message
|
(catch 'error-message
|
||||||
|
(setf p-err "Error.\n")
|
||||||
(multichan-expand #'result *track*))
|
(multichan-expand #'result *track*))
|
||||||
|
@ -1,41 +1,28 @@
|
|||||||
;nyquist plug-in
|
;nyquist plug-in
|
||||||
;version 4
|
;version 4
|
||||||
;type process
|
;type process spectral
|
||||||
;preview linear
|
;preview linear
|
||||||
;name "Spectral edit parametric EQ..."
|
;name "Spectral edit parametric EQ..."
|
||||||
;action "Filtering..."
|
;action "Filtering..."
|
||||||
;author "Paul Licameli"
|
;author "Paul Licameli"
|
||||||
;copyright "Released under terms of the GNU General Public License version 2"
|
;copyright "Released under terms of the GNU General Public License version 2"
|
||||||
|
|
||||||
|
|
||||||
;; SpectralEditParametricEQ.ny by Paul Licameli, November 2014.
|
;; SpectralEditParametricEQ.ny by Paul Licameli, November 2014.
|
||||||
;; Updated to version 4 by Steve Daulton November 2014.
|
;; Updated by Steve Daulton 2014 / 2015.
|
||||||
;; Released under terms of the GNU General Public License version 2:
|
;; Released under terms of the GNU General Public License version 2:
|
||||||
;; http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
;; http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
||||||
|
|
||||||
;control control-gain "Gain (dB)" real "" 0 -24 24
|
;control control-gain "Gain (dB)" real "" 0 -24 24
|
||||||
|
|
||||||
(setf control-gain (min 24 (max -24 control-gain))) ; excessive settings may crash
|
(defun wet (sig gain fc bw)
|
||||||
|
(eq-band sig fc gain (/ bw 2)))
|
||||||
(defmacro validate (hz)
|
|
||||||
"Ensure frequency is below Nyquist"
|
|
||||||
`(setf ,hz (max 0 (min (/ *sound-srate* 2.0) ,hz))))
|
|
||||||
|
|
||||||
(defun wet (sig gain f0 f1)
|
|
||||||
;; (re)calculate bw and fc to ensure we do not exceed Nyquist frequency
|
|
||||||
(validate f0)
|
|
||||||
(validate f1)
|
|
||||||
(let ((fc (sqrt (* f0 f1)))
|
|
||||||
(bw (/ (log (/ f1 f0))
|
|
||||||
(log 2.0))))
|
|
||||||
(when (= bw 0)
|
|
||||||
(throw 'error-message (format nil "~aBandwidth is zero.~%Select a frequency range." p-err)))
|
|
||||||
(eq-band sig fc gain (/ bw 2))))
|
|
||||||
|
|
||||||
(defun result (sig)
|
(defun result (sig)
|
||||||
(let*
|
(let*
|
||||||
((f0 (get '*selection* 'low-hz))
|
((f0 (get '*selection* 'low-hz))
|
||||||
(f1 (get '*selection* 'high-hz))
|
(f1 (get '*selection* 'high-hz))
|
||||||
|
(fc (get '*selection* 'center-hz))
|
||||||
|
(bw (get '*selection* 'bandwidth))
|
||||||
(tn (truncate len))
|
(tn (truncate len))
|
||||||
(rate (snd-srate sig))
|
(rate (snd-srate sig))
|
||||||
(transition (truncate (* 0.01 rate))) ; 10 ms
|
(transition (truncate (* 0.01 rate))) ; 10 ms
|
||||||
@ -44,18 +31,34 @@
|
|||||||
(breakpoints (list t1 1.0 t2 1.0 tn))
|
(breakpoints (list t1 1.0 t2 1.0 tn))
|
||||||
(env (snd-pwl 0.0 rate breakpoints)))
|
(env (snd-pwl 0.0 rate breakpoints)))
|
||||||
(cond
|
(cond
|
||||||
((not (or f0 f1))
|
((not (or f0 f1)) ; This should never happen for a 'spectral' effect.
|
||||||
(throw 'error-message (format nil "~aPlease select frequencies." p-err)))
|
(throw 'error-message (format nil "~aPlease select frequencies." p-err)))
|
||||||
((or (not f0) (= f0 0))
|
((not f0)
|
||||||
(throw 'error-message (format nil "~aLow frequency is undefined." p-err)))
|
(throw 'error-message (format nil "~aLow frequency is undefined." p-err)))
|
||||||
((not f1)
|
((not f1)
|
||||||
(throw 'error-message (format nil "~aHigh frequency is undefined." p-err)))
|
(throw 'error-message (format nil "~aHigh frequency is undefined." p-err)))
|
||||||
;; If seleted frequency band is above Nyquist, do nothing.
|
((and fc (= fc 0))
|
||||||
((< f0 (/ *sound-srate* 2.0))
|
(throw 'error-message (format nil "~aCenter frequency must be above 0 Hz." p-err)))
|
||||||
(sum (prod env (wet sig control-gain f0 f1)) (prod (diff 1.0 env) sig))))))
|
((and f1 (> f1 (/ *sound-srate* 2)))
|
||||||
|
(throw 'error-message
|
||||||
|
(format nil "~aFrequency selection is too high for track sample rate.
|
||||||
|
For the current track, the high frequency setting cannot~%~
|
||||||
|
be greater than ~a Hz"
|
||||||
|
p-err (/ *sound-srate* 2))))
|
||||||
|
((and bw (= bw 0))
|
||||||
|
(throw 'error-message
|
||||||
|
(format nil "~aBandwidth is zero (the upper and lower~%~
|
||||||
|
frequencies are both ~a Hz).~%~
|
||||||
|
Please select a frequency range."
|
||||||
|
p-err f0)))
|
||||||
|
;; If centre frequency band is above Nyquist, do nothing.
|
||||||
|
((and fc (>= fc (/ *sound-srate* 2.0)))
|
||||||
|
nil)
|
||||||
|
(t (sum (prod env (wet sig control-gain fc bw))
|
||||||
|
(prod (diff 1.0 env) sig))))))
|
||||||
|
|
||||||
(catch 'error-message
|
(catch 'error-message
|
||||||
(setf p-err "")
|
(setf p-err "Error.\n")
|
||||||
(if (= control-gain 0) ; Allow dry preview
|
(if (= control-gain 0)
|
||||||
"Gain is zero. Nothing to do."
|
nil ; Do nothing
|
||||||
(multichan-expand #'result *track*)))
|
(multichan-expand #'result *track*)))
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
;nyquist plug-in
|
;nyquist plug-in
|
||||||
;version 4
|
;version 4
|
||||||
;type process
|
;type process spectral
|
||||||
;preview linear
|
;preview linear
|
||||||
;name "Spectral edit shelves..."
|
;name "Spectral edit shelves..."
|
||||||
;action "Filtering..."
|
;action "Filtering..."
|
||||||
@ -9,35 +9,31 @@
|
|||||||
|
|
||||||
|
|
||||||
;; SpectralEditShelves.ny by Paul Licameli, November 2014.
|
;; SpectralEditShelves.ny by Paul Licameli, November 2014.
|
||||||
;; Updated to version 4 by Steve Daulton November 2014.
|
;; Updated by Steve Daulton 2014 / 2015.
|
||||||
;; Released under terms of the GNU General Public License version 2:
|
;; Released under terms of the GNU General Public License version 2:
|
||||||
;; http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
;; http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
||||||
|
|
||||||
;control control-gain "Gain (dB)" real "" 0 -24 24
|
;control control-gain "Gain (dB)" real "" 0 -24 24
|
||||||
|
|
||||||
(setf control-gain (min 24 (max -24 control-gain))) ; excessive settings may crash
|
|
||||||
|
|
||||||
(defmacro validate (hz)
|
(defmacro validate (hz)
|
||||||
"Ensure frequency is below Nyquist"
|
"If frequency is above Nyquist, don't use it"
|
||||||
`(setf ,hz (max 0 (min (/ *sound-srate* 2.0) ,hz))))
|
`(if (or (>= ,hz (/ *sound-srate* 2.0))
|
||||||
|
(<= ,hz 0))
|
||||||
|
(setf ,hz nil)))
|
||||||
|
|
||||||
(defun mid-shelf (sig lf hf gain)
|
(defun mid-shelf (sig lf hf gain)
|
||||||
"Combines high shelf and low shelf filters"
|
"Combines high shelf and low shelf filters"
|
||||||
(let* ((invg (- gain)))
|
(let ((invg (- gain)))
|
||||||
(scale (db-to-linear gain)
|
(scale (db-to-linear gain)
|
||||||
(eq-highshelf (eq-lowshelf sig lf invg)
|
(eq-highshelf (eq-lowshelf sig lf invg)
|
||||||
hf invg))))
|
hf invg))))
|
||||||
|
|
||||||
(defun wet (sig gain f0 f1)
|
(defun wet (sig gain f0 f1)
|
||||||
|
"Apply appropriate filter"
|
||||||
(cond
|
(cond
|
||||||
((not f0) (eq-lowshelf sig (validate f1) gain))
|
((not f0) (eq-lowshelf sig f1 gain))
|
||||||
((not f1) (eq-highshelf sig (validate f0) gain))
|
((not f1) (eq-highshelf sig f0 gain))
|
||||||
(t
|
(t (mid-shelf sig f0 f1 gain))))
|
||||||
(validate f0)
|
|
||||||
(validate f1)
|
|
||||||
(when (= f0 f1)
|
|
||||||
(throw 'error-message "Please select a frequency range."))
|
|
||||||
(mid-shelf sig f0 f1 gain))))
|
|
||||||
|
|
||||||
(defun result (sig)
|
(defun result (sig)
|
||||||
(let*
|
(let*
|
||||||
@ -51,24 +47,26 @@
|
|||||||
(breakpoints (list t1 1.0 t2 1.0 tn))
|
(breakpoints (list t1 1.0 t2 1.0 tn))
|
||||||
(env (snd-pwl 0.0 rate breakpoints)))
|
(env (snd-pwl 0.0 rate breakpoints)))
|
||||||
(cond
|
(cond
|
||||||
((not (or f0 f1))
|
((not (or f0 f1)) ; This should never happen for a 'spectral' effect.
|
||||||
(throw 'error-message (format nil "~aPlease select frequencies." p-err)))
|
(throw 'error-message (format nil "~aPlease select frequencies." p-err)))
|
||||||
; shelf is above Nyquist frequency so do nothing
|
((and f0 (>= f0 (/ *sound-srate* 2.0)))
|
||||||
((and f0 (>= f0 (/ *sound-srate* 2.0))) nil)
|
; Shelf is above Nyquist frequency so do nothing.
|
||||||
(T (sum (prod env (wet sig control-gain f0 f1))
|
nil)
|
||||||
(prod (diff 1.0 env) sig))))))
|
((and f0 f1 (= f0 f1))
|
||||||
|
(throw 'error-message
|
||||||
;; Frequency selection must be between 0 Hz and Nyquist.
|
(format nil "~aBandwidth is zero (the upper and lower~%~
|
||||||
(if (and (get '*selection* 'low-hz)
|
frequencies are both ~a Hz).~%~
|
||||||
(<= (get '*selection* 'low-hz) 0))
|
Please select a frequency range."
|
||||||
(remprop '*selection* 'low-hz))
|
p-err f0)))
|
||||||
(if (and (get '*selection* 'high-hz)
|
(T (if f0 (validate f0))
|
||||||
(>= (get '*selection* 'high-hz)(/ *sound-srate* 2)))
|
(if f1 (validate f1))
|
||||||
(remprop '*selection* 'high-hz))
|
(if (not (or f0 f1)) ; 'validate' may return nil
|
||||||
|
nil ; Do nothing
|
||||||
|
(sum (prod env (wet sig control-gain f0 f1))
|
||||||
|
(prod (diff 1.0 env) sig)))))))
|
||||||
|
|
||||||
(catch 'error-message
|
(catch 'error-message
|
||||||
(setf p-err "")
|
(setf p-err "Error.\n")
|
||||||
(if (= control-gain 0) ; Allow dry preview
|
(if (= control-gain 0)
|
||||||
"Gain is zero. Nothing to do."
|
nil ; Do nothing
|
||||||
(multichan-expand #'result *track*)))
|
(multichan-expand #'result *track*)))
|
||||||
|
|
||||||
|
@ -377,6 +377,34 @@ bool NyquistEffect::SetAutomationParameters(EffectAutomationParameters & parms)
|
|||||||
|
|
||||||
bool NyquistEffect::Init()
|
bool NyquistEffect::Init()
|
||||||
{
|
{
|
||||||
|
// As of Audacity 2.1.2 rc1, 'spectral' effects are allowed only if
|
||||||
|
// the selected track(s) are in a spectrogram view, and there is at
|
||||||
|
// least one frequency bound and Spectral Selection is enabled for the
|
||||||
|
// selected track(s) - (but don't apply to Nyquist Prompt).
|
||||||
|
|
||||||
|
if (!mIsPrompt && mIsSpectral) {
|
||||||
|
AudacityProject *project = GetActiveProject();
|
||||||
|
bool bAllowSpectralEditing = true;
|
||||||
|
|
||||||
|
SelectedTrackListOfKindIterator sel(Track::Wave, project->GetTracks());
|
||||||
|
for (WaveTrack *t = (WaveTrack *) sel.First(); t; t = (WaveTrack *) sel.Next()) {
|
||||||
|
if (t->GetDisplay() != WaveTrack::Spectrum ||
|
||||||
|
!(t->GetSpectrogramSettings().SpectralSelectionEnabled())) {
|
||||||
|
bAllowSpectralEditing = false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!bAllowSpectralEditing || ((mF0 < 0.0) && (mF1 < 0.0))) {
|
||||||
|
wxMessageBox(_("To use 'Spectral effects', enable 'Spectral Selection'\n"
|
||||||
|
"in the track Spectrogram settings and select the\n"
|
||||||
|
"frequency range for the effect to act on."),
|
||||||
|
_("Error"), wxOK | wxICON_EXCLAMATION | wxCENTRE);
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (!mIsPrompt && !mExternal)
|
if (!mIsPrompt && !mExternal)
|
||||||
{
|
{
|
||||||
//TODO: If we want to auto-add parameters from spectral selection,
|
//TODO: If we want to auto-add parameters from spectral selection,
|
||||||
@ -621,12 +649,6 @@ bool NyquistEffect::Process()
|
|||||||
wxString centerHz = wxT("nil");
|
wxString centerHz = wxT("nil");
|
||||||
wxString bandwidth = wxT("nil");
|
wxString bandwidth = wxT("nil");
|
||||||
|
|
||||||
const WaveTrack::WaveTrackDisplay display = mCurTrack[0]->GetDisplay();
|
|
||||||
const bool bAllowSpectralEditing =
|
|
||||||
(display == WaveTrack::Spectrum) &&
|
|
||||||
mCurTrack[0]->GetSpectrogramSettings().SpectralSelectionEnabled();
|
|
||||||
|
|
||||||
if (bAllowSpectralEditing) {
|
|
||||||
#if defined(EXPERIMENTAL_SPECTRAL_EDITING)
|
#if defined(EXPERIMENTAL_SPECTRAL_EDITING)
|
||||||
if (mF0 >= 0.0) {
|
if (mF0 >= 0.0) {
|
||||||
lowHz.Printf(wxT("(float %s)"), Internat::ToString(mF0).c_str());
|
lowHz.Printf(wxT("(float %s)"), Internat::ToString(mF0).c_str());
|
||||||
@ -641,7 +663,11 @@ bool NyquistEffect::Process()
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ((mF0 > 0.0) && (mF1 >= mF0)) {
|
if ((mF0 > 0.0) && (mF1 >= mF0)) {
|
||||||
bandwidth.Printf(wxT("(float %s)"), Internat::ToString(log(mF1 / mF0) / log(2.0)).c_str());
|
// with very small values, bandwidth calculation may be inf.
|
||||||
|
// (Observed on Linux)
|
||||||
|
double bw = log(mF1 / mF0) / log(2.0);
|
||||||
|
if (!isinf(bw)) {
|
||||||
|
bandwidth.Printf(wxT("(float %s)"), Internat::ToString(bw).c_str());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1346,6 +1372,9 @@ void NyquistEffect::Parse(wxString line)
|
|||||||
else if (tokens[1] == wxT("analyze")) {
|
else if (tokens[1] == wxT("analyze")) {
|
||||||
mType = EffectTypeAnalyze;
|
mType = EffectTypeAnalyze;
|
||||||
}
|
}
|
||||||
|
if (len >= 3 && tokens[2] == wxT("spectral")) {;
|
||||||
|
mIsSpectral = true;
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1582,6 +1611,7 @@ bool NyquistEffect::ParseProgram(wxInputStream & stream)
|
|||||||
mIsSal = false;
|
mIsSal = false;
|
||||||
mControls.Clear();
|
mControls.Clear();
|
||||||
mCategories.Clear();
|
mCategories.Clear();
|
||||||
|
mIsSpectral = false;
|
||||||
|
|
||||||
mFoundType = false;
|
mFoundType = false;
|
||||||
while (!stream.Eof() && stream.IsOk())
|
while (!stream.Eof() && stream.IsOk())
|
||||||
|
@ -180,6 +180,7 @@ private:
|
|||||||
bool mCompiler;
|
bool mCompiler;
|
||||||
bool mIsSal;
|
bool mIsSal;
|
||||||
bool mExternal;
|
bool mExternal;
|
||||||
|
bool mIsSpectral;
|
||||||
/** True if the code to execute is obtained interactively from the user via
|
/** True if the code to execute is obtained interactively from the user via
|
||||||
* the "Nyquist Prompt", false for all other effects (lisp code read from
|
* the "Nyquist Prompt", false for all other effects (lisp code read from
|
||||||
* files)
|
* files)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user