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

**URL:** <https://discourse.processing.org/t/what-is-the-code-for-my-wave-to-move-at-the-same-time-as-the-song/29728>\
**Category:** Libraries\
**Tags:** homework\
**Created:** [April 29, 2021, 2:02pm UTC](https://discourse.processing.org/t/what-is-the-code-for-my-wave-to-move-at-the-same-time-as-the-song/29728 "2021-04-29T14:02:03Z")\
**Posts on this page:** 16\
**Page:** 1

<div class="post-metadata">

**Author:** ![Marga](https://avatars.discourse-cdn.com/v4/letter/m/a3d4f5/32.png) [@Marga](https://discourse.processing.org/u/Marga)\
**Post date:** [April 29, 2021, 2:02pm UTC](https://discourse.processing.org/t/what-is-the-code-for-my-wave-to-move-at-the-same-time-as-the-song/29728/1 "2021-04-29T14:02:03Z")

</div>

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:

```auto
import ddf.minim.*;

Minim minim;
AudioPlayer song;

void setup(){
size(1000, 1000);
background(#357BC4);

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

}

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

}

```

Thank you!

---

<div class="post-metadata">

**Author:** ![ReyzArtz](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/reyzartz/32/11750_2.png) [@ReyzArtz](https://discourse.processing.org/u/ReyzArtz)\
**Post date:** [April 29, 2021, 2:28pm UTC](https://discourse.processing.org/t/what-is-the-code-for-my-wave-to-move-at-the-same-time-as-the-song/29728/2 "2021-04-29T14:28:51Z")

</div>

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

[![](https://img.youtube.com/vi/jEwAMgcCgOA/hqdefault.jpg "17.9: Sound Visualization: Graphing Amplitude - p5.js Sound Tutorial") ](https://www.youtube.com/watch?v=jEwAMgcCgOA)

---

<div class="post-metadata">

**Author:** ![glv](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/glv/32/18785_2.png) [@glv](https://discourse.processing.org/u/glv)\
**Post date:** [April 29, 2021, 3:29pm UTC](https://discourse.processing.org/t/what-is-the-code-for-my-wave-to-move-at-the-same-time-as-the-song/29728/3 "2021-04-29T15:29:52Z")

</div>

The sound libraries have examples that come with them.

Processing sound library:

- [https://processing.org/tutorial/](https://processing.org/tutorial/) There is one for Sound

- [Sound \ Libraries \ Processing.org](https://processing.org/reference/libraries/sound/)

- From the Processing PDE in the file menu:

The Minim library also has resources and examples.

`:)`

---

<div class="post-metadata">

**Author:** ![Marga](https://avatars.discourse-cdn.com/v4/letter/m/a3d4f5/32.png) [@Marga](https://discourse.processing.org/u/Marga)\
**Post date:** [April 30, 2021, 10:06am UTC](https://discourse.processing.org/t/what-is-the-code-for-my-wave-to-move-at-the-same-time-as-the-song/29728/4 "2021-04-30T10:06:23Z")

</div>

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

```auto

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");
  sample.loop();

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

public void draw() {

  background(125, 255, 125);
  noStroke();
  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

---

<div class="post-metadata">

**Author:** ![jafal](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jafal/32/19112_2.png) [@jafal](https://discourse.processing.org/u/jafal)\
**Post date:** [April 30, 2021, 10:31am UTC](https://discourse.processing.org/t/what-is-the-code-for-my-wave-to-move-at-the-same-time-as-the-song/29728/5 "2021-04-30T10:31:24Z")

</div>

> [@Marga](#):
>
> 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 ?

---

<div class="post-metadata">

**Author:** ![jafal](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jafal/32/19112_2.png) [@jafal](https://discourse.processing.org/u/jafal)\
**Post date:** [April 30, 2021, 11:01am UTC](https://discourse.processing.org/t/what-is-the-code-for-my-wave-to-move-at-the-same-time-as-the-song/29728/6 "2021-04-30T11:01:19Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Marga](https://avatars.discourse-cdn.com/v4/letter/m/a3d4f5/32.png) [@Marga](https://discourse.processing.org/u/Marga)\
**Post date:** [April 30, 2021, 11:04am UTC](https://discourse.processing.org/t/what-is-the-code-for-my-wave-to-move-at-the-same-time-as-the-song/29728/7 "2021-04-30T11:04:48Z")

</div>

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  
NullPointerException  
NullPointerException  
NullPointerException  
NullPointerException  
Could not run the sketch (Target VM failed to initialize).  
For more information, read revisions.txt and Help ? Troubleshooting.

---

<div class="post-metadata">

**Author:** ![jafal](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jafal/32/19112_2.png) [@jafal](https://discourse.processing.org/u/jafal)\
**Post date:** [April 30, 2021, 11:06am UTC](https://discourse.processing.org/t/what-is-the-code-for-my-wave-to-move-at-the-same-time-as-the-song/29728/8 "2021-04-30T11:06:32Z")

</div>

> [@Marga](#):
>
> 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  
> NullPointerException

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

---

<div class="post-metadata">

**Author:** ![Marga](https://avatars.discourse-cdn.com/v4/letter/m/a3d4f5/32.png) [@Marga](https://discourse.processing.org/u/Marga)\
**Post date:** [April 30, 2021, 11:10am UTC](https://discourse.processing.org/t/what-is-the-code-for-my-wave-to-move-at-the-same-time-as-the-song/29728/9 "2021-04-30T11:10:18Z")

</div>

I already did it but, it didn’t work

---

<div class="post-metadata">

**Author:** ![jafal](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jafal/32/19112_2.png) [@jafal](https://discourse.processing.org/u/jafal)\
**Post date:** [April 30, 2021, 11:18am UTC](https://discourse.processing.org/t/what-is-the-code-for-my-wave-to-move-at-the-same-time-as-the-song/29728/10 "2021-04-30T11:18:09Z")

</div>

chick spelling and UPPER or lower case is important

---

<div class="post-metadata">

**Author:** ![jafal](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jafal/32/19112_2.png) [@jafal](https://discourse.processing.org/u/jafal)\
**Post date:** [April 30, 2021, 11:18am UTC](https://discourse.processing.org/t/what-is-the-code-for-my-wave-to-move-at-the-same-time-as-the-song/29728/11 "2021-04-30T11:18:46Z")

</div>

> **[Using sound in Processing](https://www.futurelearn.com/info/courses/creative-coding/0/steps/400)**
>
> A simple sketch that uses sound and image together

---

<div class="post-metadata">

**Author:** ![Marga](https://avatars.discourse-cdn.com/v4/letter/m/a3d4f5/32.png) [@Marga](https://discourse.processing.org/u/Marga)\
**Post date:** [May 1, 2021, 6:45pm UTC](https://discourse.processing.org/t/what-is-the-code-for-my-wave-to-move-at-the-same-time-as-the-song/29728/12 "2021-05-01T18:45:09Z")

</div>

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.

```auto
import processing.sound.*;

SoundFile sample;
Waveform waveform;

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

void setup(){
size(640, 360);
background(255);
frameRate(1);

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

}

void draw() {
 r = random(255);
 g = random(255);
 b = random(255);
 background(r, g, b);
  stroke(255);
  strokeWeight(5);
  noFill();
 

 
waveform.analyze(); 

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

```

---

<div class="post-metadata">

**Author:** ![glv](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/glv/32/18785_2.png) [@glv](https://discourse.processing.org/u/glv)\
**Post date:** [May 1, 2021, 7:03pm UTC](https://discourse.processing.org/t/what-is-the-code-for-my-wave-to-move-at-the-same-time-as-the-song/29728/13 "2021-05-01T19:03:31Z")

</div>

Hello,

Use the default frameRate.

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

```auto
void setup() 
  {
  println(frameRate);  
  }

void draw() 
  {
  if(frameCount%60 == 0)
    {
    println(frameCount/60); 
    }
  }

```

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

println() is a useful function!

`:)`

---

<div class="post-metadata">

**Author:** ![jafal](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jafal/32/19112_2.png) [@jafal](https://discourse.processing.org/u/jafal)\
**Post date:** [May 1, 2021, 7:14pm UTC](https://discourse.processing.org/t/what-is-the-code-for-my-wave-to-move-at-the-same-time-as-the-song/29728/14 "2021-05-01T19:14:57Z")

</div>

compare the speed with. aiff file and , wav file

---

<div class="post-metadata">

**Author:** ![jafal](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jafal/32/19112_2.png) [@jafal](https://discourse.processing.org/u/jafal)\
**Post date:** [May 1, 2021, 7:17pm UTC](https://discourse.processing.org/t/what-is-the-code-for-my-wave-to-move-at-the-same-time-as-the-song/29728/15 "2021-05-01T19:17:27Z")

</div>

hi

> [@glv](#):
>
> Use the default frameRate.

hi

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

---

<div class="post-metadata">

**Author:** ![glv](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/glv/32/18785_2.png) [@glv](https://discourse.processing.org/u/glv)\
**Post date:** [May 1, 2021, 9:11pm UTC](https://discourse.processing.org/t/what-is-the-code-for-my-wave-to-move-at-the-same-time-as-the-song/29728/16 "2021-05-01T21:11:22Z")

</div>

Hello,

Read this and all the related references:

- [frameRate() / Reference / Processing.org](https://processing.org/reference/frameRate_.html)

A good read:

> **[Frame Rate (FPS) vs Refresh Rate (Hz)](https://www.avadirect.com/blog/frame-rate-fps-vs-hz-refresh-rate/)**
>
> When comparing the performance of two custom gaming PCs, we often look at the frame rates each computer is capable of producing in a certain game at the same resolution and graphics quality. Frame rates are measured in FPS or Frames per Second. Most...

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.

`:)`
