i-rinat / apulse

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

Ring buffer without locking #12

Closed skotopes closed 9 years ago

skotopes commented 10 years ago

Current implementation is not very efficient for audio. I can recommend implementation made by Jack: https://github.com/jackaudio/jack2/blob/master/common/ringbuffer.c It's a de-facto standard.

i-rinat commented 10 years ago

Yeah, it's not utmost efficient. But what goal are you trying to achieve? Say the fastest-in-the-Universe ringbuffer will be used. What changes then?

That implementation doesn't look thread-safe. Consider two writers, both trying to fill the buffer. There is a possibility they overwrite each others data. There seems to be no apparent issues with only one reader and one writer. But current (with locks) version should not be significantly slower in that case too, while providing thread safety in case of multiple writers.

And I'll have to change project license if I use that code.

skotopes commented 10 years ago

One of the reasons why ring buffer is used in audio is because it allows to forget about locking. It's especially important when you feeding device with small buffer and want to achieve low latency.

Implementation from Jack is safe for 2 threads: 1 writer and 1 reader. If we are still talking about audio and you trying to feed ring buffer from multiple threads then you doing it wrong.

Ring buffer is quite standard thing, algorithm is not patented. Guys from Jack audio also didn't invent it. In worst case you can find other implementation which matches your license.

I'm just pointing that this type of structure not intended to be used with locking.

i-rinat commented 10 years ago

Feel free to implement any buffering scheme you like. I have no intention to perform further development.

skotopes commented 10 years ago

Why?

It's quite nice project, and people promoting it as a replacement for geeks who don't like to use pulse audio. They using it with a new Skype versions which only support pulse audio.

As for me I'm not using linux on desktop, but I can help with my experience and advices.

i-rinat commented 10 years ago

Why?

I don't want to do it at the moment. And I don't think decision will change in a near future.

They using it with a new Skype versions which only support pulse audio.

This was the first and only real reason to develop it. (Aside from practice.) Now, when Skype works, there is nothing left to do.

vlad2005 commented 10 years ago

Congrats for u work!!!! In my case is an must to have this wrapper because with pulseaudio skype work really badly.

Thanks!!

P.S. i see that sometimes, when skype start first, then chrome not work on youtube. After quit skype, logout and login again everything work well. I don't know, i will test more.

i-rinat commented 10 years ago

i see that sometimes, when skype start first, then chrome not work on youtube

@vlad2005, you probably use hw:0,0 or something similar as output device. If so, first application will grab output device exclusively. You can use plughw-type devices to make ALSA convert sample rates and mix sound streams for you. Then multiple applications can output audio simultaneously.

vlad2005 commented 10 years ago

I try right now command like this: apulse skype plughw:0,0 and seem to work. Is this right command?

i-rinat commented 10 years ago

Is this right command?

No, you use environment variables to select devices. Something like that: APULSE_CAPTURE_DEVICE=plughw:0,0 APULSE_PLAYBACK_DEVICE=plughw:0,0 apulse skype

Your command only passes parameter to skype itself, and it apparently just ignores that.

I'm not good at configuring audio devices, default configurations always worked well for me. If you want detailed instructions, start with http://www.alsa-project.org/main/index.php/Asoundrc

vlad2005 commented 10 years ago

Ok, thanks! In fact is specified in documentation! :)

vlad2005 commented 10 years ago

I'm happy!!!! For the first time i was able to use skype with ubuntu 14.04 without pulseuadio in real conversation. Until now, with pulseaudio i have bad audio, unusable. Now, i save on cloud apulse and skype 4.3 for future! :) Thanks again!

P.S. will be great for community if u have time to create an ppa for this wonderfull wrapper. Many people are scarried about compiling in linux.

jauhien commented 10 years ago

will be great for community if u have time to create an ppa for this wonderfull wrapper. Many people are scarried about compiling in linux.

Use distribution, where it is packed already, e.g. Gentoo. ;-)