Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ArrayIndexOutOfBoundsException: 3 when trying to load (mp3) sound file #14

Closed
MOQN opened this issue Oct 23, 2018 · 10 comments
Closed

ArrayIndexOutOfBoundsException: 3 when trying to load (mp3) sound file #14

MOQN opened this issue Oct 23, 2018 · 10 comments
Labels
bug Something isn't working help wanted Extra attention is needed

Comments

@MOQN
Copy link

MOQN commented Oct 23, 2018

Hello, after recent updates (maybe Processing, Java or the library itself), my students and I cannot load a certain sound file which we were able to load for 2 years. Can you please take a look at the issue?

The sound file is attached
Both versions of Processing and Sound library are latest. (v3.4, v2.0.2)
I also found some relevant thread here.


Error Message below:

ArrayIndexOutOfBoundsException: 3

Oct 24, 2018 4:33:03 AM com.jsyn.engine.SynthesisEngine start
INFO: Pure Java JSyn from www.softsynth.com, rate = 44100, RT, V16.8.0 (build 463, 2017-10-16)

sound.wav.zip

@tongdaxu
Copy link

tongdaxu commented Nov 1, 2018

Same issue noticed, windows 10, Processing 3.4 and latest Sound lib.

Raise:
ArrayIndexOutOfBoundsException: 3
When:
Attempting to load a mp3 audio file in by
happyTTS = new SoundFile(this, "Happy_TTS.mp3");

@AST-esp-rasp
Copy link

I'm having the same issue
ArrayIndexOutOfBoundsException: 3
When:
Attempting to load a mp3 audio file in by
happyTTS = new SoundFile(this, "3 Beep.mp3");

@kevinstadler kevinstadler changed the title Can't load sound files, except for the .aiff files given from the example. ArrayIndexOutOfBoundsException: 3 when trying to load (mp3) sound file Nov 14, 2018
@kevinstadler kevinstadler added bug Something isn't working help wanted Extra attention is needed labels Nov 14, 2018
@sgolanka
Copy link

Same--on both Windows and Macs (ArrayIndexOutOfBoundsException).

file = new SoundFile(this, "Kalimba.mp3");

@showyourmindlab
Copy link

Having the same issue on my 2018 macbook pro with Processing 3.4 and Sound 2.02.

@dinarname
Copy link

Hi!
I encountered the same problem. First there was a message about the array, then about the fact that the file could not be decoded.

I fixed this through the conversion of my files(.mp3 and .wav) into an .aiff format.

@jlinseman
Copy link

jlinseman commented Dec 20, 2018

Fixed

I had the same issue and tried everything I could find in these forums. Newest update did nothing.

Once I changed the files to .wav format the file worked. I still see red warnings but the game doesn't give the arrayIndexOutOfBounds error anymore.
I used Audacity to convert.

Red warning code that appears still is this (with or without .mp3 files)

Dec 20, 2018 3:37:34 PM com.jsyn.devices.javasound.JavaSoundAudioDevice <init>
INFO: JSyn: default output latency set to 80 msec for Windows 10
Dec 20, 2018 3:37:34 PM com.jsyn.engine.SynthesisEngine start
INFO: Pure Java JSyn from www.softsynth.com, rate = 44100, RT, V16.8.0 (build 463, 2017-10-16)

But I no longer get this after it.

Error: ArrayIndexOutOfBoundsExeption : 16
Could not run the sketch (Target VM failed to initialize).
For more information, read revisions.txt and Help ? Troubleshooting.

@TotallyJuice
Copy link

I had the same problem. I started with original .wav files from my music creation software and converted them into .mp3 files using an online converter. (to try and save on file size) The converted .mp3 files would not load into by program. I tried my first .wav files and they worked. So I am guessing that some converters will generate .mp3 files that the sound library cannot handle.

@cluder
Copy link
Contributor

cluder commented Mar 14, 2019

I also got the exception on some mp3 files:
`java.lang.ArrayIndexOutOfBoundsException: 3
at fr.delthas.javamp3.Decoder.decodeFrame(Decoder.java:474)
at fr.delthas.javamp3.Decoder.init(Decoder.java:431)
at fr.delthas.javamp3.Sound.(Sound.java:49)
at processing.sound.SoundFile.(Unknown Source)

A VBR file fails to load: (info according to winamp)
MPEG-1 Layer 3, 84 Kbps (VBR), 14 Frames, 48000 Hz Joint Stereo

The exception happens when trying to determine the frequency.
The samplingFrequency = 3 is decoded in the JavaMP3 library:
https://github.com/delthas/JavaMP3/blob/master/src/main/java/fr/delthas/javamp3/Decoder.java#L466

The SAMPLING_FREQUENCY array contains 3 elements: int[] SAMPLING_FREQUENCY = {44100, 48000, 32000}
Index [1] would be 48'000, but somehow it wants to access index [3] which is out of bounds.

The frequency is read from two bits: 0 0 = 44khz, 0 1 = 48 khz, 1 0 = 32 khz, 1 1 = ?
see http://id3lib.sourceforge.net/id3/mp3frame.html
image

I am currently trying to reproduce the problem directly in JavaMP3.

@cluder
Copy link
Contributor

cluder commented Mar 14, 2019

The problem seems to be in the processing.sound.SoundFile class.

  1. an InputStream is created
  2. it is tried to load the file as a WAV or AIF, which reads the 1st byte of the stream.
  3. as this fails, it is tried to load the InputStream as a mp3, but this stream is not at the beginning anymore, since we already read 4 bytes.

https://github.com/processing/processing-sound/blob/master/src/processing/sound/SoundFile.java#L59
The InputStream fin is already at position 4, when it is passed to the Sound constructor, which then leads to the wrong decoding.
Sound mp3 = new Sound(fin);

Maybe the InputStream should be created freshly, before trying to parse as mp3.

    try {
        // load WAV or AIF using JSyn
        this.sample = SampleLoader.loadFloatSample(fin); // <-- 'fin' will be modified after this call (4 bytes are read)
    } catch (IOException e) {
        // try parsing as mp3
        try {
            // re-create the input stream before creating the mp3
            fin = parent.createInput(path);
            Sound mp3 = new Sound(fin);

Mp3 file to reproduce the problem: https://github.com/cluder/processing-examples/blob/master/resources/beep1.mp3

@sjernigan
Copy link

I had the same problem when trying to load mono mp3s. Changed them to stereo and they worked.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests