Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

37
LINES

< > BotCompany Repo | #1020114 // Play Audio Loop

JavaX source code (Dynamic Module) [tags: use-pretranspiled] - run with: Stefan's OS

Uses 11463K of libraries. Click here for Pure Java version (14906L/104K).

1  
!7
2  
3  
import static x30_pkg.x30_util.VF1;
4  
5  
sclass PlayAudioLoop > DynModule {
6  
  bool enabled = true;
7  
  float gain = 0.5f;
8  
  File file;
9  
  
10  
  transient short[] loop;
11  
  transient StereoSamplesIterator source;
12  
  transient GainSoundSource gainSource;
13  
  
14  
  start {
15  
    dm_addSoundSource(gainSource = GainSoundSource(0));
16  
    onChangeAndNow(r {
17  
      set(gainSource, gain := enabled ? (double) gain : 0.0);
18  
    });
19  
    loadFile(file);
20  
  }
21  
22  
  visualize {
23  
    ret jHandleFileDrop(voidfunc(final File f) enter { thread { loadFile(f); } },
24  
      centerAndSouth(withLabel("File:", dm_fieldLabel('file)),
25  
        centerAndEast(
26  
          withLabel("Volume (0-200%):", liveSliderZeroToOne(gain/2, voidfunc(float f) { setField(gain := f*2) })),
27  
          dm_fieldCheckBox('enabled))));
28  
  }
29  
30  
  void loadFile(File f) {
31  
    loop = null;
32  
    setField(file := f);
33  
    print("Loading audio file: " + f);
34  
    pcall { loop = decodeAudioFileToStereoSamples(f); }
35  
    gainSource.replaceSource(source = stereoSamplesIterator_longCounter(loop));
36  
  }
37  
}

download  show line numbers  debug dex  old transpilations   

Travelled to 8 computer(s): bhatertpkbcr, cfunsshuasjs, gwrvuhgaqvyk, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #1020114
Snippet name: Play Audio Loop
Eternal ID of this version: #1020114/14
Text MD5: 1dbd5bdd2699f68f4f9daf75667e37e4
Transpilation MD5: 32f4e38449dc170265b3ae81fe06dc62
Author: stefan
Category:
Type: JavaX source code (Dynamic Module)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2018-12-08 21:45:59
Source code size: 1058 bytes / 37 lines
Pitched / IR pitched: No / No
Views / Downloads: 326 / 682
Version history: 13 change(s)
Referenced in: [show references]