Skip to content

Commit 607d725

Browse files
fefantoMichelangelo Nottoli
andauthored
add option to select sample rates and block sizes (#43)
* add option to select sample rates and block sizes * option bs and sr now are stl vectors Co-authored-by: Michelangelo Nottoli <[email protected]>
1 parent 84ab51e commit 607d725

File tree

7 files changed

+124
-20
lines changed

7 files changed

+124
-20
lines changed

Source/CommandLine.cpp

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,32 @@ File getOutputDir (const ArgumentList& args)
173173
return getOptionValue (args, "--output-dir", {}, "Missing output-dir path argument!").toString();
174174
}
175175

176+
std::vector<double> getSampleRates (const ArgumentList& args)
177+
{
178+
StringArray input = StringArray::fromTokens(getOptionValue (args, "--sample-rates", String ("44100,48000,96000") , "Missing sample rate list argument!").toString(),
179+
",",
180+
"\""
181+
);
182+
std::vector<double> output;
183+
for(String sr: input) {
184+
output.push_back(sr.getDoubleValue());
185+
}
186+
return output;
187+
}
188+
189+
std::vector<int> getBlockSizes (const ArgumentList& args)
190+
{
191+
StringArray input = StringArray::fromTokens(getOptionValue (args, "--block-sizes", String ("64,128,256,512,1024") , "Missing block size list argument!").toString(),
192+
",",
193+
"\""
194+
);
195+
std::vector<int> output;
196+
for(String sr: input) {
197+
output.push_back(sr.getIntValue());
198+
}
199+
return output;
200+
}
201+
176202
StringArray getDisabledTest (const ArgumentList& args)
177203
{
178204
const File disabledTestsFile (getOptionValue (args, "--disabled-tests", {}, "Missing disabled-tests path argument!").toString());
@@ -221,7 +247,9 @@ static Option possibleOptions[] =
221247
{ "--data-file", true },
222248
{ "--output-dir", true },
223249
{ "--repeat", true },
224-
{ "--randomise", false }
250+
{ "--randomise", false },
251+
{ "--sample-rates", true },
252+
{ "--block-sizes", true },
225253
};
226254

227255
StringArray mergeEnvironmentVariables (StringArray args, std::function<String (const String& name, const String& defaultValue)> environmentVariableProvider = [] (const String& name, const String& defaultValue) { return SystemStats::getEnvironmentVariable (name, defaultValue); })
@@ -292,6 +320,10 @@ static String getHelpMessage()
292320
<< " If specified, sets a directory to store the log files. This can be useful for continuous integration." << newLine
293321
<< " --disabled-tests [pathToFile]" << newLine
294322
<< " If specified, sets a path to a file that should have the names of disabled tests on each row." << newLine
323+
<< " --sample-rates [list of comma separated sample rates]" << newLine
324+
<< " If specified, sets the list of sample rates at which tests will be executed (default=44100,48000,96000)" << newLine
325+
<< " --block-sizes [list of comma separated block sizes]" << newLine
326+
<< " If specified, sets the list of block sizes at which tests will be executed (default=64,128,256,512,1024)" << newLine
295327
<< " --version" << newLine
296328
<< " Print pluginval version." << newLine
297329
<< newLine
@@ -352,6 +384,8 @@ static void validate (CommandLineValidator& validator, const ArgumentList& args)
352384
options.outputDir = getOutputDir (args);
353385
options.withGUI = ! args.containsOption ("--skip-gui-tests");
354386
options.disabledTests = getDisabledTest (args);
387+
options.sampleRates = getSampleRates (args);
388+
options.blockSizes = getBlockSizes (args);
355389

356390
validator.validate (fileOrIDs,
357391
options,

Source/MainComponent.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,16 @@ File getOutputDir()
9292
return getAppPreferences().getValue ("outputDir", String());
9393
}
9494

95+
std::vector<double> getSampleRates() // from UI no setting of sampleRates yet
96+
{
97+
return {44100., 48000., 96000. };
98+
}
99+
100+
std::vector<int> getBlockSizes() // from UI no setting of block sizes yet
101+
{
102+
return { 64, 128, 256, 512, 1024 };
103+
}
104+
95105

96106
PluginTests::Options getTestOptions()
97107
{
@@ -103,6 +113,8 @@ PluginTests::Options getTestOptions()
103113
options.numRepeats = getNumRepeats();
104114
options.randomiseTestOrder = getRandomiseTests();
105115
options.outputDir = getOutputDir();
116+
options.sampleRates = getSampleRates();
117+
options.blockSizes = getBlockSizes();
106118

107119
return options;
108120
}

Source/PluginTests.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ struct PluginTests : public UnitTest
3636
File dataFile; /**< File which tests can use to run user provided data. */
3737
File outputDir; /**< Directory in which to write the log files for each test run. */
3838
StringArray disabledTests; /**< List of disabled tests. */
39+
std::vector<double> sampleRates; /**< List of sample rates. */
40+
std::vector<int> blockSizes; /**< List of block sizes. */
3941
};
4042

4143
/** Creates a set of tests for a fileOrIdentifier. */

Source/Validator.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,8 @@ namespace IDs
249249
DECLARE_ID(outputDir)
250250
DECLARE_ID(withGUI)
251251
DECLARE_ID(disabledTests)
252+
DECLARE_ID(sampleRates)
253+
DECLARE_ID(blockSizes)
252254

253255
DECLARE_ID(MESSAGE)
254256
DECLARE_ID(type)
@@ -479,7 +481,9 @@ class ValidatorChildProcess : public ChildProcessSlave,
479481
options.outputDir = File (v[IDs::outputDir].toString());
480482
options.withGUI = v.getProperty (IDs::withGUI, true);
481483
options.disabledTests = StringArray::fromLines (v.getProperty (IDs::disabledTests).toString());
482-
484+
options.sampleRates = juce::VariantConverter<std::vector<double>>::fromVar( v.getProperty (IDs::sampleRates).toString() );
485+
options.blockSizes = juce::VariantConverter<std::vector<int>>::fromVar( v.getProperty (IDs::blockSizes).toString() );
486+
483487
for (auto c : v)
484488
{
485489
String fileOrID;
@@ -670,6 +674,8 @@ class ValidatorParentProcess : public ChildProcessMaster
670674
v.setProperty (IDs::outputDir, options.outputDir.getFullPathName(), nullptr);
671675
v.setProperty (IDs::withGUI, options.withGUI, nullptr);
672676
v.setProperty (IDs::disabledTests, options.disabledTests.joinIntoString ("\n"), nullptr);
677+
v.setProperty (IDs::sampleRates, juce::VariantConverter<std::vector<double>>::toVar(options.sampleRates), nullptr);
678+
v.setProperty (IDs::blockSizes, juce::VariantConverter<std::vector<int>>::toVar(options.blockSizes), nullptr);
673679

674680
return v;
675681
}

Source/Validator.h

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,34 @@
2525
#define LOG_PIPE_CHILD_COMMUNICATION 0
2626
#endif
2727

28+
namespace juce
29+
{
30+
template<typename T>
31+
struct VariantConverter<std::vector<T>>
32+
{
33+
static std::vector<T> fromVar (const var& v)
34+
{
35+
jassert (v.isArray());
36+
Array<var>* vr = v.getArray();
37+
std::vector<T> vc;
38+
for (var vItem : *vr)
39+
{
40+
vc.push_back (static_cast<T> (vItem));
41+
}
42+
return vc;
43+
}
44+
static var toVar (const std::vector<T>& vc)
45+
{
46+
juce::var vr;
47+
for (T t : vc)
48+
{
49+
vr.append (t);
50+
}
51+
return vr;
52+
}
53+
};
54+
}// namespace juce
55+
2856
class ValidatorParentProcess;
2957

3058
//==============================================================================

Source/tests/BasicTests.cpp

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,12 @@ struct EditorWhilstProcessingTest : public PluginTest
134134
if (instance.hasEditor())
135135
{
136136
instance.releaseResources();
137-
instance.prepareToPlay (44100.0, 512);
137+
138+
const std::vector<double>& sampleRates = ut.getOptions().sampleRates;
139+
const std::vector<int>& blockSizes = ut.getOptions().blockSizes;
140+
141+
jassert (sampleRates.size()>0 && blockSizes.size()>0);
142+
instance.prepareToPlay (sampleRates[0], blockSizes[0]);
138143

139144
const int numChannelsRequired = jmax (instance.getTotalNumInputChannels(), instance.getTotalNumOutputChannels());
140145
AudioBuffer<float> ab (numChannelsRequired, instance.getBlockSize());
@@ -183,8 +188,13 @@ struct AudioProcessingTest : public PluginTest
183188
bool callReleaseResourcesBeforeSampleRateChange)
184189
{
185190
const bool isPluginInstrument = instance.getPluginDescription().isInstrument;
186-
const double sampleRates[] = { 44100.0, 48000.0, 96000.0 };
187-
const int blockSizes[] = { 64, 128, 256, 512, 1024 };
191+
192+
const std::vector<double>& sampleRates = ut.getOptions().sampleRates;
193+
const std::vector<int>& blockSizes = ut.getOptions().blockSizes;
194+
195+
jassert (sampleRates.size()>0 && blockSizes.size()>0);
196+
instance.prepareToPlay (sampleRates[0], blockSizes[0]);
197+
188198
const int numBlocks = 10;
189199
auto r = ut.getRandom();
190200

@@ -193,8 +203,8 @@ struct AudioProcessingTest : public PluginTest
193203
for (auto bs : blockSizes)
194204
{
195205
ut.logMessage (String ("Testing with sample rate [SR] and block size [BS]")
196-
.replace ("SR", String (sr, 0), false)
197-
.replace ("BS", String (bs), false));
206+
.replace ("SR", String(sr,0) , false)
207+
.replace ("BS", String(bs), false));
198208

199209
if (callReleaseResourcesBeforeSampleRateChange)
200210
instance.releaseResources();
@@ -344,8 +354,13 @@ struct AutomationTest : public PluginTest
344354
{
345355
const bool subnormalsAreErrors = ut.getOptions().strictnessLevel > 5;
346356
const bool isPluginInstrument = instance.getPluginDescription().isInstrument;
347-
const double sampleRates[] = { 44100.0, 48000.0, 96000.0 };
348-
const int blockSizes[] = { 64, 128, 256, 512, 1024 };
357+
358+
const std::vector<double>& sampleRates = ut.getOptions().sampleRates;
359+
const std::vector<int>& blockSizes = ut.getOptions().blockSizes;
360+
361+
jassert (sampleRates.size()>0 && blockSizes.size()>0);
362+
instance.prepareToPlay (sampleRates[0], blockSizes[0]);
363+
349364
auto r = ut.getRandom();
350365

351366
for (auto sr : sampleRates)
@@ -354,8 +369,8 @@ struct AutomationTest : public PluginTest
354369
{
355370
const int subBlockSize = 32;
356371
ut.logMessage (String ("Testing with sample rate [SR] and block size [BS] and sub-block size [SB]")
357-
.replace ("SR", String (sr, 0), false)
358-
.replace ("BS", String (bs), false)
372+
.replace ("SR", String(sr,0), false)
373+
.replace ("BS", String(bs), false)
359374
.replace ("SB", String (subBlockSize), false));
360375

361376
instance.releaseResources();

Source/tests/ExtremeTests.cpp

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,13 @@ struct AllocationsInRealTimeThreadTest : public PluginTest
2626
void runTest (PluginTests& ut, AudioPluginInstance& instance) override
2727
{
2828
const bool isPluginInstrument = instance.getPluginDescription().isInstrument;
29-
const double sampleRates[] = { 44100.0, 48000.0, 96000.0 };
30-
const int blockSizes[] = { 64, 128, 256, 512, 1024 };
29+
30+
const std::vector<double>& sampleRates = ut.getOptions().sampleRates;
31+
const std::vector<int>& blockSizes = ut.getOptions().blockSizes;
32+
33+
jassert (sampleRates.size()>0 && blockSizes.size()>0);
34+
instance.prepareToPlay (sampleRates[0], blockSizes[0]);
35+
3136
const int numBlocks = 10;
3237
auto r = ut.getRandom();
3338

@@ -36,8 +41,8 @@ struct AllocationsInRealTimeThreadTest : public PluginTest
3641
for (auto bs : blockSizes)
3742
{
3843
ut.logMessage (String ("Testing with sample rate [SR] and block size [BS]")
39-
.replace ("SR", String (sr, 0), false)
40-
.replace ("BS", String (bs), false));
44+
.replace ("SR", String(sr,0), false)
45+
.replace ("BS", String(bs), false));
4146
instance.releaseResources();
4247
instance.prepareToPlay (sr, bs);
4348

@@ -103,19 +108,21 @@ struct LargerThanPreparedBlockSizeTest : public PluginTest
103108
ut.logMessage ("INFO: Skipping test for plugin format");
104109
return;
105110
}
111+
112+
const std::vector<double>& sampleRates = ut.getOptions().sampleRates;
113+
const std::vector<int>& blockSizes = ut.getOptions().blockSizes;
106114

107-
const double sampleRates[] = { 44100.0, 48000.0, 96000.0 };
108-
const int blockSizes[] = { 64, 128, 256, 512, 1024 };
109-
115+
jassert (sampleRates.size()>0 && blockSizes.size()>0);
116+
110117
for (auto sr : sampleRates)
111118
{
112119
for (auto preparedBlockSize : blockSizes)
113120
{
114121
const auto processingBlockSize = preparedBlockSize * 2;
115122
ut.logMessage (String ("Preparing with sample rate [SR] and block size [BS], processing with block size [BSP]")
116-
.replace ("SR", String (sr, 0), false)
123+
.replace ("SR", String(sr,0), false)
117124
.replace ("BSP", String (processingBlockSize), false)
118-
.replace ("BS", String (preparedBlockSize), false));
125+
.replace ("BS", String(preparedBlockSize), false));
119126
instance.releaseResources();
120127
instance.prepareToPlay (sr, preparedBlockSize);
121128

0 commit comments

Comments
 (0)