Quantcast
Channel: Library Questions - Processing 2.x and 3.x Forum
Viewing all articles
Browse latest Browse all 2896

How can associate Amplitude analyze() (sound library) with a GImageButton (G4P library)

$
0
0

How can I associate the rms.input with a GImageButton?

I think that the problem is that if I have these arguments:

seq3.play(k, 1.0);
rms = new Amplitude(this);
rms.input(seq3);

in the setup() and I press a GImageButton of play, I obtain only 0.0 always, and if I change it to another position to activate them when I press play button an error appear. If I have the example Amplitude in Sound Library and I try to put in draw()

rms = new Amplitude(this); rms.input(sample);

everything crash with the following error:Untitled

I need to put and GImageButton to play the song and to start to analize de Amplitude. But if I put these like

public void setup() {
    size(640,360);
    sample = new SoundFile(this, "Seq3.aiff");
}

public void draw() {
    background(125,255,125);
    noStroke();
    fill(255,0,150);

    sum += (rms.analyze() - sum) * smooth_factor;

    float rms_scaled=sum*(height/2)*scale;

    ellipse(width/2, height/2, rms_scaled, rms_scaled);
    println(rms_scaled);
}

void handleButtonEvents(GImageButton button, GEvent event){
if(button == btnPlaySeq3){
    loop();
    seq3.play(k, 1.0);
    rms = new Amplitude(this);
    rms.input(seq3);
    }

everything crash and appear the same error. If I put

rms = new Amplitude(this); rms.input(sample);

in the setup() and only seq3.play(k, 1.0) in the handleButtonEvents like this

void setup() {
            size(640,360);

    sample = new SoundFile(this, "Seq3.aiff");

    rms = new Amplitude(this);
    rms.input(sample);
}

public void draw() {
        background(125,255,125);
        noStroke();
        fill(255,0,150);

        sum += (rms.analyze() - sum) * smooth_factor;

        float rms_scaled=sum*(height/2)*scale;

        ellipse(width/2, height/2, rms_scaled, rms_scaled);
        println(rms_scaled);
    }

void handleButtonEvents(GImageButton button, GEvent event){
if(button == btnPlaySeq3){
    loop();
    seq3.play(k, 1.0);
    }

if(button == btnStopSeq3){
    loop();
    seq3.stop();
    mode = 3;
  }

after press the play button only appears 0.0 and never change. Also, when the soundfile finish, an error appears and I need to reopen the file.

Note: I put only the main code of the problem because I have a lot of Tabs to create a visual interface


Viewing all articles
Browse latest Browse all 2896

Trending Articles