-
Notifications
You must be signed in to change notification settings - Fork 149
exclusive mode for wasapi #35
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Not yet. But if you are willing to test it, I can try to implement it.
|
yes, I would love to test it. The wasapi exclusive mode is supposed to have 2016-08-16 19:47 GMT+02:00 Matthias Geier [email protected]:
|
Great! I'll implement this next week and let you know when there's something |
See also #4. |
I've installed the
I have no experience with cffi and don't know how to fix it. |
Sorry, my bad! I've updated the last commit, can you please try again? |
so I got:
|
Silly me. I made another mistake. Can you try again, please? |
mhm.. I tried also to change
|
but actually wasapi just doesn't work anymore at all. I had this behavior before, but I really don't understand it; no idea, why. I'll test it on the pc |
on win8, I get the same error as before:
|
and on my laptop wasapi juest doesn't work anymore, it says invalid device, although I'm using the same device, same drivers etc.. wdm/ks still works; that's so strange.. |
OK, I guess now we are down to the real problem ... Please make sure that you are using the correct DLL, see #36 (comment). You could also try the DLL from https://github.com/adfernandes/precompiled-portaudio-windows instead of the bundled DLL. Or the one from pyo. Can you please try it with Probably the error is related to On the computers where WASAPI doesn't work, does it work with other PortAudio applications, e.g. Audacity? |
yes, I'm using the correct dll (I need to specify it each time in I'm using windows 7 on my laptop. The wasapi drivers worked with Loopback recording with wasapi host under audacity however works well on |
I don't know why WASAPI doesn't work anymore. Did you try an older version of python-sounddevice for comparison? You could search your hard disk for |
ok, when I run wasapi_exclusive = sd.WasapiSettings(exclusive=False), I get sounddevice.PortAudioError: Error opening OutputStream: Incompatible host same error with Fernandes' libraries |
ok, I've tried to set hostApiType in the WasapiSettings class to any number |
This should do it: wasapi_exclusive._streaminfo.hostApiType If you want to get the host API type from an existing stream, you'll need You can add this to the PaHostApiTypeId Pa_GetStreamHostApiType( PaStream* stream ); And then you should be able to use it like this: mystream = sd.OutputStream(...)
ha_type = sd._lib.Pa_GetStreamHostApiType(mystream._ptr) |
regarding wasapi not working, I've tried it out with pysounddevice and it didn't work... the portaudio.dll on the win8 was actually located in the psychopy folder (c:\programfiles (x86)\psychopy), I didn't expect cffi to search there... Maybe the path was added to my local python installation... |
@piotx Any news? Did you get it to work in the meantime? |
Hello Matthias, I didn't try it out any more, I would linke to do it again after |
Hello, on a Windows 7 system, I get the same error message as Piotr.
Cheers |
|
Good idea! Actually, I was already working on updating to the new PortAudio release, some testing would be very welcome! For now, there is a branch called |
I would like to download files from GitHub manually. Can I just replace libportaudio64bit.dll and sounddevice.py in my present sounddevice installation in WinPython with the files from the |
Yes, this should work, too. |
Thank you mgeier. I installed new DLL and played without error. wasapi_exclusive = sd.WasapiSettings(exclusive=True)
sd.play(mysnd, extra_settings=wasapi_exclusive) I will report the performance aftertime. |
I've just checked it out on win8 and it works for me as well! Pretty cool! |
ok, so wasapi (exclusive=True) works with sd.play. that's pretty cool! The latency seems to be great (as measured with an oscilloscope and parallel port triggers), but only 37ms of the 50ms sound are played back on one of my machines (win8 with onboard soundcard) OutputStream.write() works only with exclusive=False; when using exclusive=True, there is only strange noise. here is the code used: from ctypes import windll
import time
import sounddevice as sd
import soundfile as sf
#exclusive = True
audio_dev = 18 #14
data, fs = sf.read('d:\snd_scripts_f\startle50ms.wav', dtype='float32')
wasapi_exclusive = sd.WasapiSettings(exclusive=True)
stream = sd.OutputStream(device = audio_dev,extra_settings=wasapi_exclusive)
stream.start()
#sd.query_devices()
p = windll.inpout32
duration = 0.05
pause = 0.1
repeat = 10000
address = 0xDC00
for i in range(1,repeat+1):
#sd.play(data,fs,device=audio_dev,extra_settings=wasapi_exclusive)
stream.write(data)
p.Out32(address, 255)
target_time = time.clock() + duration
while time.clock() < target_time:
pass
p.Out32(address, 0)
time.sleep(pause) |
@piotx Thanks for testing this, nice that it (mostly) works!
This sounds similar to #44, doesn't it? I also experienced that in some situations the last few frames are not played with ALSA. This might as well depend on the hardware. With JACK, however, this never happened.
Does this only happen with the new PortAudio version? @hiccup7 @stefanrepplinger Do you want to try it, too? I've created a PR for the new dylib/DLL version: #53. Does anyone have an ASIO device to test? Does anyone of you happen to use 32-bit Windows? |
I can do some tests, when I'll be back in one week or so. Exclusive mode btw. I just replaced the portaudio.dll with the new one... I'm using the |
Test conditions:
The following applies when the WASAPI host API device is used: With the WDM-KS and ASIO host API devices are used for the same USB external DAC, |
@hiccup7 Thanks for the thorough test! That's good news! Did you also try it without modifying |
I tested with the Realtek sound card on my laptop. It works with WASAPI shared mode, but not with exclusive mode. However, JRiver Media Center v22 outputs noise with exclusive mode on the same device. Therefore, I suspect that this sound card is the problem for exclusive mode. I haven't yet tested any other conditions. I plan to test with the original Christoph Gohlke added sounddevice to his Windows builds using the same Microsoft compiler as each version of Python uses: http://www.lfd.uci.edu/~gohlke/pythonlibs/#sounddevice We can expect that a lot more Windows Python users will be using sounddevice now that Christoph has added this support. |
FYI, the file It's great that the |
I tested the original I documented my testing result just now for cgohlke's wheel at winpython/winpython#428 |
That's great, so there is no need to change I will make a new release soon, but I would like to hear first if the new 32-bit DLL works. |
I have tested sounddevice with the new 32bit DLL on 32bit Windows 7. I recorded the data in 1000 Hz, so 1 ms error is the sampling error. Thank you anyway! The performance is good enough. |
@cosacog Thanks for testing, it's good to know that the 32bit DLLs work. I don't understand those plots, what are they supposed to show? |
I played just one time with ASIO, but it failed. It was wired to me that the device number for ASIO was only 14. The other apis like WASAPI and MME had more than one device numbers for input and output. By the way, each histogram shows the difference between a trigger and a sound with psychopy. With MME, the delay of sound is around 270 ms while the jitter is 5-6 ms. When recording EEG responses after sound, the jitter is a problem because brain responses (evoked potentials) are time locked to the stimulus, and the potentials are blurred by the jitter. Now I am happy to see that the jitter is 1 ms or less with WDM-KS. |
How did it fail?
That's normal, and that's actually an advantage! Thanks for explaining the histograms, I think I understand them now. That's really interesting. I would expect that the jitter is highly dependent on the audio block size, right? |
The error log when playin with asio is as follows:
I created trigger through parallel port with psychopy. The script to create trigger and to play sound is here in Gist. I recorded the trigger out of parallel port and the sound through RCA plug of the PCI-e sound card, using AD converter of EEG measurement system. I played click (square wave) sound. The plot image of the sound is shown below. The plot means that 441 points out of 88200 points (at 44100 hz) are the sound, so the sound duration is 10 ms. plt.plot(mysnd)
Please see the script above. I am sorry but I do not understand the blocking or the callback method enough. I think I used the blocking method.
I'm sorry again. I don't understand block sizes. The duration of the sound is 10 ms, but maybe it's not the answer.
The delay and jitter is repoted on another thread of psychopy as you know. |
The ASIO error is unfortunate, but I have no clue what's its cause. Does the same ASIO device work with other PortAudio applications, e.g. Audacity? Thanks for the Gist, that's very helpful. So you were using I suspect that you jitter measurements may be biased because you repeat the measurements regularly. Your p_port.setData(int(1))
sd.play(mysnd, blocking=True)
p_port.setData(int(0)) Whenever you want to wait some time, you can just use time.sleep(). BTW, I just found out that Jon added a
The audio drivers and audio frameworks normally don't process the sound sample by sample. They typically work on a bunch of samples at once, which I would call a "block", but there are different names in use. PortAudio of course also uses blocks internally, and with sd.default.blocksize = 1024 The blocksize will have an immediate effect on the latency. Apart from the sd.default.latency = 'low' For some devices, however, the default "high" and "low" settings are actually the same. sd.default.latency = 0.005 Of course, only a certain range of latencies is physically possible, PortAudio will try to get as close as possible to the value you specified. Once you have created an It would be interesting to know if your measured latencies are similar to those estimated by PortAudio. |
I reported ASIO results with the 64-bit DLL a week ago:
I would like to set |
@hiccup7 TBH, I don't know yet. Probably I should change the API completely ... Can you please open a new issue for that where we can discuss further? |
Done. See #55 |
@mgeier Thank you for a lot of comments and advises. They are very helpful for me to understand the settings. I will test the measurements according to your advice and the new psychopy sounddevice backend. I am busy for some time, so it will be in a few weeks. |
I'm closing this because I think there are no more open questions. Thanks for the discussions! If there are any more problems/comments/suggestions/..., feel free to create new issues. |
Hello,
it's not an issue, but rather a question.
Is it possible to enable exclusive for wasapi?
best wishes
Piotr
The text was updated successfully, but these errors were encountered: