Uses 911K of libraries. Click here for Pure Java version (5564L/28K).
1 | !7 |
2 | |
3 | import static x30_pkg.x30_util.VF1; |
4 | |
5 | cmodule AudioOutput > DynPrintLog { |
6 | switchable int bufSize = 40960; |
7 | switchable float gain = 1; |
8 | switchable bool registerService; |
9 | transient playAudioFromSampleMakingFunction_AudioLoop loop; |
10 | transient L<VF1<double[]>> sources = notifyingList(r setNumSources); |
11 | transient SimpleLiveValue<Int> numSources = new(Int, 0); |
12 | |
13 | visualize { |
14 | ret centerAndSouth(super.visualize(), |
15 | withLeftAndRightMargin(vstackWithSpacing( |
16 | withLabel("Volume (0-200%):", liveSliderZeroToOne(gain/2, voidfunc(float f) { setField(gain := f*2) })), |
17 | jrightalignedline(withLabel("Sound sources:", jLiveValueLabel(numSources))) |
18 | ))); |
19 | } |
20 | |
21 | start { |
22 | final VF1<VF1<double[]>> vfRemoveSource = voidfunc(VF1<double[]> source) { |
23 | removeSource(source) |
24 | }; |
25 | ownTimer(loop = playAudioFromSampleMakingFunction(bufSize, voidfunc(double[] pair) { |
26 | audio_makeSampleFromSources(sources, pair, gain, vfRemoveSource) |
27 | })); |
28 | |
29 | dm_registerAs audioOutputModule(); |
30 | |
31 | if (registerService) |
32 | dm_registerService('playWAVAndWait, func(S method, O[] args) -> bool { |
33 | temp enter(); |
34 | callMC(f dm_playWAV, args); |
35 | true; |
36 | }); |
37 | } |
38 | |
39 | void setNumSources { numSources.set(l(sources)); } |
40 | |
41 | // hold audio sources during reload |
42 | |
43 | O _getReloadData() { ret sources; } |
44 | void _setReloadData(L<VF1<double[]>> sources) { addAll(this.sources, sources); } |
45 | |
46 | // API |
47 | |
48 | void addSource(VF1<double[]> source) { |
49 | sources.add(source); |
50 | print("Audio source added."); |
51 | } |
52 | |
53 | void removeSource(VF1<double[]> source) { |
54 | sources.remove(source); |
55 | print("Audio source removed."); |
56 | } |
57 | |
58 | AudioFormat getAudioFormat() { ret loop.quality; } |
59 | |
60 | long samplesPlayed() { ret loop.samplesPlayed; } |
61 | } |
download show line numbers debug dex old transpilations
Travelled to 15 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, irmadwmeruwu, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt, xrpafgyirdlv
No comments. add comment
Snippet ID: | #1016699 |
Snippet name: | Audio Output [Dyn Module] |
Eternal ID of this version: | #1016699/40 |
Text MD5: | ee68a7b54cbe3afa95a4002bf2cb1eb6 |
Transpilation MD5: | 230c666ab1c7fb49bce35fb3bbb4454f |
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-06 23:38:00 |
Source code size: | 1842 bytes / 61 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 623 / 29757 |
Version history: | 39 change(s) |
Referenced in: | [show references] |