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

Support for Processing 4 (getLineIn doesn't work) #119

Closed kawaiiDango closed 2 years ago

kawaiiDango commented 2 years ago

I have the following code:

Mixer.Info[] mixerInfo = AudioSystem.getMixerInfo();
  for (int i = 0; i < mixerInfo.length; i++) {
    //automatically choose stereo mix
    println(mixerInfo[i].getName());
    if (mixerInfo[i].getName().indexOf("Stereo Mix")>-1) {
      Mixer mixer = AudioSystem.getMixer(mixerInfo[i]);
      minim.setInputMixer(mixer);
      break;
    }
  } 

  minim.debugOn();
  in = minim.getLineIn(Minim.STEREO, 1024, 48000);

Works with Processing 3 but I get the following on Processing 4:

Port Speakers (Realtek High Definiti
Port Microphone (Realtek High Defini
Port Stereo Mix (Realtek High Defini

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

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

Processing 4 changelog states: "There have been many updates for the Video and Sound libraries as we chase Apple's ever-changing guidelines for what constitutes “safe” software."

Using minim 2.2.2 on Windows 11

ddf commented 2 years ago

Since the error is coming out of JavaSound this may have something to do with the version of Java bundled with Processing 4 (if you are using that version of Processing). A couple things it might be: the Port Stereo Mix doesn't actually support the 48000 sample rate you are requesting because of how it is configured or the mixers are enumerating in a different order on Processing 4 and the first one with "Stereo Mix" in the name doesn't work. Beyond that, I'm not really sure.

kawaiiDango commented 2 years ago

Processing 4 comes with Java 11, so its most probably that. The sound settings dialog does show 2 channel, 16 bit, 48000Hz and I tried manually indexing the stereo mix and the microphone and they didn't work. There are only 3 devices enumerated in my system: speakers, mic and stereo mix.

ddf commented 2 years ago

Damn, that's frustrating. If you don't explicitly set the input mixer does getLineIn work? I'd assume you'd wind up with the microphone input.

kawaiiDango commented 2 years ago

the mixers are enumerating in a different order on Processing 4 and the first one with "Stereo Mix" in the name doesn't work.

Sorry for not checking properly. This was the case. There were more devices enumerated, and the ones starting with "Port" didn't work, "Stereo Mix" did. The order has changed in Processing 4, the ones with "Port" are enumerated first.