!7 import static x30_pkg.x30_util.VF1; sclass BlipOnNoise > DynPrintLog { transient volatile L recording; transient JButton btn; visualize { btn = jbutton("Record [hold button down]"); onMouseDown(btn, r { print("Recording!"); recording = synchroList(); }); onMouseUp(btn, r { if (recording == null) ret with print("Huh?"); L l = recording; recording = null; print("Recording done. Got " + l(l) + " chunks"); }); ret northAndCenterWithMargins(btn, super.visualize()); } void start { ownTimer(q = startQ()); VF1 audioListener = voidfunc(short[] data) { temp enter(); L l = recording; if (l == null) ret; l.add(cloneShortArray(data)); // Quickly calculate the volume final float vol = shortSamplesToPercentVolume(data); // Do everything else in our own thread q.add(r { //print("vol: " + vol); if (now() > delayUntil && vol >= threshold && lastVolume < threshold) { delayUntil = now()+forcedDelay; blip(); printWithTime("Got noise (" + iround(vol) + "%)"); } lastVolume = vol; }); }; // Link to audio input module dm_addAudioListener(audioListener); } }