ddf / Minim

A Java audio library, designed to be used with Processing.
http://code.compartmental.net/tools/minim
GNU Lesser General Public License v3.0
671 stars 137 forks source link

AudioStream cant be safely created. #75

Closed 0fca closed 5 years ago

0fca commented 6 years ago

AudioStream causes Minim#getLineIn() to fail so it returns: Minim.getLineIn: attempt failed, could not secure an AudioInput. I'm not sure if it is not caused by the lack of sun. packages, but it was met some time ago(in 2015 when sun. pacakges where accessible) and solved by replacing AudioInput with AudioPlayer, however in case of mine where I need just to get system's sound stdin I can't replace it. OS: Mint 18.1/ openSUSE 42.3. both: x64 Using with Processing 3.3.7. Earlier met under: 2.2.1 as it is stated here. Java ver used: 1.8.x where x is >130, so I mean that I noticed this error to occur under b130/131. Now I'm using 1.8.161. Greetings.

cheungbe commented 6 years ago

Did you ever figure out how to resolve this? I'm running into the exact same issue and have tried every suggestion I've found online.

cheungbe commented 6 years ago

Resolved by setting the LineIn format to MONO (getLineIn(Minim.MONO))

hamoid commented 5 years ago

I have a similar error with Idea and openJDK 10: AudioPlayer works fine, but AudioInput gives me a

==== JavaSound Minim Error ====
==== Error acquiring TargetDataLine: Line unsupported: interface TargetDataLine supporting format PCM_SIGNED 44100.0 Hz, 16 bit, stereo, 4 bytes/frame, little-endian

=== Minim Error ===
=== Minim.getLineIn: attempt failed, could not secure an AudioInput.

What's interesting is that both variations work fine inside Processing, but not in Idea. I tried MONO and STEREO but it made no difference. Could it be because of the JDK version?

hamoid commented 5 years ago

So silly. The issue was that in Processing the right mixerInfo id is 0, but for some reason in IntelliJ it's 2. I guess I should use the name as a String instead of an int somehow.

    private void startAudioInput() {
        minim = new Minim(this);

        var mixerInfo = AudioSystem.getMixerInfo();
        printArray(mixerInfo);

        // In Processing it's 0, but here it's 2!
        // [2] default [default], version 4.18.0-12-generic
        var mixer = AudioSystem.getMixer(mixerInfo[2]);

        minim.setInputMixer(mixer);
        audio = minim.getLineIn();

        fft = new FFT(audio.bufferSize(), audio.sampleRate());
        fft.logAverages(22, 3);
    }

Update. I'll do this instead:

        startAudioInput("default [default]");
    }

    private void startAudioInput(String deviceName) {
        minim = new Minim(this);

        var mixerInfo = AudioSystem.getMixerInfo();
        printArray(mixerInfo);

        for (var info : mixerInfo) {
            if(info.getName().equals(deviceName)) {
                minim.setInputMixer(AudioSystem.getMixer(info));
                audio = minim.getLineIn(Minim.STEREO, 128);

                fft = new FFT(audio.bufferSize(), audio.sampleRate());
                fft.logAverages(22, 3);
                break;
            }
        }
    }
ddf commented 5 years ago

Glad you figured this out. As you discovered, this sort of thing usually boils down to how the version of Java being used presents audio hardware on the computer as mixers. Things can also get weird if you have a multi-channel soundcard.