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

23
LINES

< > BotCompany Repo | #1016690 // Mix 2 Loops (OK)

JavaX source code (desktop) [tags: use-pretranspiled] - run with: x30.jar

Download Jar. Libraryless. Click here for Pure Java version (3071L/22K).

!7

static int bufSize = 40960;

p {
  short[] loop1 = decodeWAVToStereoSamples(loadLibrary(#1400093));
  short[] loop2 = decodeWAVToStereoSamples(newFile(downloadsDir(), "27130__pryght-one__harp.wav"));
  VF1<short[]> vf = mixLoops(loop1, loop2);
  playAudioFromSampleMakingFunction(bufSize, vf);
}

static VF1<short[]> mixLoops(final short[] loop1, final short[] loop2) {
  ret new VF1<short[]>() {
    int i = 0;
    
    void get(short[] pair) {
      int j = max(0, min(l(loop2), 2*iround(i/2*((double) l(loop2))/l(loop1))));
      pair[0] = (short) ((loop1[i] + loop2[j])/2);
      pair[1] = (short) ((loop1[i+1] + loop2[j+1])/2);
      i = (i+2) % l(loop1);
    }
  };
}

Author comment

Began life as a copy of #1016688

download  show line numbers  debug dex  old transpilations   

Travelled to 14 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, irmadwmeruwu, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #1016690
Snippet name: Mix 2 Loops (OK)
Eternal ID of this version: #1016690/6
Text MD5: ee65cfaf40d902d83c24ceebcd543bfd
Transpilation MD5: 42b8c3c0a0518907b2e66247a2c262f7
Author: stefan
Category: javax / sound
Type: JavaX source code (desktop)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2018-06-28 00:56:24
Source code size: 699 bytes / 23 lines
Pitched / IR pitched: No / No
Views / Downloads: 409 / 1033
Version history: 5 change(s)
Referenced in: [show references]