Git Product home page Git Product logo

Comments (6)

lawrence-iviani avatar lawrence-iviani commented on July 28, 2024 1

@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.

mgeier avatar mgeier commented on July 28, 2024

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.

lawrence-iviani avatar lawrence-iviani commented on July 28, 2024

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.

mgeier avatar mgeier commented on July 28, 2024

@lawrence-iviani

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.

mgeier avatar mgeier commented on July 28, 2024

@lawrence-iviani

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.

mgeier avatar mgeier commented on July 28, 2024

I'm closing this for now, but I'm open for further suggestions regarding the topic.

from python-sounddevice.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.