Code Monkey home page Code Monkey logo

Comments (10)

jacobanana avatar jacobanana commented on June 18, 2024 1

Hi Matthias,
Sorry for the late reply. I had a go at the new branch and this works for me.

I create a method to query the devices and force the refresh and this works fine:

def query_devices_refresh(device=None):
        sd._terminate()
        sd._initialize()
        return sd.query_devices(device)

There is no problem with disconnecting a device and then executing _terminate() followed by initialize()

Thanks again for your support
Adrien

from python-sounddevice.

mgeier avatar mgeier commented on June 18, 2024

See issue #3.

from python-sounddevice.

jacobanana avatar jacobanana commented on June 18, 2024

HI Matthias

Thanks for your quick reply. I've tried this but _terminate returns an error in Python 2.7:

>>> sd._terminate() Traceback (most recent call last): File "<stdin>", line 1, in <module> File "C:\Python27\lib\site-packages\sounddevice.py", line 2681, in _terminate _atexit.unregister(_lib.Pa_Terminate) AttributeError: 'module' object has no attribute 'unregister'

I have tried executing the ._check(sd._lib.Pa_Terminate(), 'Error terminating PortAudio') manually instead followed by _initialize() but this doesn't refresh the list of devices produces by query_devices()

Any ideas? Thanks for your help

Adrien

from python-sounddevice.

jacobanana avatar jacobanana commented on June 18, 2024

Hi Matthias,

I found that commenting out the line with _atexit.unregister(_lib.Pa_Terminate) solves the problem.

Adrien

from python-sounddevice.

mgeier avatar mgeier commented on June 18, 2024

OK, but when you call sd._terminate() and then close the Python interpreter, you'll get this error:

PortAudioError: Error terminating PortAudio: PortAudio not initialized

Right?

I'll have to find a way to work around the fact that atexit.unregister() doesn't exist in Python 2.

from python-sounddevice.

jacobanana avatar jacobanana commented on June 18, 2024

HI Matthias,

This is the error I get when closing the Python interpreter:

Error in atexit._run_exitfuncs: Traceback (most recent call last): File "C:\Python27\lib\atexit.py", line 24, in _run_exitfuncs func(*targs, **kargs) KeyboardInterrupt Error in sys.exitfunc: Traceback (most recent call last): File "C:\Python27\lib\atexit.py", line 24, in _run_exitfuncs func(*targs, **kargs) KeyboardInterrupt

from python-sounddevice.

mgeier avatar mgeier commented on June 18, 2024

I've implemented a possible fix in #48, can you please check if that works for you?

Note: If you change the configuration (plug/unplug devices) while PortAudio is initialized, the next call to sd._terminate() might crash your Python interpreter! At least that happens sometimes when I start/stop jackd at the wrong time.
Make sure to always use it like this, then it should be safe:

  1. sd._terminate()
  2. change hardware
  3. sd._initialize()

The behavior should be better now, even for Python 3, because atexit.unregister() has a slightly different behavior than I thought.
Previously, if sd._initialize() was called multiple times and afterwards sd._terminate() was called fewer times, the missing "terminate" calls were not done when exiting. This is of course a silly edge case, but now that should work, too.

For those who are curious, here's a discussion about adding atexit.unregister() to Python: https://mail.python.org/pipermail/python-dev/2005-April/052983.html. The opinions are mostly negative, I wonder why they added it anyway in Python 3 ...

from python-sounddevice.

mgeier avatar mgeier commented on June 18, 2024

@jacobanana Thanks, I've merged #48 into master.

It's good to know that there are no crashes when hot-plugging devices. On which OS did you try that?

from python-sounddevice.

jacobanana avatar jacobanana commented on June 18, 2024

hi matthias,
that was tried on windows 8.1, osx and raspbian

i did get one problem on osx with multiple streams running at once... i know you recommend only having one stream running at a time but it does work quite well on raspbian. I get an occasional crash on OSX and windows ASIO just doesn't allow it at all. This is a separate issue though.

from python-sounddevice.

mgeier avatar mgeier commented on June 18, 2024

Thanks. So the only time it reportedly crashed, is when starting/stopping jackd at the wrong time. That's good to know.

About multiple streams: PortAudio doesn't officially support multiple streams. They might work on some platforms, but if you want your code to be portable, you should only use one stream at a time.

If you think there is something that I could do on the Python side, please open a new issue.

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.