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

48
LINES

< > BotCompany Repo | #1018253 // Audio Input + Output [dev., Dyn Module, TODO: sync-start]

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

Libraryless. Compilation Failed (14949L/104K).

!7

import static x30_pkg.x30_util.VF1;

sclass AudioInputOutput > DynPrintLog {
  int bufSize = 40960;
  transient recordToAudioListeners_AudioLoop loop;
  transient SimpleLiveValue<Float> lvVolume = floatLiveValue(); // in percent
  L<VF1<short[]>> audioListeners = synchroList();
  float gain = 1;
  transient playAudioFromSampleMakingFunction_AudioLoop outputLoop;
  transient L<VF1<double[]>> sources = synchroList();
  
  visualize {
    ret centerAndSouthWithMargins(super.visualize(),
      vstackWithSpacing(
        withLabel("Volume (0-200%):", liveSliderZeroToOne(gain/2, voidfunc(float f) { setField(gain := f*2) })),
        jCenteredLine(jLiveValueLabel(mapLiveValue(func(float volume) -> S { "Input Volume: " + iround(volume) + " %" }, S, lvVolume)))));
  }

  start {
    ownTimer(loop = recordToAudioListeners(audioListeners, bufSize, lvVolume));
    ownTimer(outputLoop = playAudioFromSampleMakingFunction_dontStart(bufSize, voidfunc(double[] pair) {
      audio_makeSampleFromSources(sources, pair, gain)
    }));
    Mixer mixer = AudioSystem.getMixer(null);
    print("Mixer: " + mixer);
    Line[] lines = { loop.line, outputLoop.out };
    bool fullSync = true;
    bool canSync = mixer.isSynchronizationSupported(lines, true);
    print("Can sync: " + canSync);
    if (!canSync) {
      fullSync = false;
      canSync = mixer.isSynchronizationSupported(lines, false);
      print("Can sync: " + canSync);
    }
    if (canSync)
      mixer.synchronize(lines, fullSync);
    loop.start();
    outputLoop.start();
  }
  
  void addAudioListener(VF1<short[]> l) { audioListeners.add(l); }
  void removeAudioListener(VF1<short[]> l) { audioListeners.remove(l); }
  
  void addSource(VF1<double[]> source) { sources.add(source); }
  void removeSource(VF1<double[]> source) { sources.remove(source); }
}

Author comment

Began life as a copy of #1017138

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: #1018253
Snippet name: Audio Input + Output [dev., Dyn Module, TODO: sync-start]
Eternal ID of this version: #1018253/6
Text MD5: 41332e8185af37b9dbad24ce532dbe02
Transpilation MD5: 84418319a853442ec45f6608fab63f58
Author: stefan
Category: javax / audio
Type: JavaX source code (Dynamic Module)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2018-09-12 13:49:08
Source code size: 1871 bytes / 48 lines
Pitched / IR pitched: No / No
Views / Downloads: 402 / 575
Version history: 5 change(s)
Referenced in: [show references]