Sound library error

Hi there!

i have a problem in import sound to a code I wrote.

i know there a lot of topics around the network on this issue but non of them helped me.

some notes:

  1. mac.
  2. processing, latest edition.
  3. download processing sound library and Minim.
  4. import my sound to every file possible in processing libraries.

this is the code:

PImage img;
import processing.sound.*;
SoundFile file;

float xpos, ypos;      

float xspeed = 2.8; 
float yspeed = 2.2;  

int xdirection = 1;  
int ydirection = 1;  

float x;
float y;


void setup() 
{
  size(640, 360);
  noStroke();
  xpos = width/2;
  ypos = height/2;
  img = loadImage("fly.png");

  file = new SoundFile(this, "flysound.mp3");
  file.play();
}

void draw() 
{
  background(225, 234, 237);
  textSize(16);
  fill (0);
  textAlign(CENTER);
  text("catch the fly inside the jar", width/2, 40);

  fill(255, 255, 255);
  stroke(203, 207, 209);
  rect(mouseX, mouseY, 70, 85, 20);
  ellipse(mouseX+35, mouseY+80, 60, 5);
  stroke(10);
  stroke(61, 61, 61);
  ellipse(mouseX+35, mouseY, 70, 10);

  xpos = xpos + ( xspeed * xdirection );
  ypos = ypos + ( yspeed * ydirection );

  if (xpos > width || xpos < 0) {
    xdirection *= -1;
  }
  if (ypos > height || ypos < 0) {
    ydirection *= -1;
  }

  imageMode(CENTER);
  image(img, xpos, ypos, width/20, height/14);
}```

Thank you!

this is the ERROR message.

In order for your sketch to read a sound file (or practically any file, for that matter), the folder that contains your sketch should also contain a folder within itself called “data”, and the sound file (or, again, any file you wish to read) must be within the “data” folder.

If you haven’t done so, I strongly suggest you do that. If there isn’t already a folder in there called “data”, just make one.

Trust me, I made the exact same mistake when I started using the sound library. :slight_smile: (Of course, if you did put it in the data folder, and something else is the source of the problem, then I apologize for the assumption).

HI,

I already have done that… :frowning:

and you’re 100% sure the file’s name is “flysound.mp3” ? Remember, it is case sensitive. Capitals can’t be replaced with lowercase or vise versa.

yes, 100%.

‫בתאריך שבת, 14 בנוב׳ 2020 ב-22:53 מאת ‪Chris via Processing Foundation‬‏ <‪processingfoundation1@discoursemail.com‬‏>:‬

Well, that eliminates the easy possibilities. I decided to copy over your code, and create my own version of the same files. I had the same problem.

I’ll try to isolate the issue by commenting out lines of code, and compare the syntax and order of execution to that of other programs where I got the sound library to work.

Alright. Waiting patiently :slight_smile:

בתאריך שבת, 14 בנוב׳ 2020 ב-23:14 מאת Chris via Processing Foundation <processingfoundation1@discoursemail.com>:

Update: Okay, I’ll admit, I made a bit of a mistake when testing this out. I decided to test it on an .m4a file, thinking it’ll produce the same results. But, as it says in the processing.sound library, particularly on how to use the SoundFile class:

This is a Soundfile Player which allows to play back and manipulate soundfiles. Supported formats are: WAV, AIF/AIFF, MP3. MP3 decoding can be very slow on ARM processors (Android/Raspberry Pi), we generally recommend you use lossless WAV or AIF files.

So, then I tried using one of my .wav files. The program worked, no errors. I thought this was weird, so I decided to convert it to an MP3 file, and see if it produces the same results. The reference page says mp3s are slow on processing.sound, but they should still work regardless. However, once I had it use an .mp3 file, I got an error. Oddly enough, one completely different from the one you got. It said “IndexOutOfBoundsException”. Which is so weird, that’s reserved for array index exceptions. I thought “okay, I just moved the file to the data folder, maybe it just hasn’t registered the change yet”. So I restarted processing, and lo and behold…nothing happened. It still said “IndexOutOfBoundsException”.

So, moral of the story…I think you might be able to fix this by converting to a wav file? I mean, it would technically be a fix, processing even recommends you use that or aif files. With that said, this is by no means a solution (and should definitely not be marked as a solution). As the reference page says, it should still work on mp3s, so why this doesn’t work for mp3 files but it does work on wav files is still a mystery.

Okay, I might’ve figured this out.

On the “README.md” file for “processing-sound-master” (the version of processing sound I downloaded) it lists 2 known bugs for using MP3 files, one saying it loads extremely slowly on ARM processors (which was already mentioned in the reference page). The other error says

Some MP3 files with meta-information (especially where large amounts of data such as the album cover image is stored in the ID3 header) fail to load (see [#32](/…/…/issues/32))

While I might be wrong, I believe this means that any MP3 file with any amount of meta information (which, again, I might be wrong, I’m pretty sure all readable files have meta information) is not guaranteed to be loadable. I don’t know if you’re using the same version of this library that I am, but if so, that could be the source of the issue. Quite a few online sources back me up here, saying that somewhere between Processing 2.0 and Processing 3.0, people became unable to use MP3 files. There appear to be a few other versions which do support MP3 files, but they don’t seem to be official releases, just fan made mods.

In any case, I do still recommend you use WAV or AIV files. There are plenty of free online
format converters, and the compression seems to be minimal on most of them. Hope this helps!