3737
3838from __future__ import annotations
3939
40- import atexit
4140import contextlib
4241import enum
4342import sys
@@ -483,14 +482,6 @@ class AudioStreamCallbackData:
483482_audio_stream_registry : weakref .WeakValueDictionary [int , AudioStream ] = weakref .WeakValueDictionary ()
484483
485484
486- @atexit .register
487- def _unlink_audio_callbacks () -> None :
488- """Deletes AudioStream callbacks to ensure a graceful application exit."""
489- for stream in _audio_stream_registry .values ():
490- stream .getter_callback = None
491- stream .putter_callback = None
492-
493-
494485class AudioStream :
495486 """An SDL audio stream.
496487
@@ -674,11 +665,13 @@ def getter_callback(self) -> Callable[[AudioStream, AudioStreamCallbackData], An
674665 @getter_callback .setter
675666 def getter_callback (self , callback : Callable [[AudioStream , AudioStreamCallbackData ], Any ] | None , / ) -> None :
676667 if callback is None :
677- lib .SDL_SetAudioStreamGetCallback (self ._stream_p , ffi .NULL , ffi .NULL )
668+ _check ( lib .SDL_SetAudioStreamGetCallback (self ._stream_p , ffi .NULL , ffi .NULL ) )
678669 _audio_stream_get_callbacks .pop (self , None )
679670 else :
680671 _audio_stream_get_callbacks [self ] = callback
681- lib .SDL_SetAudioStreamGetCallback (self ._stream_p , lib ._sdl_audio_stream_callback , ffi .cast ("void*" , 0 ))
672+ _check (
673+ lib .SDL_SetAudioStreamGetCallback (self ._stream_p , lib ._sdl_audio_stream_callback , ffi .cast ("void*" , 0 ))
674+ )
682675
683676 @property
684677 def putter_callback (self ) -> Callable [[AudioStream , AudioStreamCallbackData ], Any ] | None :
@@ -692,11 +685,13 @@ def putter_callback(self) -> Callable[[AudioStream, AudioStreamCallbackData], An
692685 @putter_callback .setter
693686 def putter_callback (self , callback : Callable [[AudioStream , AudioStreamCallbackData ], Any ] | None , / ) -> None :
694687 if callback is None :
695- lib .SDL_SetAudioStreamPutCallback (self ._stream_p , ffi .NULL , ffi .NULL )
688+ _check ( lib .SDL_SetAudioStreamPutCallback (self ._stream_p , ffi .NULL , ffi .NULL ) )
696689 _audio_stream_put_callbacks .pop (self , None )
697690 else :
698691 _audio_stream_put_callbacks [self ] = callback
699- lib .SDL_SetAudioStreamPutCallback (self ._stream_p , lib ._sdl_audio_stream_callback , ffi .cast ("void*" , 0 ))
692+ _check (
693+ lib .SDL_SetAudioStreamPutCallback (self ._stream_p , lib ._sdl_audio_stream_callback , ffi .cast ("void*" , 1 ))
694+ )
700695
701696
702697class _LoopSoundFunc :
@@ -806,7 +801,8 @@ def stop(self) -> None:
806801class BasicMixer :
807802 """An SDL sound mixer implemented in Python and Numpy.
808803
809- Example:
804+ Example::
805+
810806 import time
811807
812808 import soundfile # pip install soundfile
@@ -1032,17 +1028,10 @@ def open( # noqa: A001, PLR0913
10321028 paused:
10331029 If True then the device will begin in a paused state.
10341030 It can then be unpaused by assigning False to :any:`AudioDevice.paused`.
1035- callback:
1036- If None then this device will be opened in push mode and you'll have to use :any:`AudioDevice.queue_audio`
1037- to send audio data or :any:`AudioDevice.dequeue_audio` to receive it.
1038- If a callback is given then you can change it later, but you can not enable or disable the callback on an
1039- opened device.
1040- If True then a default callback which plays silence will be used, this is useful if you need the audio
1041- device before your callback is ready.
1031+ callback: An optional callback to use, this is deprecated.
10421032
10431033 If a callback is given then it will be called with the `AudioDevice` and a Numpy buffer of the data stream.
10441034 This callback will be run on a separate thread.
1045- Exceptions not handled by the callback become unraiseable and will be handled by :any:`sys.unraisablehook`.
10461035
10471036 .. versionchanged:: Unreleased
10481037 SDL3 returns audio devices differently, exact formatting is set with :any:`AudioDevice.new_stream` instead.
0 commit comments