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

41
LINES

< > BotCompany Repo | #1016692 // Mix 2 Loops with switching second loop (OK)

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

Download Jar. Libraryless. Click here for Pure Java version (6365L/44K).

!7

static int bufSize = 40960;
static short[] loop1, loop2;
static volatile short[] nextLoop2;
static double speed2 = 2;

p {
  loop1 = decodeWAVToStereoSamples(loadLibrary(#1400093));
  loop2 = decodeWAVToStereoSamples(newFile(downloadsDir(), "Audio/103615__deller24__loop1.wav"));
  VF1<double[]> vf = mixLoops();
  playAudioFromSampleMakingFunction(bufSize, vf);
  bot();
}

sS answer(S s) {
  new Matches m;
  if (swic_trim(trim(s), "speed ", m)) ret "OK" with speed2 = parseDouble($1);
  File f = putInDirIfNotAbsolute(downloadsDir(), s);
  nextLoop2 = decodeWAVToStereoSamples(f);
  ret "OK";
}

static VF1<double[]> mixLoops() {
  ret new VF1<double[]>() {
    int i = 0;
    
    void get(double[] pair) {
      int j = mod(2*iround(
        i/2*((double) l(loop2))/l(loop1)*speed2), l(loop2));
      pair[0] = (loop1[i] + loop2[j])/2.0;
      pair[1] = (loop1[i+1] + loop2[j+1])/2.0;
      i = (i+2) % l(loop1);
      if (i == 0 && nextLoop2 != null) {
        print("Switching");
        loop2 = nextLoop2;
        nextLoop2 = null;
      }
    }
  };
}

Author comment

Began life as a copy of #1016690

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: #1016692
Snippet name: Mix 2 Loops with switching second loop (OK)
Eternal ID of this version: #1016692/19
Text MD5: dd31e0556526f1be75bcc5ca3181fbf7
Transpilation MD5: 8d3bed4820dc79f83c8d2d9213cd1293
Author: stefan
Category: javax / sound
Type: JavaX source code (desktop)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2018-12-08 17:07:29
Source code size: 1104 bytes / 41 lines
Pitched / IR pitched: No / No
Views / Downloads: 358 / 847
Version history: 18 change(s)
Referenced in: [show references]