Minim without Processing

I’ve been asked many times to remove the PApplet dependency from Minim and tonight I have done it. If you’d like to try out Minim in your not-Processing Java app, you can grab the latest from the repo to do so. I’ve put the details in the Javadoc, but I’ll lay out the basics here, as well.

Processing provides two key methods that the JavaSound implementation of Minim uses when dealing with sound files. The sketchPath method is used by createRecorder to generate an absolute path from the file name provided to that method. The createInput method is used to get InputStreams for reading audio files. In order to remove the dependency on PApplet, the Minim constructor that required a PApplet as an argument has been replaced with one that takes an Object. This Object is then passed to the JavaSound implementation, which uses reflection to try to locate sketchPath and createInput methods on that Object.

What it boils down to is that if you are building a not-Processing Java app, you must simply write sketchPath and createInput methods for one of your application classes and then pass an instance of that class to the Minim constructor. The exact method signatures are:

String sketchPath(String fileName);
InputStream createInput(String fileName);

17 thoughts on “Minim without Processing

  1. Do you have a ready to get started example of thisone?

    Thanks in advance, I want to use minim but no processing

  2. Not immediately handy, I’m afraid. As it is, my collaborator suggested that relying on the Processing method names is probably not the best idea, so it is likely we will pick better named methods to look for. I will make a follow up post when that happens and include an example.

  3. A small example or code snippet would be very helpful. i downloaded the libs from the above link, but (for example) minim = new Minim(this) still needs a PApplet, and wont accept no value. would a small guide like the fft be possible for using minim without P5?

  4. Hmm, I will see if I can find some time to post an example. It’s possible that for some reason the jar files in the repo had not been updating to include this feature, you might try again now.

  5. Ive added the methods and so far it seems to kind of work (from the top part of the included log) however when song.play() is called it spurts out this error

    any thoughts?

    path: /1.mp3
    C:\Users\seantest/test.mp3
    C:\Users\seantest/test.mp3
    ==== JavaSound Minim Error ====
    ==== Don’t know the ID3 code TLAN

    Exception in thread “Thread-2″ java.lang.NoSuchMethodError: javazoom.jl.decoder.LayerIIIDecoder.(Ljavazoom/jl/decoder/Bitstream;Ljavazoom/jl/decoder/Header;Ljavazoom/jl/decoder/SynthesisFilter;Ljavazoom/jl/decoder/SynthesisFilter;Ljavazoom/jl/decoder/Obuffer;I)V
    at javazoom.jl.decoder.Decoder.retrieveDecoder(Unknown Source)
    at javazoom.jl.decoder.Decoder.decodeFrame(Unknown Source)
    at javazoom.spi.mpeg.sampled.convert.DecodedMpegAudioInputStream.execute(Unknown Source)
    at org.tritonus.share.TCircularBuffer.read(TCircularBuffer.java:134)
    at org.tritonus.share.sampled.convert.TAsynchronousFilteredAudioInputStream.read(TAsynchronousFilteredAudioInputStream.java:189)
    at ddf.minim.javasound.JSBaseAudioRecordingStream.readBytes(Unknown Source)
    at ddf.minim.javasound.JSBaseAudioRecordingStream.mRead(Unknown Source)
    at ddf.minim.javasound.JSBaseAudioRecordingStream.read(Unknown Source)
    at ddf.minim.javasound.JSAudioOutput.readStream(Unknown Source)
    at ddf.minim.javasound.JSAudioOutput.run(Unknown Source)

  6. just for reference these are the methods

    it seems sketchPath never gets called?

    the track is loaded because i can get its length, samplerate etc, but the other libraries cant find the file? when play() is called

    public String sketchPath(String fileName) {
    System.out.println(“SketchPath: ” + Gdx.files.getExternalStoragePath() + fileName);
    return fileName;
    }

    public InputStream createInput(String fileName) {
    InputStream in2;
    try {
    in2 = new FileInputStream(fileName);
    System.out.println(“InputStream: created! ” + fileName);
    return in2;
    } catch (Exception ex) {
    System.out.println(“Error Catch Triggered: “+ex);
    in2 = null;
    }
    return in2;
    }
    }

  7. @Greg sketchPath will only be called when Minim needs to create a file on disk, which would only happen if you used an AudioRecorder. As for the exception in your first comment, the NoSuchMethodError makes me think that the mp3 decoding is expecting something to be there that isn’t, but I’m not sure why using it outside of Processing would cause that. Maybe you aren’t linking in some dependency that Processing automatically takes care of. Just a guess. You might try using a WAV file and see if that works.

  8. Excellent, getting a little closer now :) it does indeed work with Wavs, what are your thoughts? I do really need to use mp3s

  9. @Thomas I’m not sure I fully understand the question you are asking.

    @Greg Are you sure you are including all of the Jar files used by Minim in your build path? For playing mp3 files you definitely need jl1.0.jar, mp3spi1.9.4.jar, and tritonus_share.jar, in addition to jsminim.jar and minim.jar.

  10. I dont get it. I tried your codeexamlpe from QuickStartGuide. I dont understand how to implement the two Methods

    String sketchPath(String fileName);
    InputStream createInput(String fileName);

    __________________________________________________
    Please take a look at my Code:

    public class Main {

    Minim minim;
    AudioPlayer player;
    AudioInput input;
    NonProcessing nonproc = new NonProcessing();

    public static void main(String[] args) {
    Main mainclass = new Main();
    mainclass.setup();

    }

    void setup() {
    // size(100, 100)

    minim = new Minim(this);
    player = minim.loadFile(“sounds\\test.mp3″);
    input = minim.getLineIn();
    }

    void draw() {
    // do what you do
    }

    void stop() {
    player.close();
    input.close();
    minim.stop();

    }

    class NonProcessing {

    String sketchPath(String fileName) {
    System.out.println(“sketchPath: ” + fileName);
    return fileName;
    }

    InputStream createInput(String fileName) {
    System.out.println(“createInput: ” + fileName);
    InputStream in2;
    try {
    in2 = new FileInputStream(fileName);
    System.out.println(“InputStream: created! ” + fileName);
    return in2;
    } catch (Exception ex) {
    System.out.println(“Error Catch Triggered: ” + ex);
    in2 = null;
    }
    return in2;
    }
    }
    }

  11. It says:

    ==== JavaSound Minim Error ====
    ==== Couldn’t find a sketchPath method on the file loading object provided!
    ==== File recording will be disabled.

    ==== JavaSound Minim Error ====
    ==== Couldn’t find a createInput method in the file loading object provided!
    ==== File loading will be disabled.

    Exception in thread “main” java.lang.NoSuchMethodError: ddf.minim.spi.MinimServiceProvider.getAudioRecordingStream(Ljava/lang/String;IZ)Lddf/minim/spi/AudioRecordingStream;
    at ddf.minim.Minim.loadFile(Unknown Source)
    at ddf.minim.Minim.loadFile(Unknown Source)
    at Main.setup(Main.java:25)
    at Main.main(Main.java:17)

  12. Ok, I got it.

    And, a friend of mine checkd out, the player only works for specific mp3-files.
    i dont know why anyway.

    maybe u have an idea.
    greetings from germany

  13. Cool, glad you got it working. I’m not really sure why only some mp3 files would work. I didn’t write the mp3 decoding code that Minim uses and I’m unfamiliar with it. If a file doesn’t play, I’d expect there to be some kind of error in the console about why, but maybe not. Just guessing: could have something to do with what bitrate the file was encoded at.

  14. @ddf

    I did include them all, I am using Libgdx to code with as well, so I am aware that using minim (and java sound) WONT work at all on android, I was planning on getting a desktop version working first and then working all that droid stuff out later and changing it as needed

    The mp3s still wont work though, and since java on a desktop does have the java sound api im a little stuck as to why this is

  15. All libs included as shown here: http://i47.tinypic.com/wvcxoh.jpg

    Exception in thread “Thread-3″ java.lang.NoSuchMethodError: javazoom.jl.decoder.LayerIIIDecoder.(Ljavazoom/jl/decoder/Bitstream;Ljavazoom/jl/decoder/Header;Ljavazoom/jl/decoder/SynthesisFilter;Ljavazoom/jl/decoder/SynthesisFilter;Ljavazoom/jl/decoder/Obuffer;I)V
    at javazoom.jl.decoder.Decoder.retrieveDecoder(Unknown Source)
    at javazoom.jl.decoder.Decoder.decodeFrame(Unknown Source)
    at javazoom.spi.mpeg.sampled.convert.DecodedMpegAudioInputStream.execute(Unknown Source)
    at org.tritonus.share.TCircularBuffer.read(TCircularBuffer.java:134)
    at org.tritonus.share.sampled.convert.TAsynchronousFilteredAudioInputStream.read(TAsynchronousFilteredAudioInputStream.java:189)
    at ddf.minim.javasound.JSBaseAudioRecordingStream.readBytes(Unknown Source)
    at ddf.minim.javasound.JSBaseAudioRecordingStream.mRead(Unknown Source)
    at ddf.minim.javasound.JSBaseAudioRecordingStream.read(Unknown Source)
    at ddf.minim.javasound.JSAudioOutput.readStream(Unknown Source)
    at ddf.minim.javasound.JSAudioOutput.run(Unknown Source)

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">