Setting speed and way of several samples

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!!!

1 Like

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:

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

1 Like

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:

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

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