Libraryless. Click here for Pure Java version (14920L/103K).
1 | !7 |
2 | |
3 | import static x30_pkg.x30_util.VF1; |
4 | |
5 | module ReceiveAudio > DynPrintLog { |
6 | bool enabled; |
7 | float gain = 0.5f; |
8 | transient L<short[]> chunks = synchroLinkedList(); |
9 | transient int minChunksToPlay = 2; |
10 | |
11 | start { |
12 | vmBus_onMessage('gotFromPrivateChat, voidfunc(S sender, S msg) { |
13 | if (enabled && startsWith(msg, "audio:")) |
14 | chunks.add(shortArrayFromBytes_littleEndian(base64decode(substring(msg, 6)))); |
15 | }); |
16 | |
17 | dm_addSoundSource(new VF1<double[]>() { |
18 | int sampleIndex; |
19 | short[] samples; |
20 | |
21 | public void get(double[] pair) { |
22 | pair[0] = pair[1] = 0; |
23 | if (!enabled) ret; |
24 | if (samples == null) { |
25 | if (l(chunks) < minChunksToPlay) { minChunksToPlay = 2; ret; } |
26 | minChunksToPlay = 1; |
27 | samples = syncPopFirst(chunks); |
28 | sampleIndex = 0; |
29 | } |
30 | pair[0] = samples[sampleIndex]*gain; |
31 | pair[1] = samples[sampleIndex+1]*gain; |
32 | sampleIndex += 2; |
33 | if (sampleIndex >= l(samples)) samples = null; |
34 | } |
35 | }); |
36 | } |
37 | |
38 | visualize { |
39 | ret centerAndSouth(super.visualize(), |
40 | centerAndEast( |
41 | withLabel("Volume (0-200%):", liveSliderZeroToOne(gain/2, voidfunc(float f) { setField(gain := f*2) })), |
42 | main.onChange(dm_fieldCheckBox('enabled), r { if (!enabled) chunks.clear() }))); |
43 | } |
44 | } |
Began life as a copy of #1019650
download show line numbers debug dex old transpilations
Travelled to 13 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, irmadwmeruwu, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tvejysmllsmz, vouqrxazstgt
No comments. add comment
Snippet ID: | #1019651 |
Snippet name: | Play Audio From Other Machine |
Eternal ID of this version: | #1019651/11 |
Text MD5: | 2140927bd717487561618f815b4c1a51 |
Transpilation MD5: | 8dec76bc021a4f349eb90a9b5b2c7fb3 |
Author: | stefan |
Category: | javax |
Type: | JavaX source code (Dynamic Module) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2018-11-16 16:25:45 |
Source code size: | 1359 bytes / 44 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 313 / 432 |
Version history: | 10 change(s) |
Referenced in: | [show references] |