Beads Library Audio Visualisation

edited April 2017 in Library Questions

Hey there,

I have a question about the beads audio library: unfortunately there are no examples how to use specific functions and classes shown in the documentation http://www.beadsproject.net/doc/

My problem is, how to separate the output of the FFT/ShortFrameSegmenter from different Gains. I want to visualize each loop track on its own.

I guess the focal point is between my comment lines. Here is my Processing Code:

import beads.*;

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();

    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;

    try {

        player = new SamplePlayer(ac, new Sample(sketchPath("") + "../120bpm/AM_OB-Bass_120-C.wav"));
        g.addInput(player);
        player2 = new SamplePlayer(ac, new Sample(sketchPath("") + "../120bpm/AM_Eighties08_120-01.wav"));
        g2.addInput(player2);
        player3 = new SamplePlayer(ac, new Sample(sketchPath("") + "../120bpm/AM_HeroGuitar_120-E01.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);

    }

}

Answers

  • Previous post possibly related: https://forum.processing.org/two/search?Search=ShortFrameSegmenter

    Also, this is not clear:

    how to separate the output of the FFT/ShortFrameSegmenter from different Gains

    What are the gains in your case?

    Kf

  • Thank you. I've already researched that special case.

    The Gains are the different Inputs that goes all to the AudioContext ac;

    Gain g = new Gain(ac, 2, gainValue);
    SamplePlayer player = null;
    g.addInput(player);
    
     ac.out.addInput(g);
      ac.out.addInput(g2);   // player 2
      ac.out.addInput(g3)    // player 3
    ...
    

    and from this point the ShortFrameSegmenter/TFT goes in the row

    ShortFrameSegmenter sfs = new ShortFrameSegmenter(ac);

    of course I could initializ three different AudioContext but this cases synchronization problems.

Sign In or Register to comment.