11"""SDL2 audio playback and recording tools.
22
3- This module includes SDL's low-level audio API and a naive implentation of an SDL mixer.
3+ This module includes SDL's low-level audio API and a naive implementation of an SDL mixer.
44If you have experience with audio mixing then you might be better off writing your own mixer or
55modifying the existing one which was written using Python/Numpy.
66
77This module is designed to integrate with the wider Python ecosystem.
8- It leaves the loading to sound samples to other libaries like
8+ It leaves the loading to sound samples to other libraries like
99`SoundFile <https://pysoundfile.readthedocs.io/en/latest/>`_.
1010
1111Example::
1717 import tcod.sdl.audio
1818
1919 device = tcod.sdl.audio.open() # Open the default output device.
20- sound, samplerate = soundfile.read("example_sound.wav", dtype="float32") # Load an audio sample using SoundFile.
21- converted = device.convert(sound, samplerate ) # Convert this sample to the format expected by the device.
22- device.queue_audio(converted) # Play audio syncroniously by appending it to the device buffer.
20+ sound, sample_rate = soundfile.read("example_sound.wav", dtype="float32") # Load an audio sample using SoundFile.
21+ converted = device.convert(sound, sample_rate ) # Convert this sample to the format expected by the device.
22+ device.queue_audio(converted) # Play audio synchronously by appending it to the device buffer.
2323
2424 while device.queued_samples: # Wait until device is done playing.
2525 time.sleep(0.001)
3333 import tcod.sdl.audio
3434
3535 mixer = tcod.sdl.audio.BasicMixer(tcod.sdl.audio.open()) # Setup BasicMixer with the default audio output.
36- sound, samplerate = soundfile.read("example_sound.wav") # Load an audio sample using SoundFile.
37- sound = mixer.device.convert(sound, samplerate ) # Convert this sample to the format expected by the device.
36+ sound, sample_rate = soundfile.read("example_sound.wav") # Load an audio sample using SoundFile.
37+ sound = mixer.device.convert(sound, sample_rate ) # Convert this sample to the format expected by the device.
3838 channel = mixer.play(sound) # Start asynchronous playback, audio is mixed on a separate Python thread.
3939 while channel.busy: # Wait until the sample is done playing.
4040 time.sleep(0.001)
5959
6060
6161def _get_format (format : DTypeLike ) -> int :
62- """Return a SDL_AudioFormat bitfield from a NumPy dtype."""
62+ """Return a SDL_AudioFormat bit-field from a NumPy dtype."""
6363 dt : Any = np .dtype (format )
6464 assert dt .fields is None
6565 bitsize = dt .itemsize * 8
@@ -83,15 +83,15 @@ def _dtype_from_format(format: int) -> np.dtype[Any]:
8383 """Return a dtype from a SDL_AudioFormat."""
8484 bitsize = format & lib .SDL_AUDIO_MASK_BITSIZE
8585 assert bitsize % 8 == 0
86- bytesize = bitsize // 8
86+ byte_size = bitsize // 8
8787 byteorder = ">" if format & lib .SDL_AUDIO_MASK_ENDIAN else "<"
8888 if format & lib .SDL_AUDIO_MASK_DATATYPE :
8989 kind = "f"
9090 elif format & lib .SDL_AUDIO_MASK_SIGNED :
9191 kind = "i"
9292 else :
9393 kind = "u"
94- return np .dtype (f"{ byteorder } { kind } { bytesize } " )
94+ return np .dtype (f"{ byteorder } { kind } { byte_size } " )
9595
9696
9797def convert_audio (
@@ -103,8 +103,8 @@ def convert_audio(
103103
104104 Args:
105105 in_sound: The input ArrayLike sound sample. Input format and channels are derived from the array.
106- in_rate: The samplerate of the input array.
107- out_rate: The samplerate of the output array.
106+ in_rate: The sample-rate of the input array.
107+ out_rate: The sample-rate of the output array.
108108 out_format: The output format of the converted array.
109109 out_channels: The number of audio channels of the output array.
110110
@@ -142,7 +142,7 @@ class AudioDevice:
142142
143143 Open new audio devices using :any:`tcod.sdl.audio.open`.
144144
145- When you use this object directly the audio passed to :any:`queue_audio` is always played syncroniously .
145+ When you use this object directly the audio passed to :any:`queue_audio` is always played synchronously .
146146 For more typical asynchronous audio you should pass an AudioDevice to :any:`BasicMixer`.
147147 """
148148
@@ -231,7 +231,7 @@ def convert(self, sound: ArrayLike, rate: int | None = None) -> NDArray[Any]:
231231
232232 Args:
233233 sound: An ArrayLike sound sample.
234- rate: The samplerate of the input array.
234+ rate: The sample-rate of the input array.
235235 If None is given then it's assumed to be the same as the device.
236236
237237 .. versionadded:: 13.6
0 commit comments