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

44
LINES

< > BotCompany Repo | #1019651 // Play Audio From Other Machine

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

Libraryless. Click here for Pure Java version (14920L/103K).

!7

import static x30_pkg.x30_util.VF1;

module ReceiveAudio > DynPrintLog {
  bool enabled;
  float gain = 0.5f;
  transient L<short[]> chunks = synchroLinkedList();
  transient int minChunksToPlay = 2;

  start {
    vmBus_onMessage('gotFromPrivateChat, voidfunc(S sender, S msg) {
      if (enabled && startsWith(msg, "audio:"))
        chunks.add(shortArrayFromBytes_littleEndian(base64decode(substring(msg, 6))));
    });

    dm_addSoundSource(new VF1<double[]>() {
      int sampleIndex;
      short[] samples;
      
      public void get(double[] pair) {
        pair[0] = pair[1] = 0;
        if (!enabled) ret;
        if (samples == null) {
          if (l(chunks) < minChunksToPlay) { minChunksToPlay = 2; ret; }
          minChunksToPlay = 1;
          samples = syncPopFirst(chunks);
          sampleIndex = 0;
        }
        pair[0] = samples[sampleIndex]*gain;
        pair[1] = samples[sampleIndex+1]*gain;
        sampleIndex += 2;
        if (sampleIndex >= l(samples)) samples = null;
      }
    });
  }
  
  visualize {
    ret centerAndSouth(super.visualize(),
      centerAndEast(
        withLabel("Volume (0-200%):", liveSliderZeroToOne(gain/2, voidfunc(float f) { setField(gain := f*2) })),
        main.onChange(dm_fieldCheckBox('enabled), r { if (!enabled) chunks.clear() })));
  }
}

Author comment

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: 311 / 428
Version history: 10 change(s)
Referenced in: [show references]