Skip to content

Commit

Permalink
Added spectral stuff to audioCompare
Browse files Browse the repository at this point in the history
  • Loading branch information
George Tzanetakis committed Nov 14, 2017
1 parent c013a4d commit 054375a
Show file tree
Hide file tree
Showing 2 changed files with 118 additions and 73 deletions.
179 changes: 112 additions & 67 deletions src/apps/audioCompare/audioCompare.cpp
Expand Up @@ -48,46 +48,17 @@ printUsage(string progName)
void
printHelp(string progName)
{
MRSDIAG("bextract.cpp - printHelp");
cerr << "bextract, MARSYAS, Copyright George Tzanetakis " << endl;
MRSDIAG("audioCompare.cpp - printHelp");
cerr << "audioCompare, MARSYAS, Copyright George Tzanetakis " << endl;
cerr << "--------------------------------------------" << endl;
cerr << "Prints information about the sound files provided as arguments " << endl;
cerr << endl;
cerr << "Usage : " << progName << " file1 file2 file3" << endl;
cerr << "Usage : " << progName << " file1 file2" << endl;
cerr << endl;
cerr << "where file1, ..., fileN are sound files in a Marsyas supported format" << endl;
cerr << "Help Options:" << endl;
cerr << "-u --usage : display short usage info" << endl;
cerr << "-v --verbose : verbose output" << endl;
cerr << "-c --collection : use files in this collection [only for MIREX 2007]" << endl;
cerr << "-n --normalize : enable normalization" << endl;
cerr << "-as --accSize : accumulator size" << endl;
cerr << "-cl --classifier : classifier name" << endl;
cerr << "-pr --predict : predict class for files in collection" << endl;
cerr << "-fe --featExtract : only extract features" << endl;
cerr << "-tc --test : test collection" << endl;
cerr << "-st --stereo : use stereo feature extraction" << endl;
cerr << "-ds --downsample : downsampling factor" << endl;
cerr << "-h --help : display this information " << endl;
cerr << "-e --extractor : extractor " << endl;
cerr << "-p --plugin : output plugin name " << endl;
cerr << "-pm --pluginmute : mute the plugin " << endl;
cerr << "-csv --csvoutput : output confidence values in sfplugin in csv format"<<endl;
cerr << "-pb --playback : playback during feature extraction " << endl;
cerr << "-s --start : playback start offset in seconds " << endl;
cerr << "-sh --shuffle : shuffle collection file before processing" << endl;

cerr << "-l --length : playback length in seconds " << endl;
cerr << "-m --memory : memory size " << endl;
cerr << "-w --wekafile : weka .arff filename " << endl;
cerr << "-od --outputdir : output directory for output of files" << endl;
cerr << "-ws --windowsize : analysis window size in samples " << endl;
cerr << "-hp --hopsize : analysis hop size in samples " << endl;
cerr << "-t --timeline : flag 2nd input collection as timelines for the 1st collection"<<endl;
cerr << "-os --onlyStable : only output 'stable' frames (silently omit the rest)"<<endl;
cerr << "-rg --regression : print regression labels instead of classification labels"<<endl;
cerr << endl;

exit(0);
}

Expand All @@ -99,9 +70,9 @@ initOptions()
cmd_options.addBoolOption("help", "h", false);
cmd_options.addBoolOption("usage", "u", false);
cmd_options.addBoolOption("verbose", "v", false);
cmd_options.addRealOption("delta_sample_threshold", "dt", 0.1);
cmd_options.addRealOption("delta_rms_dB", "db", 0.0);
cmd_options.addRealOption("delta_spectrum", "ds", 0.0);
cmd_options.addRealOption("delta_sample_threshold", "dt", 0.4);
cmd_options.addRealOption("delta_rms_dB", "db", -15.0);
cmd_options.addRealOption("delta_spectrum_dB", "ds", -50.0);
}

void
Expand All @@ -112,11 +83,9 @@ loadOptions()
verboseopt = cmd_options.getBoolOption("verbose");
dt_ = cmd_options.getRealOption("delta_sample_threshold");
db_ = cmd_options.getRealOption("delta_rms_dB");
ds_ = cmd_options.getRealOption("delta_spectrum");
ds_ = cmd_options.getRealOption("delta_spectrum_dB");
}



int
isClose(string infile1, string infile2)
{
Expand Down Expand Up @@ -147,50 +116,114 @@ isClose(string infile1, string infile2)
mrs_natural num_of_different_windows = 0;
while ( pnet->getctrl("mrs_bool/hasData")->to<mrs_bool>() )
{
diff_detected = false;
pnet->tick();
l++;
const realvec& processedData =
pnet->getctrl("Sum/sum/mrs_realvec/processedData")->to<mrs_realvec>();
for (i=0; i<samples; ++i)
{
if (verboseopt)
{
if (abs(processedData(i)) > ds_)
{
cout<<processedData(i)<< " > " << ds_;
cout<< " : " << l << "*512 + " << i << endl;
{
if (verboseopt)
{
if (fabs(processedData(i)) > dt_)
{
cout<<processedData(i)<< " > " << dt_;
cout<< " : " << l << "*512 + " << i << endl;
}
}

if ( abs(processedData(i)) > ds_)

if ( fabs(processedData(i)) > dt_)
{
diff_detected = true;
}

}

const realvec& rmsData =
pnet->getctrl("mrs_realvec/processedData")->to<mrs_realvec>();

mrs_real rms_db = 20 * log10(rmsData(0,0) + 0.00001);
if (rms_db > db_)
{
diff_detected = true;
if (verboseopt)
cout << "RMS in dB(" << l << "*512) = " << rms_db << ":" << db_ << endl;
}

if (diff_detected)
num_of_different_windows++;
}
delete pnet;
cout << "Number of different windows = " << num_of_different_windows << endl;
if (num_of_different_windows > 0)
return 1;
else
return 0;
}

}

const realvec& rmsData =
pnet->getctrl("mrs_realvec/processedData")->to<mrs_realvec>();

mrs_real rms_db = 20 * log10(rmsData(0,0) + 0.00001);
if (verboseopt)
{
// cout << "RMS in dB = " << rms_db << endl;
}
if (rms_db > db_)
{
diff_detected = true;
cout << "RMS in dB(" << l << "*512) = " << rms_db << "-" << db_ << endl;
}
int
isCloseSpectral(string infile1, string infile2)
{
MarSystemManager mng;
MarSystem* pnet = mng.create("Series", "pnet");

if (diff_detected)
num_of_different_windows++;
MarSystem* invnet = mng.create("Series", "invnet");
invnet->addMarSystem(mng.create("SoundFileSource", "src2"));
invnet->updControl("SoundFileSource/src2/mrs_string/filename", infile2);
invnet->addMarSystem(mng.create("Spectrum", "spk2"));
invnet->addMarSystem(mng.create("PowerSpectrum", "pspk2"));
invnet->addMarSystem(mng.create("Transposer", "trsp2"));
invnet->addMarSystem(mng.create("Negative", "neg"));

MarSystem* net = mng.create("Series", "net");
net->addMarSystem(mng.create("SoundFileSource", "src1"));
net-> updControl("SoundFileSource/src1/mrs_string/filename", infile1);
net->addMarSystem(mng.create("Spectrum", "spk1"));
net->addMarSystem(mng.create("PowerSpectrum", "pspk1"));
net->addMarSystem(mng.create("Transposer", "trsp1"));

MarSystem* fanout = mng.create("Fanout", "fanout");
fanout->addMarSystem(net);
fanout->addMarSystem(invnet);

pnet->addMarSystem(fanout);
pnet->addMarSystem(mng.create("Sum", "sum"));
pnet->addMarSystem(mng.create("Rms", "rms"));
pnet->linkControl("mrs_bool/hasData",
"Fanout/fanout/Series/net/SoundFileSource/src1/mrs_bool/hasData");

mrs_natural i;
mrs_natural samples =
pnet->getctrl("mrs_natural/inSamples")->to<mrs_natural>();
mrs_natural l = 0;
mrs_bool diff_detected = false;
mrs_natural num_of_different_windows = 0;
while ( pnet->getctrl("mrs_bool/hasData")->to<mrs_bool>() )
{
diff_detected = false;
pnet->tick();
l++;
const realvec& processedData =
pnet->getctrl("Sum/sum/mrs_realvec/processedData")->to<mrs_realvec>();
const realvec& rmsData =
pnet->getctrl("mrs_realvec/processedData")->to<mrs_realvec>();

mrs_real rms_db = 20 * log10(rmsData(0,0) + 0.00001);
if (rms_db > ds_)
{
diff_detected = true;
if (verboseopt)
cout << "Spectral RMS in dB(" << l << "*512) = " << rms_db << ":" << db_ << endl;
}

if (diff_detected)
num_of_different_windows++;
}
delete pnet;
cout << "Number of different windows = " << num_of_different_windows << endl;
if (diff_detected)
cout << "Number of spectral different windows = " << num_of_different_windows << endl;
if (num_of_different_windows > 0)
return 1;
else
return 0;
Expand All @@ -204,20 +237,32 @@ main(int argc, const char **argv)
string progName = argv[0];
if (argc == 1)
printUsage(progName);

// handling of command-line options
initOptions();
cmd_options.readOptions(argc, argv);
loadOptions();

vector<string> soundfiles = cmd_options.getRemaining();
string file1 = soundfiles[0];
string file2 = soundfiles[1];


cout << "Delta sample threshold (dt) = " << dt_ << endl;
cout << "Delta time-domain window RMS in dB (db) = " << db_ << endl;
cout << "Delta spectral RMS in dB (ds) = " << ds_ << endl;

mrs_bool is_close = isClose(file1, file2);
if (!is_close)
mrs_bool is_closeSpectral = isCloseSpectral(file1, file2);
cout << is_close << endl;
cout << is_closeSpectral << endl;
if (!is_close && !is_closeSpectral)
cout << "Files are identical" << endl;
else
cout << "Files are different" << endl;



return is_close;
}

12 changes: 6 additions & 6 deletions src/marsyas_python/amplitude_histogram.py
Expand Up @@ -89,7 +89,7 @@ def process_collection(wav_fnames):
inSamples.setValue_natural(winSize)
fname = plot_net.getControl("SoundFileSource/src/mrs_string/filename")
normalize = plot_net.getControl("Fanout/fan/Series/hist/Histogram/histo/mrs_bool/normalize")
deltaStd = plot_net.getControl("Fanout/fan/Series/hist/Histogram/histo/mrs_real/deltaStd")
# deltaStd = plot_net.getControl("Fanout/fan/Series/hist/Histogram/histo/mrs_real/deltaStd")
memSize1 = plot_net.getControl("Fanout/fan/Series/hist/TextureStats/tstats1/mrs_natural/memSize")
memSize2 = plot_net.getControl("Fanout/fan/Series/dlt/TextureStats/tstats2/mrs_natural/memSize")
# normalize1 = plot_net.getControl("Fanout/fan/Series/dlt/Histogram/histo1/mrs_bool/normalize")
Expand All @@ -105,7 +105,7 @@ def process_collection(wav_fnames):
num_glitch = 0
numFiles = 0
seconds2process = 15.0
samples2process = seconds2process * 8000
samples2process = seconds2process * 48000
iterations2process = int(samples2process * 1.0 / winSize)


Expand All @@ -122,7 +122,7 @@ def process_collection(wav_fnames):

plot_net.tick()
# print("DELTA", deltaStd.to_real())
deltas.append(deltaStd.to_real())
# deltas.append(deltaStd.to_real())
nTicks = nTicks + 1
normalize.setValue_bool(True)
# normalize1.setValue_bool(True)
Expand All @@ -145,13 +145,13 @@ def process_collection(wav_fnames):

avg_ratio = avg_ratio / numFiles
print("----------------------")
print("AVERAGE AGGREGATE = ", np.mean(aggregate_deltas), np.std(aggregate_deltas))
# print("AVERAGE AGGREGATE = ", np.mean(aggregate_deltas), np.std(aggregate_deltas))
print(("AVERAGE RATIO=" , avg_ratio))
print(("NUM GLITCH = ", num_glitch, numFiles))
print(("GLITCH PERCENTAGE=", int(100 * (num_glitch * 1.0/len(wav_fnames)))))

print("AVG DELTA = ", np.mean(deltas))
print("STD DELTA = ", np.std(deltas))
# print("AVG DELTA = ", np.mean(deltas))
# print("STD DELTA = ", np.std(deltas))
# show(gridplot(*figs, ncols=2))
return (ratios, wav_fnames)

Expand Down

0 comments on commit 054375a

Please sign in to comment.