Uses 911K of libraries. Click here for Pure Java version (5267L/26K).
1 | !7 |
2 | |
3 | cmodule AudioInput > DynPrintLog { |
4 | switchable int sampleRate = 44100; |
5 | switchable int channels = 2; |
6 | switchable int bufSize = 40960; |
7 | switchable bool sendOutClonedData; // makes things easier for clients |
8 | switchable bool verbose; |
9 | transient recordToAudioListeners_AudioLoop loop; |
10 | transient SimpleLiveValue<Float> lvVolume = floatLiveValue(); // in percent |
11 | transient L<VF1<short[]>> audioListeners = synchroList(); |
12 | |
13 | visual centerAndSouthWithMargins(super.visualize(), |
14 | jCenteredLine(jLiveValueLabel(mapLiveValue(func(float volume) -> S { "Volume: " + iround(volume) + " %" }, S, lvVolume)))); |
15 | |
16 | start { |
17 | ownTimer(loop = recordToAudioListeners(audioListeners, bufSize, lvVolume, getAudioFormat())); |
18 | loop.verbose = verbose; |
19 | dm_watchFieldAndNow sendOutClonedData(() -> { loop.cloneDataOnce = sendOutClonedData; }); |
20 | loop.start(); |
21 | dm_registerAs audioInputModule(); |
22 | JComponent trayIcon = jMinWidth(16, jVerticalGreenBar(lvVolume, max := 100)); |
23 | componentPopupMenuItem(trayIcon, "Audio Input", r { dm_showModule(module()) }); |
24 | dm_setTrayIcon(trayIcon); |
25 | } |
26 | |
27 | // hold audio listeners during reload |
28 | |
29 | O _getReloadData() { ret audioListeners; } |
30 | void _setReloadData(L<VF1<short[]>> listeners) { addAll(audioListeners, listeners); } |
31 | |
32 | // API |
33 | |
34 | void addAudioListener(VF1<short[]> l) { audioListeners.add(l); } |
35 | void removeAudioListener(VF1<short[]> l) { audioListeners.remove(l); } |
36 | |
37 | AudioFormat getAudioFormat() { ret new AudioFormat(AudioFormat.Encoding.PCM_SIGNED, sampleRate, 16, channels, channels*2, sampleRate, false); } |
38 | |
39 | float getVolume() { ret lvVolume!; } |
40 | |
41 | // for debugging |
42 | O currentListener() { ret loop.currentListener; } |
43 | } |
Began life as a copy of #1016699
download show line numbers debug dex old transpilations
Travelled to 17 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, hpgrupgrauku, irmadwmeruwu, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, snaazhdonpnp, tslmcundralx, tvejysmllsmz, vouqrxazstgt, xrpafgyirdlv
No comments. add comment
Snippet ID: | #1017138 |
Snippet name: | Audio Input [Dyn Module] |
Eternal ID of this version: | #1017138/53 |
Text MD5: | 6e66c9579001afd3562dfab4eb559dfc |
Transpilation MD5: | b9e307ca49ddd67ca71145c68ccee410 |
Author: | stefan |
Category: | javax / audio |
Type: | JavaX source code (Dynamic Module) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2020-02-15 13:43:21 |
Source code size: | 1741 bytes / 43 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 629 / 135817 |
Version history: | 52 change(s) |
Referenced in: | [show references] |