Capturing Sound from Wine with TargetDataLine

I wrote a small Java test application that captures sound from a mixer on ubuntu 12.04.

The code works fine, I can record sound from all applications except everything that works under Wine.

Whenever I run my program, after starting Wine, the call to targetDataLine.read() will be blocked forever

When Wine does not work in the background, it correctly displays 0 when there is no input, or the number of bytes read if there is input, as expected.

If I run my program before starting Wine, the sound driver will not be available in the fault.

I tried using both mixers provided by Alsa, as well as the default device, the same result.

I could imagine that wine somehow blocks Alsou (for some reason), but why does a simple call to targetDataLine.read() make the sound fail in Wine? mixerInfo[0] is used by default on my btw system, and the application, of course, always runs outside of Wine using the latest version of JRE (7).

 private void readSound () { byte tempBuffer[] = new byte[10000]; int cnt = 0; Mixer.Info[] mixerInfo = AudioSystem.getMixerInfo(); System.out.println("Available mixers:"); for (int p = 0; p < mixerInfo.length; p++) System.out.println(mixerInfo[p].getName()); format = getAudioFormat(); DataLine.Info dataLineInfo = new DataLine.Info(TargetDataLine.class, format); Mixer mixer = AudioSystem.getMixer(mixerInfo[0]); try { targetDataLine = (TargetDataLine) mixer.getLine(dataLineInfo); targetDataLine.open(format); } catch(Exception e) { e.printStackTrace(); } targetDataLine.start(); while (true) { i++; cnt = targetDataLine.read(tempBuffer, 0, tempBuffer.length); System.out.println("read " + cnt + " bytes:" + tempBuffer[i]); calculateLevel(tempBuffer, 0, 200); targetDataLine.flush(); System.out.println(level); } } 
+48
java linux audio alsa wine
Jul 18 '12 at 21:26
source share
1 answer

Use the AudioSystem.write () method. It is much easier.

 targetDataLine.open(format); targetDataLine.start(); AudioInputStream ais=new AudioInputStream(targetDataLine); AudioFileFormat.Type fileformat=AudioFileFormat.Type.WAVE; /* Other Audio file formats supported: AudioFileFormat.Type.AU AudioFileFormat.Type.AIFF AudioFileFormat.Type.AIFC AudioFileFormat.Type.SND */ File audoutputfile=new File('myfile'); //adjust extension according to AudioFileFormat AudioSystem.write(ais,fileformat, audoutputfile); 
+1
Oct 17 '16 at 16:20
source share
— -



All Articles