Skip to content

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

Closed

Description

@MOQN

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

Activity

  1. tongdaxu commented on Nov 1, 2018

    @tongdaxu

    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");

  2. AST-esp-rasp commented on Nov 9, 2018

    @AST-esp-rasp

    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");

  3. 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[/+] on Nov 14, 2018
  4. added
    bug
    help wanted
    on Nov 14, 2018
  5. sgolanka commented on Nov 27, 2018

    @sgolanka

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

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

  6. showyourmindlab commented on Dec 3, 2018

    @showyourmindlab

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

  7. dinarname commented on Dec 5, 2018

    @dinarname

    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.

  8. jlinseman commented on Dec 20, 2018

    @jlinseman

    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.
    
  9. TotallyJuice commented on Feb 27, 2019

    @TotallyJuice

    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.

  10. cluder commented on Mar 14, 2019

    @cluder
    Contributor

    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.

  11. cluder commented on Mar 14, 2019

    @cluder
    Contributor

    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

  12. sjernigan commented on Jun 4, 2022

    @sjernigan

    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bughelp wanted

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions