Howdy, Stranger!

We are about to switch to a new forum software. Until then we have removed the registration on this forum.

  • Beads - Getting different results each time I run FFT

    I am trying to use the Beads ShortFrameSegmenter and FFT in order to determine the pitch and harmonics of a sample but each time I run my sketch I get different results. Here's my code

    import beads.*;
    import org.jaudiolibs.beads.*;
    import java.util.Timer;
    import java.util.TimerTask;
    
    AudioContext ac;
    GranularSamplePlayer sample;
    Gain gain;
    
    ShortFrameSegmenter sfs;
    FFT fft;
    PowerSpectrum ps;
    Frequency f;
    SpectralPeaks sp;
    float[][] meanHarmonics;
    
    int numPeaks = 6;
    
    int loops = 0;
    double meanFrequency = 0.0;
    Timer t = new Timer();
    boolean finished = false;
    
    void setup() {
      size(1600, 900);
      ac = new AudioContext();
      ac.start();
      sample = new GranularSamplePlayer(ac, SampleManager.sample(dataPath("") + "\\C2.mp3"));
    
      gain = new Gain(ac, 1, 1);
    
      // input chaining
      gain.addInput(sample);
      ac.out.addInput(gain);
    
      // setup analysis
      // break audio into more manageable chunks
      sfs = new ShortFrameSegmenter(ac);
      sfs.addInput(sample);
    
      // fast fourier transform to analyse the harmonic spectrum
      fft = new FFT();
      sfs.addListener(fft);
    
      // PowerSpectrum turns the raw FFT output into proper audio data.
      ps = new PowerSpectrum();
      fft.addListener(ps);
    
      // Frequency tries to determine the strongest frequency in the wave
      // which is the fundamental that determines the pitch of the sound
      f = new Frequency(44100.0f);
      ps.addListener(f);
    
      // Listens for harmonics
      sp = new SpectralPeaks(ac, numPeaks);
      ps.addListener(sp);
    
      meanHarmonics = new float[numPeaks][2];
    
      // initialise meanHarmonics
      for (int i = 0; i < numPeaks; i++) {
        for (int j = 0; j < 2; j++) {
          meanHarmonics[i][j] = 0;
        }
      }
    
      ac.out.addDependent(sfs);
    
      t.scheduleAtFixedRate(new TimerTask() {
        public void run() {
          loops++;
          if (loops == 1) {
            sample.start(0);
          } else if (loops >= 1500) {
            finished = true;
            t.cancel();
          }
          Float inputFrequency = f.getFeatures();
          if (inputFrequency != null && inputFrequency != Float.NaN) {
            println(inputFrequency);
            meanFrequency += inputFrequency;
          }
          float[][] harmonics = sp.getFeatures();
          if (harmonics != null) {
            for (int feature = 0; feature < numPeaks; feature++) {
              // harmonic must be in human audible range
              // and its amplitude must be large enough to be audible
              if (harmonics[feature][0] < 20000.0 && harmonics[feature][1] > 0.01) {
                // average out the frequencies
                meanHarmonics[feature][0] += harmonics[feature][0];
                // average out the amplitudes
                meanHarmonics[feature][1] += harmonics[feature][1];
              }
            }
          }
        }
      }
      , 0, 1);
      while (!finished) { 
        print("");
      }
      float maxAmp = 0.0;
      float freq = 0.0;
      sample.pause(true);
      meanFrequency /= loops;
      println(meanFrequency);
      for (int feature = 0; feature < numPeaks; feature++) {
        meanHarmonics[feature][0] /= loops;
        meanHarmonics[feature][1] /= loops;
        if (meanHarmonics[feature][1] > maxAmp) {
          freq = meanHarmonics[feature][0];
          maxAmp = meanHarmonics[feature][1];
        }
        println(meanHarmonics[feature][0] + " " + meanHarmonics[feature][1]);
      }
      println(freq + " " + meanFrequency);
      println();
    }
    

    For every run I do I get different values for the harmonics' frequencies and amplitudes as well as the meanFrequency value, which is often NaN. I've also noticed that when printing the inputFrequency on each iteration its values are not entirely accurate especially in the lower end of the frequency spectrum. I've tested this both with complex samples and simple sine waves.

    StackOverflow question: https://stackoverflow.com/questions/48769181/getting-different-results-each-time-i-run-fft-with-processing-and-beads

  • Beads Library Audio Visualisation

    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.

  • Beads Library Audio Visualisation

    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

  • Beads Library Audio Visualisation

    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);
    
        }
    
    }
    
  • Beads unable to load mp3s

    I'm using Beads to play mp3s and affect their playback rate. Beads 1.01, Processing 3.3, Windows 10.

    X-Posted here

    I've encountered an issue when loading mp3s that some will be unable to play and throw the error below.

    I've uploaded an mp3 that doesn't work here: r&s and here: movieaudio The movieaudio doesn't throw the error, it just gets stuck on line 23 or 25 in the code.

    The code is a manipulation of the sampling_03.pde example from Sonifying Processing.

    Any light that can be shed on this would be immensely appreciated. Thanks.

    Error:

    AudioContext : no AudioIO specified, using default => beads.JavaSoundAudioIO.
    java.lang.reflect.InvocationTargetException
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:498)
        at processing.core.PApplet.selectCallback(PApplet.java:6529)
        at processing.core.PApplet.access$0(PApplet.java:6522)
        at processing.core.PApplet$3.run(PApplet.java:6434)
        at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:311)
        at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:756)
        at java.awt.EventQueue.access$500(EventQueue.java:97)
        at java.awt.EventQueue$3.run(EventQueue.java:709)
        at java.awt.EventQueue$3.run(EventQueue.java:703)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:76)
        at java.awt.EventQueue.dispatchEvent(EventQueue.java:726)
        at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:201)
        at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:116)
        at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:105)
        at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
        at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93)
        at java.awt.EventDispatchThread.run(EventDispatchThread.java:82)
    Caused by: java.lang.NullPointerException
        at beads.SamplePlayer.<init>(Unknown Source)
        at Sound_BeadsII.fileSelected(Sound_BeadsII.java:47)
        ... 21 more
    

    Code:

    import beads.*;
    import java.util.Arrays; 
    AudioContext ac;
    SamplePlayer sp1;
    PowerSpectrum ps;
    Gain sampleGain;
    Glide gainValue;
    Glide rateValue;
    color fore = color(255, 102, 204);
    float rangeAvg = -1, timeValue = 2;
    
    void setup() {
      size(800, 600);
    
      ac = new AudioContext();
      selectInput("Select an audio file:", "fileSelected");
      background(0); 
      //1440 frames / 60 seconds = 0.0625 seconds/frame
    }
    
    void fileSelected(File selection) {
      println("here fileselection");
      String audioFileName = selection.getAbsolutePath();
      println("here loaded from absolutepath");
      Sample sample = SampleManager.sample("2048", audioFileName);
      println("here loaded selected file");
      //SamplePlayer player = new SamplePlayer(ac, sample);
      //Gain g = new Gain(ac, 2, 0.2);
      //g.addInput(player);
      //ac.out.addInput(g);
      sp1 = new SamplePlayer(ac, sample);
      println("here initialising sp1");
    
      //try {  
      //  sp1 = new SamplePlayer(ac, sample);
      //  //sp1 = new SamplePlayer(ac, new Sample(sketchPath("") + "/data/Hellboy_audio.mp3"));
      //}  
      //catch(Exception e) {
      //  println("Exception while attempting to load sample!");
      //  e.printStackTrace(); //print a technical description of the error
      //}
      // note that we want to play the sample multiple times
      sp1.setKillOnEnd(false);
    println("here to killonend");
      rateValue = new Glide(ac, 1, 30); // initialize our rateValue Glide object
      sp1.setRate(rateValue); // connect it to the SamplePlayer
    println("here setting sp1.ratevalue");
      // volume of our sample player
      gainValue = new Glide(ac, 0.7, 30);
      sampleGain = new Gain(ac, 1, gainValue);
      sampleGain.addInput(sp1);
    
      ac.out.addInput(sampleGain); // connect the Gain to the AudioContext
    
      //analysis chain
      ShortFrameSegmenter sfs = new ShortFrameSegmenter(ac);
      sfs.addInput(ac.out);
      FFT fft = new FFT();
      ps = new PowerSpectrum();
      sfs.addListener(fft);
      fft.addListener(ps);
      ac.out.addDependent(sfs);
      ac.start();
    }
    
    void draw() {
      //float halfWidth = width / 2.0;
      //gainValue.setValue((float)mouseY / (float)height); // set the gain based on mouse position along the Y-axis
      //rateValue.setValue((((float)mouseX - halfWidth)/halfWidth)+1); // set the rate based on mouse position along the X-axis
    
      background(0);
      stroke(fore);
    
      if (ps == null) return;
      float[] features = ps.getFeatures();
    
      if (features != null) {
    
        for (int i = 0; i < width; i++) {
          int featureIndex = i * features.length / width/2;
          int vOffset = height - Math.min((int)(features[featureIndex] * height), height);
          rangeAvg += vOffset;
          //println("rangeAvg: " + rangeAvg);
          line(i, 0, i, vOffset);
        }
        rangeAvg = rangeAvg / width;
        println("rangeAvg Avg: " + rangeAvg);
    
        if      (rangeAvg > 0   && rangeAvg < 100) {rateValue.setValue(timeValue/4); println("1/4x");}
        else if (rangeAvg > 100 && rangeAvg < 200) {rateValue.setValue(timeValue/2); println("1/2x");}
        else if (rangeAvg > 200 && rangeAvg < 300) {rateValue.setValue(timeValue);   println("1x");}
        else if (rangeAvg > 300 && rangeAvg < 400) {rateValue.setValue(timeValue*2); println("2x");}
        else if (rangeAvg > 400 && rangeAvg < 500) {rateValue.setValue(timeValue*3); println("3x");}
        else if (rangeAvg > 500 && rangeAvg < 600) {rateValue.setValue(timeValue*4); println("4x");}
    
      }
    }
    
  • Using Beads Library in Processing - Using peakdetector on multiple objects | Sample visualization

    Okeydoke, I'm working on a sketch using the beads and SMT libraries. I have a few things that I'm struggling with, if you can help, that'd be awesome.

    The Questions:

    • Trying to make each object respond by lighting up as it is played (controlled by audioPlay), currently all do at the same time, any ideas on separating the functions?

    • I can't work out why the variable brightTime, although it occurs for each function (myobject1/2/3) - seems to have an effect on the counter globally for some reason. Any ideas?

    • Any help on the timing function audioDraw would be appreciated - I'm not sure I've got it worked out very well as I want to make sure that if one period elapses before another beat the color jumps to full 255 alpha again.

    Any other fixes or re modelling suggestions are more than welcome.

    Thanks guys.

    import vialab.SMT.*;
    import beads.*;
    
    //Objects
    object myobject1;
    object myobject2;
    object myobject3;
    
    //Sketch Variables
    float midX, midY, length1;
    //Zone Variables
    float cX, cY;
    //Time Variables
    float m, n, t, dim;
    //Beat Variables
    float beat1, beat2, beat3, beat4, brightTime;
    float bpm;
    boolean play;
    
    
    AudioContext ac;
    
    void setup() {
      midX = width/2;
      midY = height/2;
      length1 = 100;
    
      //size(displayWidth, displayHeight, SMT.RENDERER);
      size(1000, 700, SMT.RENDERER);
      myobject1 = new object(0, 0, length1, length1, 0, 20, 100, 200);
      myobject2 = new object(0, 0, length1, length1, 0, 10, 200, 180);
      myobject3 = new object(0, 0, length1, length1, 0, 0, 0, 150);
    
      SMT.init( this, TouchSource.AUTOMATIC);
    
      Zone zone = new Zone("Object", 480, 200, 100, 100);
      Zone zone2 = new Zone("Object2", 480, 330, 100, 100);
      Zone zone3 = new Zone("Object3", 480, 460, 100, 100);
    
      SMT.add( zone);
      SMT.add( zone2);
      SMT.add( zone3);
    
      m = millis()/10;
      t = 0;
    
    if (brightTime <= 0) {
            brightTime = t;
            dim = t;
            play = false;
          }
    
      ac = new AudioContext(); 
    
      myobject1.audio();
      myobject2.audio();
      myobject3.audio();
      play = false;
    }
    
    void draw() {
    
      background(0);
      noStroke();
      frameRate(100);
      m++;
      dim++;
    
      println( m );
    
      myobject1.texts();
    
      myobject1.timer();
    //  myobject2.timer();
    //  myobject3.timer();
    }
    
    void drawObject(Zone zone) {
      cX = zone.getX();
      cY = zone.getY();
      text("1", 0, 0);
      myobject1.audioIn();
      myobject1.display();
    }
    void touchObject(Zone zone) {
      zone.drag();
    }
    
    void drawObject2(Zone zone2) {
      cX = zone2.getX();
      cY = zone2.getY();
      text("2", 0, 0);
      myobject2.audioIn();
      myobject2.display();
    }
    void touchObject2(Zone zone2) {
      zone2.drag();
    }
    
    void drawObject3(Zone zone3) {
      cX = zone3.getX();
      cY = zone3.getY();
      text("3", 0, 0);
      myobject3.audioIn();
      myobject3.display();
      //  myobject3.audioDraw();
    }
    void touchObject3(Zone zone3) {
      zone3.drag();
    }
    
    class object {
      float xpos, ypos, wid, hei, vol, room, pit, bright, brightTime, dim, rate, Xrate;
      color c, b, a, d;
      float textY;
      int dt;
    
      String sourceFile; // this will hold the path to our audio file
      SamplePlayer sp; // the SamplePlayer class will be used to play the audio file
      PowerSpectrum ps;
      PeakDetector od;
      ShortFrameSegmenter sfs;
    
      //Gain
      Gain g;
      Glide gainValue;
      //Reverb
      Reverb r; // our Reverberation unit generator
      float brightness;
      int time; // tracks the time 
    
        object(float tempXpos, float tempYpos, float tempWid, float tempHei, float tempRoom, color tempA, color tempB, color tempC) {
        xpos = tempXpos;
        ypos = tempYpos;
        wid = tempWid;
        hei = tempHei;
        room = tempRoom;
        a = tempA;
        b = tempB;
        c = tempC;
      }
    
      void audio() {
    
        sourceFile = dataPath("sounds.wav");
        try {  
          sp = new SamplePlayer(ac, new Sample(sourceFile));
        }
        catch(Exception e)
        {
          println("Exception while attempting to load sample!");
          e.printStackTrace(); 
          exit();
        }
        sp.setKillOnEnd(false);
    
        gainValue = new Glide(ac, 0.0, 20);
        g = new Gain(ac, 1, gainValue);
        g.addInput(sp); // connect the filter to the gain
        r = new Reverb(ac, 1); // create a new reverb with a single output channel
        r.setSize(0.5); // set the room size (between 0 and 1) 0.5 is the default
        r.setDamping(room); // set the damping (between 0 and 1) - the higher the dampening, the fewer resonant high frequencies
        r.addInput(g); // connect the gain to the reverb
        ac.out.addInput(r); // connect the Reverb to the AudioContext
      }
    
      void texts() {
        fill(255);
        textY = 100;
    
    //    text(+myobject1.pit, 100, textY);
    //    text(+myobject1.room, 100, textY+20);
    //    text(+myobject2.pit, 100, textY+40);
    //    text(+myobject2.room, 100, textY+60);
    //    text(+myobject3.pit, 100, textY+80);
    //    text(+myobject3.room, 100, textY+100);
        text("time "+m, 100, midY);
        text("beat1 "+beat1, 100, midY+20);
        text("brightTime "+brightTime, 100, midY+40);
        text("dim "+dim, 100, midY+60);
    
        text("brightTime1 "+myobject1.brightTime, 100, midY+300);
        text("bright1 "+myobject1.bright, 100, midY+320);
        text("rate "+myobject1.rate, 100, midY+340);
        text("brightTime2 "+myobject2.brightTime, 300, midY+300);
        text("bright2 "+myobject2.bright, 300, midY+320);
        text("rate2 "+myobject2.rate, 300, midY+340);
        text("brightTime3 "+myobject3.brightTime, 500, midY+300);
        text("bright2 "+myobject3.bright, 500, midY+320);
        text("rate3 "+myobject3.rate, 500, midY+340);
      }
    
      void audioPlay() {
        gainValue.setValue(4);
        r.setSize(room);
        sp.setPitch(new Glide(ac, pit));
        ac.start(); // begin audio processing
        sp.setToLoopStart(); // move the playback pointer to the first loop point (0.0)
        sp.start(); // play the audio file
      }
    
      void timer() {
        beat1 = (100*(60/bpm));
        beat2 = (200*(60/bpm));
        beat3 = (300*(60/bpm));
        beat4 = (400*(60/bpm));
    
        if ( key== 'q') {
          bpm = 60;
        } else if (key== 'w') {
          bpm = 120;
        } else if (key== 'e') {
          bpm = 240;
        } else {
          bpm = 30;
        }
    
        if (m == beat1) {
          myobject1.audioPlay( );
          play = true;
        }  
        if (m == beat2) {
          //      myobject2.audioPlay();
        }
        if (m == beat3) {
          myobject2.audioPlay();
          play = true;
        }
        if (m == beat4) {
          //      myobject1.audioPlay();
        }
        if (m == beat4) {
          m = t;
        }
      }
    
      void display() {
        noStroke();
        colorMode(RGB);
        fill(a, b, c);    
        rectMode(CORNER);
        rect(xpos, ypos, wid, hei);
        stroke(255);
        line((xpos+(wid/2)), (ypos+(hei/2)), (xpos+(wid/2)), ypos);
        audioDraw();
      }
    
      void audioIn() {
        room = map(cX, 0, width, 0, 0.9);
        pit = map(cY, 0, height, 2, 0);
        rate = map(cY, 0, height, 1, 2);
        Xrate = map(cX, 0, width, 1, 1.5);
      }
    
      void audioDraw() {
        if (play == true) {
          fill(255, 0, 0, brightTime);
          rectMode(CORNER);
          rect(xpos, ypos, wid, hei);
          dim++;
          bright = 150;
          brightTime = bright - dim/(rate*Xrate);
        }
        if (brightTime <= 0) {
          brightTime = t;
          dim = t;
          play = false;
        }
      }
    }
    
  • Trouble with beads

    Hey everyone. I'm creating a program for a project using Beads and Processing that measures frequency and the musical 'key' that frequency is in. It draws randomly based on said factors, however I'm having trouble constraining the input so that it will read more accurately. Any thoughts? Here is my code below, thanks!:

    import beads.*; AudioContext ac; PowerSpectrum ps; Glide frequencyGlide; Frequency f; //WavePlayer wp; int i; int buffIndex; float meanFrequency; float average; float inputFrequency;

    //color fore = color(255, 255, 255); //color back = color(0, 0, 0); //int Arrays; void setup() { size(800, 800);

    ac = new AudioContext();

    UGen microphoneIn = ac.getAudioInput();//UGen is the audio input class

    Gain g = new Gain (ac, 0, 0.5); frequencyGlide = new Glide (ac, 0, 0); //wp = new WavePlayer (ac, frequencyGlide, Buffer.SINE);

    g.addInput(g);

    ShortFrameSegmenter sfs = new ShortFrameSegmenter(ac);

    sfs.addInput(microphoneIn);

    FFT fft = new FFT();

    sfs.addListener(fft);

    ps = new PowerSpectrum();

    fft.addListener(ps); g.addInput(microphoneIn); ac.out.addInput(g); f = new Frequency(44100.0f);

    ps.addListener(f); ac.out.addDependent(sfs); ac.start(); }

    void draw() { background(0, 0, 0); //stroke(fore);

    float readFreq =constrain(inputFrequency,82.41,1500.0); fill(255);

    text("Input Frequency: " + meanFrequency, 200, 200); if (f.getFeatures() != null && (1.0)>= .75) { float inputFrequency = f.getFeatures();

    if ( inputFrequency> 1000) { meanFrequency = (0.4 * inputFrequency) + (0.6 * meanFrequency); frequencyGlide.setValue(meanFrequency); } stroke(255); line(width/2, height/2, inputFrequency, 0); stroke(random(0,255),random(0,255),random(0,255)); line(width/2+100, height/2+100, inputFrequency, 0); stroke(random(0,255),random(0,255),random(0,255)); line(width2, height2, inputFrequency, 0); stroke(random(0,255),random(0,255),random(0,255)); line(width2+100, height2+100, inputFrequency, 0); stroke(random(0,255),random(0,255),random(0,255)); line(width/4, height/4, inputFrequency, 0); stroke(random(0,255),random(0,255),random(0,255)); line(width/2-100, height/2-100, inputFrequency, 0); stroke(random(0,255),random(0,255),random(0,255)); line(width/4, height/4, inputFrequency, 0); stroke(random(0,255),random(0,255),random(0,255)); line(width*4-100, height-4+100, inputFrequency, 0);

    //change random to input freq// int sampleNumber=50; //fore=(int)inputFrequency/10; //ellipse(width/2, height/2, inputFrequency/2, inputFrequency/2); float[] values= new float[sampleNumber]; for (int i=0; i<values.length; i++) { values[i]= inputFrequency; float average=(values[0]+values[1]+values[2]+values[3]+values[4]+values[5]+values[6]+values[7]+values[8] +values[9]+values[10]+values[11]+values[12]+values[13]+values[14]+values[15]+values[16]+values[17]+values[18]); println("the average"+" "+average); float drawValue=map(average,inputFrequency,1000,0,255); float drawValueR=map(average,inputFrequency,900,0,255); float drawValueG=map(average, inputFrequency,800,0,255); float drawValueB=map(average, inputFrequency,700,0,255); float drawValueSizeW=map(average, inputFrequency, inputFrequency, 0, width); float drawValueSizeH=map(average, inputFrequency, 900, 0, height); fill(drawValueR,drawValueG,drawValueB); stroke(random(0,255),random(0,255),random(0,255)); //line(85, 20, 100, 100); //line(drawValue, 90, 150, 180); frameRate(24); stroke(random(0,255),random(0,255),random(0,255)); fill(random(drawValueR,drawValueB),random(drawValueR,drawValueB),random(drawValueR,drawValueB)); ellipse(350,350,random(0,255),random(0,255)); fill(random(drawValueR,drawValueB),random(drawValueR,drawValueB),random(drawValueR,drawValueB)); ellipse(550,550,random(0,255)/2,random(0,255)/2); fill(random(drawValueR,drawValueB),random(drawValueR,drawValueB),random(drawValueR,drawValueB)); ellipse(350,350,random(drawValueR,drawValueB)/6,random(0,255)); //fill(drawValue, drawValue-128, drawValue); //rect(0, 0, width, height); println(drawValue+" drawValue"); } } }