!7 cmodule AudioInput > DynPrintLog { switchable int sampleRate = 44100; switchable int channels = 2; switchable int bufSize = 40960; switchable bool sendOutClonedData; // makes things easier for clients switchable bool verbose; transient recordToAudioListeners_AudioLoop loop; transient SimpleLiveValue lvVolume = floatLiveValue(); // in percent transient L> audioListeners = synchroList(); visual centerAndSouthWithMargins(super.visualize(), jCenteredLine(jLiveValueLabel(mapLiveValue(func(float volume) -> S { "Volume: " + iround(volume) + " %" }, S, lvVolume)))); start { ownTimer(loop = recordToAudioListeners(audioListeners, bufSize, lvVolume, getAudioFormat())); loop.verbose = verbose; dm_watchFieldAndNow sendOutClonedData(() -> { loop.cloneDataOnce = sendOutClonedData; }); loop.start(); dm_registerAs audioInputModule(); JComponent trayIcon = jMinWidth(16, jVerticalGreenBar(lvVolume, max := 100)); componentPopupMenuItem(trayIcon, "Audio Input", r { dm_showModule(module()) }); dm_setTrayIcon(trayIcon); } // hold audio listeners during reload O _getReloadData() { ret audioListeners; } void _setReloadData(L> listeners) { addAll(audioListeners, listeners); } // API void addAudioListener(VF1 l) { audioListeners.add(l); } void removeAudioListener(VF1 l) { audioListeners.remove(l); } AudioFormat getAudioFormat() { ret new AudioFormat(AudioFormat.Encoding.PCM_SIGNED, sampleRate, 16, channels, channels*2, sampleRate, false); } float getVolume() { ret lvVolume!; } // for debugging O currentListener() { ret loop.currentListener; } }