javascript - Manipulating sound p5.js or processing.js -


i have spent hours novice processing knowledge trying turn processing program online equivalent students. seeking of masses!

the biggest problem there no minim library in processing.js or p5.js. in other words, program below work in openprocessing.org. audio processing program allows students

i feel have combed extensively through http://processingjs.org/reference/ , https://p5js.org/reference/#/libraries/p5.sound no avail.

the big stuff happening in myeffect class. process() function reads memory array of samples , processes each of them 1 @ time. duplicate capability in openprocessing.org. line students alter

newsamp[j] = samp[j];

to like

newsamp[j] = samp[j] * 2;

and explain how has altered sound.

here program in original processing form:

import ddf.minim.spi.*; import ddf.minim.signals.*; import ddf.minim.*; import ddf.minim.analysis.*; import ddf.minim.ugens.*; import ddf.minim.effects.*;  minim minim; audioplayer song; float[] oldsamp; string songfilename = "basicdrum.mp3"; final int buffersize = 4096;  void setup() {   size(640,200);   stroke(255);   textsize(32);    minim = new minim(this);   song = minim.loadfile(songfilename, buffersize);    song.addeffect(new myeffect());   oldsamp = new float[song.buffersize()];   song.play();  }   void draw() {   /* draw visualizer */   background(0);   fill(#bbbb00);   text("mono channel", 50, 50);   (int = 0; < song.buffersize() - 1; i++)   {     line(i, 100 + song.left.get(i)*100, i+1, 100 +song.left.get(i+1)*100);   } }  class myeffect implements audioeffect {    void process(float[] samp)   {     float[] newsamp = samp.clone();  //create copy alter     int j = 0;      while (j < newsamp.length)     {       newsamp[j] = samp[j];          /* here alter each sample */       j = j + 1;     }     oldsamp = samp.clone();          //save copy of later     // have copy values samp work     arraycopy(newsamp, samp);   }    void process(float[] left, float[] right)    //stereo has left , right channels   {     float[] average = left;      (int = 0; < left.length; i++)       {             average[i] = (left[i] + right[i])/2.0;       }     process(average);   } } 

thank guidance can provide!

you aren't going able directly translate line-by-line processing either processing.js or p5.js, you've discovered there no javascript version of minim. (well, there is, it's pretty old.)

(taking step back, should never try translate code 1 language going line-by-line.)

instead, need take what code does , figure out how in target language (in case, javascript).

i'd start googling "p5.js sound" or "processing.js sound" or "javascript sound". again, goal figure out how play sounds in javascript, not recreate minim line-by-line.

see also:


Comments

Popular posts from this blog

Is there a better way to structure post methods in Class Based Views -

performance - Why is XCHG reg, reg a 3 micro-op instruction on modern Intel architectures? -

jquery - Responsive Navbar with Sub Navbar -