i-rinat / apulse

PulseAudio emulation for ALSA
MIT License
609 stars 35 forks source link

Need to select device for capture without using dsnoop #14

Open zen2 opened 10 years ago

zen2 commented 10 years ago

Thanks for this project that permit us to get rid of pulseaudio to use Skype.

The only way I get to use apulse with skype is using this .asoundrc:

pcm.duplex {
    type asym
    playback.pcm "dmix"
    capture.pcm "dsnoop"
}
pcm.!default {
    type plug
    slave.pcm "duplex"
}

That works using the Echo/Sound test of skype but that don't work for long in real call: it works for few minutes and suddenly, no sound is hearing anymore by my voice call mate.

The fact that I use a real audio card with hardware mixing so I don't need dsnoop/dmix combo. And last point my default output is hw:0,0 but my microphone capture is on hw:0,1.

How can I tell a pulse to use hw0,0 and hw0,1 as respectively my playback/capture device ?

mtbc commented 10 years ago

Does it help to set the environment variables APULSE_CAPTURE_DEVICE=hw:0,1 APULSE_PLAYBACK_DEVICE=hw:0,0?

zen2 commented 10 years ago

when I use APULSE_CAPTURE_DEVICE=hw:0,1 APULSE_PLAYBACK_DEVICE=hw:0,0 I got the skype login sound then If try the Echo/Sound test, there is no sound anymore and I got this:

$ LC_ALL=C APULSE_CAPTURE_DEVICE=hw:0,1 APULSE_PLAYBACK_DEVICE=hw:0,0 skype [apulse] [error] do_connect_pcm, snd_pcm_hw_params_set_rate, Invalid argument [apulse] [error] do_connect_pcm, snd_pcm_hw_params_set_rate, Invalid argument

i-rinat commented 10 years ago

Try to keep dmix for playback (there can be multiple streams), but select hw:0,1 for capture:

$ APULSE_CAPTURE_DEVICE=hw:0,1 skype
i-rinat commented 10 years ago

snd_pcm_hw_params_set_rate fails if real hardware device can't support requested rate. If one uses dsnoop or dmix, conversion is performed by ALSA, so it kind of works. I can try fix it by using snd_pcm_hw_params_set_rate_near which will select something audio hardware supports. Although it's unlikely the fix will work well, since Skype requests specific rate and expects it, but will get different one.

zen2 commented 10 years ago

I got accurately the same result:

$ LC_ALL=C APULSE_CAPTURE_DEVICE=hw:0,1 skype [apulse] [error] do_connect_pcm, snd_pcm_hw_params_set_rate, Invalid argument [apulse] [error] do_connect_pcm, snd_pcm_hw_params_set_rate, Invalid argument

by the way, i don't need dmix since the sound card have a 32 channels hardware mixing:

$ LC_ALL=C aplay -l | head -3 \ List of PLAYBACK Hardware Devices ** card 0: Audigy2 [SB Audigy 2 ZS [SB0350]], device 0: emu10k1 [ADC Capture/Standard PCM Playback] Subdevices: 32/32

i-rinat commented 10 years ago

since the sound card have a 32 channels hardware mixing:

Subdevices: 32/32

Does that mean you need to specify hw:0,0; hw:0,1; hw:0,2 and so on for different channels to be mixed?

zen2 commented 10 years ago

no that means that hw:0,0 can handle 32 sound streams coming from different applications and mix them at hardware level. dmix does the same thing at software level.

i-rinat commented 10 years ago

First, try to use plughw:0,0 instead of hw:0,0. Then, if it doesn't work, try fix from dev branch: https://github.com/i-rinat/apulse/tree/dev, also with plughw.

zen2 commented 10 years ago

$ LC_ALL=C APULSE_CAPTURE_DEVICE=plughw:0,1 APULSE_PLAYBACK_DEVICE=plughw:0,0 skype => Doesn't work Echo/Sound test service: it's likethere is no micro at all

$ LC_ALL=C APULSE_PLAYBACK_DEVICE=plughw:0,0 skype => Does work using hw mix and dsnoop capture but capture stop working after few minutes... :(

zen2 commented 10 years ago

with the dev branch:

APULSE_CAPTURE_DEVICE=plughw:0,1 APULSE_PLAYBACK_DEVICE=plughw:0,0 skype => Doesn't work Echo/Sound test service: it's likethere is no micro at all

with dsnoop/dmix asoundrc

skype => Does work but microphone stop to work after 2 minutes.

whithout asoundrc

skype => Doesn't work Echo/Sound test service: it's likethere is no micro at all

13ilya commented 10 years ago

I have a similar problem with broken microphone on skype, and I decided to write here, so as not to create a new issue.

In my system 2 sound card (CA0106 and HDA NVidia) and microphone on webcams. Sound I play from default (hw:0,0), and capture take with hw:1,0

Through apulse skype sound playing, but none of the 3 microphone does not work. Through alsa (check on Audacity) work all 3 through PulseAudio works hw: 0,0 (default).

Tried [code]APULSE_CAPTURE_DEVICE=hw:1,0 && apulse skype[/code] It does not help.

apulse building on openSUSE 12.3 x86_64 by [code]cd /tmp && git clone git://github.com/i-rinat/apulse.git && cd apulse && cmake -LA -DCMAKE_C_FLAGS_RELEASE:STRING="-m32 -march=native -msse3 -O3 -fomit-frame-pointer -pipe -DNDEBUG" -DCMAKE_CXX_FLAGS_RELEASE:STRING="-m32 -march=native -msse3 -O3 -fomit-frame-pointer -pipe -DNDEBUG" -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/usr && make -j4 && sudo make -j4 install && .. && sudo rm -r apulse[/code]

i-rinat commented 10 years ago

@IlyaIndigo, have you tried plughw:1,0 as capture device?

PulseAudio API have no rate negotiation abilities. Application just asks for a desired rate, and PA transparently performs resampling. Within apulse code I ask underlying hardware for that exact rate, and that probably fails if you use hw. Usually default device points to something like plughw, and thus almost arbitrary rate works. Either dmix or dsnoop do desired rate conversion.

13ilya commented 10 years ago

@i-rinat, thank you, it's work :-) [code]APULSE_CAPTURE_DEVICE=plughw:1,0 apulse skype[/code]

i-rinat commented 10 years ago

@zen2, I recently changed period size in 533b161ecf34fa06e1a8b67b4edefa5d8b974d6a (was hardcoded previously). It can change operation mode, and therefore fix the issue (hopefully, still no guarantees).

ismaell commented 8 years ago

Is this still a problem? I've been using plug+dsnoop for months with three different recording devices with no problems so far....