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)

1  
sclass StreamingSoundSource extends VF1<double[]> {
2  
  bool enabled;
3  
  L<short[]> chunks = synchroLinkedList();
4  
  int minChunksToPlay = 2;
5  
  short[] samples;
6  
  int sampleIndex;
7  
8  
  public void get(double[] pair) {
9  
    pair[0] = pair[1] = 0;
10  
    if (!enabled) ret;
11  
    if (samples == null) {
12  
      if (l(chunks) < minChunksToPlay) { minChunksToPlay = 2; ret; }
13  
      minChunksToPlay = 1;
14  
      samples = syncPopFirst(chunks);
15  
      sampleIndex = 0;
16  
    }
17  
    pair[0] = samples[sampleIndex];
18  
    pair[1] = samples[sampleIndex+1];
19  
    sampleIndex += 2;
20  
    if (sampleIndex >= l(samples)) samples = null;
21  
  }
22  
  
23  
  void addChunk(short[] chunk) { chunks.add(chunk); }
24  
  
25  
  void setEnabled(bool b) {
26  
    enabled = b;
27  
    if (!b) chunks.clear();
28  
  }
29  
}

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: 194 / 742
Version history: 4 change(s)
Referenced in: [show references]