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
668 stars 136 forks source link

getLineIn() not working on Big Sur with Processing 3 and Minim 2.2.2 #114

Open paulcanning opened 3 years ago

paulcanning commented 3 years ago

As per the title.

Installed Processing 3 and Minim 2.2.2, and tried the following code

import ddf.minim.*;
import ddf.minim.analysis.*;
import ddf.minim.effects.*;
import ddf.minim.signals.*;
import ddf.minim.spi.*;
import ddf.minim.ugens.*;

Minim minim;
AudioInput in;

void setup() {
  minim = new Minim(this);
  in = minim.getLineIn();
  in.enableMonitoring();
}

void draw() {
  for(int i = 0; i < in.bufferSize() - 1; i++)
  {
    line( i, 50 + in.left.get(i)*50, i+1, 50 + in.left.get(i+1)*50 );
    line( i, 150 + in.right.get(i)*50, i+1, 150 + in.right.get(i+1)*50 );
  }
}

And nothing happens.

ddf commented 3 years ago

Most likely related to something changing in Big Sur's handling of audio things, might require a Java update, not sure. I can't test Big Sur on my ancient Macbook unfortunately. You could try adding a minim.debugOn() before calling getLineIn() and see what's reported in the console.

ddf commented 3 years ago

Would also recommend searching the Processing forum to see if other folks have had trouble with audio on Big Sur and if they were able to fix it.

paulcanning commented 3 years ago

The debug line gave me:

==== JavaSound Minim Debug ====
==== TargetDataLine buffer size is 16384
==== TargetDataLine format is PCM_SIGNED 44100.0 Hz, 16 bit, stereo, 4 bytes/frame, little-endian
==== TargetDataLine info is interface TargetDataLine supporting 14 audio formats, and buffers of at least 32 bytes

=== Minim Debug ===
=== byteBufferSize is 4096

==== JavaSound Minim Debug ====
==== SourceDataLine is class com.sun.media.sound.DirectAudioDevice$DirectSDL
==== Buffer size is 16384 bytes.
==== Format is PCM_SIGNED 44100.0 Hz, 16 bit, stereo, 4 bytes/frame, little-endian.

=== Minim Debug ===
=== Likely buffer underrun in AudioOutput.
ddf commented 3 years ago

Well, that looks like it's successfully getting an input, but it may not be the one you are expecting. I'd recommend running the setInputMixer example in the Advanced folder of the Minim examples and see what you get onscreen for buttons. You can click on a button to attempt to open that input.

paulcanning commented 3 years ago

I did as you asked with the example, and got this message when clicking the button for the onboard mic:

==== 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.
ddf commented 3 years ago

Ok, so it could be that the onboard mic doesn't support the default format. I'd recommend checking your system settings to see how audio for the mic is configured (ie sample rate, bit-depth) and then modify setInputMIxer to use the version of getLineIn that takes format arguments and provide those values. For example minim.getLineIn(Minim.MONO, 1024, 48000, 24) would try to acquire a mono input with a buffer size of 1024 that has a sample rate of 48kHz and a bit-depth of 24.

justincouch commented 2 years ago

I was getting this same error and was able to correct it with the arguments @ddf mentioned above with a slight modification. The built in Macbook Pro microphone is mono, but only works with a bit depth of 8 or 16. in = minim.getLineIn(Minim.MONO, 1024, 44100, 16); worked for me. With the caveat that I just upgraded to Processing 4 because of P3D issues. So my setup is: MacBook Pro (16-inch, 2019) MacOS Monterey Processing 4.0b5