# Setting speed and way of several samples

**URL:** <https://discourse.processing.org/t/setting-speed-and-way-of-several-samples/11035>\
**Category:** Project Guidance\
**Created:** [May 8, 2019, 12:53pm UTC](https://discourse.processing.org/t/setting-speed-and-way-of-several-samples/11035 "2019-05-08T12:53:37Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![bking](https://avatars.discourse-cdn.com/v4/letter/b/dc4da7/32.png) [@bking](https://discourse.processing.org/u/bking)\
**Post date:** [May 8, 2019, 12:53pm UTC](https://discourse.processing.org/t/setting-speed-and-way-of-several-samples/11035/1 "2019-05-08T12:53:37Z")

</div>

Hi,  
I would like to know if a program already exist to control the speed and way (backward/forward) of several sound sample (mp3) in order to play it as DJ could done with several turntable.  
My data of speed (positive or negative will come from data of Arduino).

Thanks for yours advices and lights!!!

---

<div class="post-metadata">

**Author:** ![kfrajer](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kfrajer/32/196_2.png) [@kfrajer](https://discourse.processing.org/u/kfrajer)\
**Post date:** [May 8, 2019, 5:53pm UTC](https://discourse.processing.org/t/setting-speed-and-way-of-several-samples/11035/2 "2019-05-08T17:53:37Z")

</div>

I don’t think you can use the Sound library as the rate is expected to be positive by doing a quick test. I did some research and it seems you should be use the Beads library. Some links to get you started:

- [http://www.beadsproject.net/](http://www.beadsproject.net/) (Check at the end, keyword: backwards)
- [www.beadsproject.net/doc/net/beadsproject/beads/ugens/SamplePlayer.html](http://www.beadsproject.net/doc/net/beadsproject/beads/ugens/SamplePlayer.html)
- A demo in Processing using SamplePlayer: [https://forum.processing.org/two/discussion/22221/beads-library-audio-visualisation](https://forum.processing.org/two/discussion/22221/beads-library-audio-visualisation)

Run your own test and become familiar with the library. If you have the arduino code setup, you could do the integration as a third step.

Kf

---

<div class="post-metadata">

**Author:** ![bking](https://avatars.discourse-cdn.com/v4/letter/b/dc4da7/32.png) [@bking](https://discourse.processing.org/u/bking)\
**Post date:** [May 9, 2019, 2:08pm UTC](https://discourse.processing.org/t/setting-speed-and-way-of-several-samples/11035/3 "2019-05-09T14:08:01Z")

</div>

Hi Kfrajer,

I test the SamplePlayer and it’s quite funny for setting speed and easy to use because you can select sample just by starting the program.  
But, I can’t manage to use properly the demo in your last link.  
I have tried to change the code but without success. the console says this:

```auto
AudioContext : no AudioIO specified, using default => beads.JavaSoundAudioIO.
java.io.IOException: Problem loading file (class=class beads.WavFileReaderWriter) /Users/macbookpro/Documents/Processing/Lireplusieurssamples2/130_ChillinBeat_SP_01.wav, Could not read audio file: /Users/macbookpro/Documents/Processing/Lireplusieurssamples2/130_ChillinBeat_SP_01.wav (No such file or directory)
	at beads.Sample.loadAudioFile(Unknown Source)
	at beads.Sample.<init>(Unknown Source)
	at Lireplusieurssamples2.setup(Lireplusieurssamples2.java:88)
	at processing.core.PApplet.handleDraw(PApplet.java:2425)
	at processing.awt.PSurfaceAWT$12.callDraw(PSurfaceAWT.java:1547)
	at processing.core.PSurfaceNone$AnimationThread.run(PSurfaceNone.java:313)
NullPointerException

```

and the program that I tried to change

```auto
import beads.*;
import java.util.Arrays; 
 
AudioContext ac;
PowerSpectrum ps;
Glide gainValue, gainValue2, gainValue3;
 
Frequency f;
SpectralCentroid sc;
SpectralPeaks sp;
int nPeaks;
float fColor = 0;
 
void setup() {
    size(600, 600);
 
   
 
    ac = new AudioContext();
// **** the original program 
    gainValue = new Glide(ac, 0.5, 20);
    Gain g = new Gain(ac, 2, gainValue);
 
    gainValue2 = new Glide(ac, 0.5, 20);
    Gain g2 = new Gain(ac, 2, gainValue2);
 
    gainValue3 = new Glide(ac, 0.5, 20);
    Gain g3 = new Gain(ac, 2, gainValue3);

    SamplePlayer player = null;
    SamplePlayer player2 = null;
    SamplePlayer player3 = null;

// **** a possibility to control gain value of each sample?    
/*
    Gain g = new Gain(ac, 2, gainValue);
    
    Gain g2 = new Gain(ac, 2, gainValue);
    
    Gain g3 = new Gain(ac, 2, gainValue);
    
     SamplePlayer player = null;
     SamplePlayer player2 = null;
     SamplePlayer player3 = null;
     
   g.addInput(player);
   g2.addInput(player);
   g3.addInput(player);
    
    ac.out.addInput(g);
    ac.out.addInput(g2); // player 2
    ac.out.addInput(g3); // p^ayer 3
 */
 // ******** end of the possible program
 
 
 
    try {
    
      
  /*    
       player = new SamplePlayer(ac, new Sample(sketchPath("") + "../130bpm/130_ChillinBeat_SP_01.wav"));
        g.addInput(player);
        player2 = new SamplePlayer(ac, new Sample(sketchPath("") + "../130bpm/130_DelaySnareBeat_SP_01.wav"));
        g2.addInput(player2);
       player3 = new SamplePlayer(ac, new Sample(sketchPath("") + "../130bpm/130_Floor4Beat_SP_01.wav"));

 */  
        player = new SamplePlayer(ac, new Sample(sketchPath("") + "130_ChillinBeat_SP_01.wav"));
        g.addInput(player);
        player2 = new SamplePlayer(ac, new Sample(sketchPath("") + "130_DelaySnareBeat_SP_01.wav"));
        g2.addInput(player2);
        player3 = new SamplePlayer(ac, new Sample(sketchPath("") + "130_Floor4Beat_SP_01.wav"));
        g3.addInput(player3);
     
    }
    
    catch (Exception e) {
        e.printStackTrace();
    }
 
    player.setKillOnEnd(false);
    player2.setKillOnEnd(false);
    player3.setKillOnEnd(false);
 
    player.setLoopType(SamplePlayer.LoopType.LOOP_FORWARDS);
    player2.setLoopType(SamplePlayer.LoopType.LOOP_FORWARDS);
    player3.setLoopType(SamplePlayer.LoopType.LOOP_FORWARDS);
 
    ac.out.addInput(g);
    ac.out.addInput(g2);
    ac.out.addInput(g3);
 
 
    /////////////////////
 
    ShortFrameSegmenter sfs = new ShortFrameSegmenter(ac);
    sfs.addInput(ac.out);
 
    FFT fft = new FFT();
    sfs.addListener(fft);
 
    ps = new PowerSpectrum();
    fft.addListener(ps);
 
    ac.out.addDependent(sfs);
 
    ////////////////////
 
    ac.start();
}
 
 
void draw() {
 
    float[] features = ps.getFeatures();
 
    if (features != null) {
 
        float bass = 0;
        for (int i = 5; i < 10; ++i) {
 
            bass += features[i];
        }
        bass /= (float)(5);
 
        float heights = 0;
        for (int i = 40; i < 45; ++i) {
 
            heights += features[i];
        }
        heights /= (float)(5);
 
        ellipse(width / 2 - 100, height / 2, bass * 20, bass * 20);
        ellipse(width / 2 + 100, height / 2, heights * 50, heights * 50);
 
    }
 
}

```

Regards, Benjamin
