!7 // Note: This is dependent on input buffer size which is not optimal. // Tested with buffer size 232 ms (using CD quality) cmodule VAD > DynPrintLogAndEnabled { double windowSize = 1; // milliseconds transient short[] buffer; double threshold = 10.0; // the magic value! start { printLogUpdateInterval = 100; // technically we are treating stereo input as mono samples // but it might not matter dm_addAudioListener(voidfunc(short[] data) enter { if (!enabled) ret; buffer = cloneArray(data); dm_q(r { if (q.size() > 2) ret with print("overload"); short[] buf = buffer; Float sampleRate = dm_audioInputSampleRate(); if (sampleRate == null) ret; int windowLength = msToSamples_int(windowSize, sampleRate); //printWithMilliseconds("Window length (" + sampleRate + "): " + windowLength); new L l; for (IntRange r : intRangeChunks(data, windowLength)) l.add(normalizedAutocorrelationOfAudioSamples(data, r)); double result = doubleAverage(l); double confidence = result/threshold*50; print("VAD " + (confidence >= 50 ? "XXX" : " ") + " value: " + iround(confidence) + " %"); }); }); } }