What is the code for my wave to move at the same time as the song?

Hello everyone!
I’m having trouble knowing how my wave moves at the same time as my music. In this sense, I would like to know if anyone can help me to resolve this issue?
I already created my wave and put my music on processing:

import ddf.minim.*;

Minim minim;
AudioPlayer song;

void setup(){
size(1000, 1000);

minim = new Minim(this);
  song = minim.loadFile("Maroon 5 - Beautiful Mistakes ft. Megan Thee Stallion (Official Lyric Video)");


void draw() {
 line(0, 550, width, 550); 
 float x = 0; 
 while(x < width) { 
   point(x, 550+ 20 * sin(x/10));
   x = x + 1; 


Thank you!

Hey Marga,
I think u r trying to visualize sound amplification
try watching this great video by Daniel Shiffman it might help

The sound libraries have examples that come with them.

Processing sound library:

The Minim library also has resources and examples.


Hello again! I found this example in the processing library:

import processing.sound.*;

SoundFile sample;
Amplitude rms;

float smoothingFactor = 0.25;

float sum;

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

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

  rms = new Amplitude(this);

public void draw() {

  background(125, 255, 125);
  fill(255, 0, 150);

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

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

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

and that was what I was looking for, but when I change the song in the place where it is to a meter, the song I want does not play. And the song has already imported it into the same folder where this sketch is located, can someone help me understand what I’m doing wrong? Thank you

what is the error massage you got ?

From the Processing PDE in the file menu select sketch/ add file/ then select your song

This error:

abr 30, 2021 12:03:31 PM com.jsyn.devices.javasound.JavaSoundAudioDevice
INFO: JSyn: default output latency set to 80 msec for Windows 10
Sound library error: unable to find file Maroon 5 - Nobody’s Love (Official Lyric Video).wav
Could not run the sketch (Target VM failed to initialize).
For more information, read revisions.txt and Help ? Troubleshooting.

From the Processing PDE in the file menu select sketch/ add file/ then select your song

I already did it but, it didn’t work

chick spelling and UPPER or lower case is important

Good afternoon.
In the meantime I manage to solve some problems that I had in relation to this issue of mine, but other questions arose.
I already have this code and I managed to get my wave to work at the same time as my music, however, there is a delay or something like that, that doesn’t let the wave accompany the music, I think it’s from frameRate, but when I shoot it background colors change too fast and I don’t want that. Can someone help me solve this problem? Thank you.

import processing.sound.*;

SoundFile sample;
Waveform waveform;

int samples = 100;
float r;
float g;
float b;

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

sample = new SoundFile(this, "Maroon 5 - Nobody's Love.wav");
  waveform = new Waveform(this, samples);


void draw() {
 r = random(255);
 g = random(255);
 b = random(255);
 background(r, g, b);


  for(int i = 0; i < samples; i++){
    // Draw current data of the waveform
    // Each sample in the data array is between -1 and +1 
      map(i, 0, samples, 0, width),
      map(waveform.data[i], -1, 1, 0, height)


Use the default frameRate.

Here is an example of a simple timer based on frameCount:

void setup() 

void draw() 
  if(frameCount%60 == 0)

You will have to look up the references to understand what this is doing.
% is the modulo operator.

println() is a useful function!


compare the speed with. aiff file and , wav file



is the default frameRate is the fastest ?? and how much is it ?


Read this and all the related references:

A good read:

And states:

However, if your FPS is higher than your refresh rate, your display will not be able to display all of the frames your computer is producing, so although the refresh rate doesn’t technically limit the frame rate, it does effectively set a cap.

You will have to read the article for context.


1 Like