1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-06-16 08:09:32 +02:00

Limit selection length for Nyquist plug-ins

This can improve progress count for Nyquist effects
that do not process all of selection (bug 558) and provides some
protection against 2^31 overflow issues (bug 439).
This commit is contained in:
Steve Daulton 2015-08-13 09:04:01 +01:00
parent 2cb32c763f
commit 7ee8032f3c
3 changed files with 25 additions and 1 deletions

View File

@ -3,6 +3,7 @@
;type analyze ;type analyze
;name "Sample Data Export..." ;name "Sample Data Export..."
;action "Analyzing..." ;action "Analyzing..."
;maxlen 1000001
;categories "http://lv2plug.in/ns/lv2core#AnalyserPlugin" ;categories "http://lv2plug.in/ns/lv2core#AnalyserPlugin"
;author "Steve Daulton" ;author "Steve Daulton"
;copyright "Released under terms of the GNU General Public License version 2" ;copyright "Released under terms of the GNU General Public License version 2"
@ -90,7 +91,7 @@
(if (< number 1) (if (< number 1)
(add-error "No samples selected.")) (add-error "No samples selected."))
(if (> number 1000000) (if (> number 1000000)
(add-error "Too many samples selected.\nSet limit to less than 1 million")) (add-error "Cannot export more than 1 million samples."))
(setq number (truncate number))) (setq number (truncate number)))

View File

@ -79,6 +79,9 @@ enum
ID_Choice = 13000 ID_Choice = 13000
}; };
// Protect Nyquist from selections greater than 2^31 samples (bug 439)
#define NYQ_MAX_LEN ((sampleCount) 2147483647)
#define UNINITIALIZED_CONTROL ((double)99999999.99) #define UNINITIALIZED_CONTROL ((double)99999999.99)
static const wxChar *KEY_Version = XO("Version"); static const wxChar *KEY_Version = XO("Version");
@ -130,6 +133,8 @@ NyquistEffect::NyquistEffect(wxString fName)
mBreak = false; mBreak = false;
mCont = false; mCont = false;
mMaxLen = NYQ_MAX_LEN;
// Interactive Nyquist // Interactive Nyquist
if (fName == NYQUIST_PROMPT_ID) if (fName == NYQUIST_PROMPT_ID)
{ {
@ -379,6 +384,7 @@ bool NyquistEffect::Init()
{ {
SaveUserPreset(GetCurrentSettingsGroup()); SaveUserPreset(GetCurrentSettingsGroup());
mMaxLen = NYQ_MAX_LEN;
ParseFile(); ParseFile();
mFileModified = mFileName.GetModificationTime(); mFileModified = mFileName.GetModificationTime();
@ -577,6 +583,14 @@ bool NyquistEffect::Process()
sampleCount end = mCurTrack[0]->TimeToLongSamples(mT1); sampleCount end = mCurTrack[0]->TimeToLongSamples(mT1);
mCurLen = (sampleCount)(end - mCurStart[0]); mCurLen = (sampleCount)(end - mCurStart[0]);
if (mCurLen > NYQ_MAX_LEN) {
wxMessageBox(_("Selection too long for Nyquist code.\nMaximum allowed selection is 2147483647 samples\n(about 13.5 hours at 44100 Hz sample rate)."),
_("Nyquist Error"), wxOK | wxCENTRE);
return false;
}
if (mCurLen > mMaxLen) mCurLen = mMaxLen;
mProgressIn = 0.0; mProgressIn = 0.0;
mProgressOut = 0.0; mProgressOut = 0.0;
@ -1401,6 +1415,14 @@ void NyquistEffect::Parse(wxString line)
return; return;
} }
// Maximum number of samples to be processed. This can help the
// progress bar if effect does not process all of selection.
if (len >= 2 && tokens[0] == wxT("maxlen")) {
long long v; // Note that Nyquist may overflow at > 2^31 samples (bug 439)
tokens[1].ToLongLong(&v);
mMaxLen = (sampleCount) v;
}
#if defined(EXPERIMENTAL_NYQUIST_SPLIT_CONTROL) #if defined(EXPERIMENTAL_NYQUIST_SPLIT_CONTROL)
if (len >= 2 && tokens[0] == wxT("mergeclips")) { if (len >= 2 && tokens[0] == wxT("mergeclips")) {
long v; long v;

View File

@ -205,6 +205,7 @@ private:
WaveTrack *mCurTrack[2]; WaveTrack *mCurTrack[2];
sampleCount mCurStart[2]; sampleCount mCurStart[2];
sampleCount mCurLen; sampleCount mCurLen;
sampleCount mMaxLen;
int mTrackIndex; int mTrackIndex;
bool mFirstInGroup; bool mFirstInGroup;
double mOutputTime; double mOutputTime;