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

29
LINES

< > BotCompany Repo | #1019653 // StreamingSoundSource - pre-buffers multiple chunks

JavaX fragment (include)

sclass StreamingSoundSource extends VF1<double[]> {
  bool enabled;
  L<short[]> chunks = synchroLinkedList();
  int minChunksToPlay = 2;
  short[] samples;
  int sampleIndex;

  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];
    pair[1] = samples[sampleIndex+1];
    sampleIndex += 2;
    if (sampleIndex >= l(samples)) samples = null;
  }
  
  void addChunk(short[] chunk) { chunks.add(chunk); }
  
  void setEnabled(bool b) {
    enabled = b;
    if (!b) chunks.clear();
  }
}

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: #1019653
Snippet name: StreamingSoundSource - pre-buffers multiple chunks
Eternal ID of this version: #1019653/5
Text MD5: 8a1493efaaf43c19a3df8eb1c1e084c5
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2018-11-16 16:33:00
Source code size: 769 bytes / 29 lines
Pitched / IR pitched: No / No
Views / Downloads: 259 / 807
Version history: 4 change(s)
Referenced in: [show references]