Comments (6)
@mgeier
Well, first of all, some information.
The environment is pretty complex and is working below a gRPC server. The idea is to use complex sound-card and run a sequence, but not at the same time, of measurements.
Till now I was using a single thread application and everything was fine, but in the moment a concurrent situation comes to life also a lot of problems present their business cards.
Accordingly to https://app.assembla.com/wiki/show/portaudio/Tips_Threading this is bad and needs special precaution. So definitely the problem is how I am using PA and sounddevice
So, if my analysis is correct (maybe I am missing something) I have to face with these problems:
- When a file with Soundcard is imported then the PortAudio is loaded and init, Pa_Initialize is called through _initialized()
- Because I embedded the whole code inside a class (a state machine of the soundcard) if I run two differents cycles of any playrec operation I experience some kinf of problem
- To make everything more difficult is then a multithread environment which needs more sync
- if the user add a sound card I need to reset the library
So, what I am doing now is to load/unload the library with some very simple methods, but this approach seems promising.
def terminate():
if sd._initialized:
sd._terminate()
return True
else:
return False
def initialize()
if not sd._initialized:
sd._initialize()
def reset()
terminate()
initialize()
Furthermore, just my two cents.
What about load/unload the library in every call that needs to use the PA library? This should increase the robustness against multithread access, isn't it? And it shouldn't break any compatibilities
from python-sounddevice.
For now, the "hidden" functions sd._terminate()
and sd._initialize()
can be used.
If anyone needs those to be part of the "official" API, please speak up!
from python-sounddevice.
Hi There,
could you add this to the public API?
Also, a method like is_initalized() should be nice to have.
I am asking because I am having a strange issue since I installed several ASIO sound card (but using once at time)
Not to mention this would fix also the issue when a refresh of the sound card list is needed
bastibe/PySoundCard#44
Thanks!
from python-sounddevice.
Do you have an idea how the API should look like?
Also, a method like is_initalized() should be nice to have.
For now, you can use sd._initialized
.
I am having a strange issue since I installed several ASIO sound card (but using once at time)
Can you describe the issue?
Is it an issue with the sounddevice
module or a more general PortAudio issue?
from python-sounddevice.
I'm very reluctant to add this to the public API because I think it would confuse users that don't have such complicated setups.
If using sd._terminate()
and sd._initialize()
works for you, that's fine, even if they start with underscores. I would consider them, together with _StreamBase
, as features for power-users, and "normal" users don't have to worry about them.
Regarding your case, you indeed have to be very careful with multithreading.
I don't know the exact requirements of your situation, but what about using a single callback for audio I/O?
Have you seen https://github.com/mgeier/python-rtmixer? Probably something like that would be a possible strategy in your case?
What about load/unload the library in every call that needs to use the PA library?
This wouldn't really work when using long-living streams.
Anyway, if that works for you, you can just wrap all of your calls into sd._initialize()
and sd._terminate()
in your own code. You could even create a little context manager for that.
I don't think it's a good idea to force this in all cases.
from python-sounddevice.
I'm closing this for now, but I'm open for further suggestions regarding the topic.
from python-sounddevice.
Related Issues (20)
- Enhancement Request: Integrate Playback Status Check into Simple `play`/`stop` API in `sounddevice` HOT 4
- Feature request for loopback of output device. HOT 3
- 设备解码错误?utf-8' codec can't decode byte 0xc2 in position 6: invalid continuation byte HOT 4
- Sounddevice + big dict + OOP = Segfault / Bus Error HOT 11
- Update device list by reloading portaudio dll HOT 1
- Won't be able to import sounddevice due to unknown issue with `libportaudio64bit.dll` HOT 5
- Error opening OutputStream: Unanticipated host error', -9999, (2, 0, 'Failed to load ASIO driver
- Use sounddevice with virtual audio device and minimize latency HOT 1
- Achieving stable latency between calls of "playrec" HOT 8
- sounddevice not recognize all devices?
- Issues with playing concurrently with Youtube HOT 1
- Latency 30mSec HOT 9
- Advice on asynchronous playback HOT 7
- docker node minimal image
- Can I continue recording until the volume drops below a threshold? HOT 4
- Simultaneous audio playback datatype issue HOT 2
- Does sd.wait() block all other threads? HOT 1
- OSERROR portaudio library not found
- Advice on detecting when Sounddevice has stopped playing audio (and using multiple OutputStreams)
- Inconsistent order of channels HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from python-sounddevice.