Capturing sound from wine

Questions about Wine on Linux
Locked
dh79
Newbie
Newbie
Posts: 3
Joined: Thu Jul 19, 2012 5:23 pm

Capturing sound from wine

Post by dh79 »

hey,

I have written a small Java application for testing purposes that captures sound from a mixer on ubuntu 12.04.

The code works fine, I can capture sound from all applications except for anything running under Wine. Whenever I start my program after having started wine, the call to targetDataLine.read() will block forever. When wine is not running in the background it correctly outputs 0 if there is no input, or the number of bytes read if there is input, as expected. If I start my program before starting wine, the sound driver will not be available within wine.

I have tried using both the mixers provided by alsa as well as the default device, same result. Ok, I could imagine that wine somehow locks alsa (for whatever reason), but why would a simple call to TargetDataLine.read() cause sound to fail in wine? mixerInfo[0] is default on my system btw, and the application is of course always running outside of wine using oracle's latest jre (7).

Code: Select all

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){           
        cnt = targetDataLine.read(tempBuffer,0,tempBuffer.length);
        System.out.println("read "+cnt+");                    
        targetDataLine.flush();
   }

}
I've already posted this at stackoverflow, but since nobody seems to have an idea I thought maybe here someone could tell me what's going on.
User avatar
dimesio
Moderator
Moderator
Posts: 13367
Joined: Tue Mar 25, 2008 10:30 pm

Re: Capturing sound from wine

Post by dimesio »

dh79 wrote: I have written a small Java application for testing purposes that captures sound from a mixer on ubuntu 12.04.
What version of Wine, and are you using the Ubuntu packages or did you compile Wine yourself?
User avatar
DanKegel
Moderator
Moderator
Posts: 1164
Joined: Wed May 14, 2008 11:44 am

Post by DanKegel »

FWIW, I record the output of wine routinely with

MONITOR=$(pactl list | grep -A2 '^Source #' | grep 'Name: .*\.monitor$' | awk '{print $NF}' | tail -n1)
parec --device="$MONITOR" --verbose $NAME.pcm

on Ubuntu 11.04 and 12.04.
J V
Level 3
Level 3
Posts: 83
Joined: Wed Mar 07, 2012 6:57 pm

Post by J V »

On pulseaudio I just use avconv (Which is built in)

Code: Select all

avconv -f alsa -i pulse -acodec libmp3lame out.mp3
Easy peasy
dh79
Newbie
Newbie
Posts: 3
Joined: Thu Jul 19, 2012 5:23 pm

Post by dh79 »

I'm using version 1.4 from the current Ubuntu package.

Unfortunately I need to do some calculations on the captured stream and low latency is important, so recording is not an option for me.
dh79
Newbie
Newbie
Posts: 3
Joined: Thu Jul 19, 2012 5:23 pm

Post by dh79 »

I just installed version 1.4.1 (latest stable package) from the winehq repository, just to be sure. Same result, the call to TargetDataLine.read() makes sound unavailable to all applications running in wine. In the sound options menu of World of Warcraft for example, all installed sound drivers are displayed correctly. If I start my program before launching WoW, it just shows "default" and "nvidia ((null))". If I launch WoW first, I can't access the mixer from java.
Locked