ffaudio 4.2.0__py3-none-win_amd64.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
ffaudio/_native.py ADDED
@@ -0,0 +1,527 @@
1
+ #
2
+ # Copyright (c) 2025 Odalith
3
+ #
4
+ # ffaudio is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public
5
+ # License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any
6
+ # later version.
7
+ #
8
+ """
9
+ The C API one to one: the library, every struct of the five public headers as a ctypes Structure, and the argument
10
+ and result types of every function. The Pythonic layer (__init__.py) is built on this; use it directly only for
11
+ what that layer does not cover.
12
+
13
+ Struct layouts must match the headers exactly: tests/test_bindings.py compares every size and offset with what a C
14
+ compiler says (tests/layout.c).
15
+ """
16
+
17
+ import ctypes
18
+ import os
19
+ import sys
20
+ from ctypes import (CFUNCTYPE, POINTER, Structure, Union, c_bool, c_char, c_char_p, c_double, c_float, c_int,
21
+ c_int32, c_int64, c_size_t, c_uint64, c_uint8, c_void_p)
22
+
23
+ ABI_MAJOR = 4 # the major version these declarations are for (the soname: libffaudio.so.4)
24
+
25
+
26
+ #+-----------------------------------------------------+
27
+ #| Finding the library |
28
+ #+-----------------------------------------------------+
29
+
30
+ def _candidates():
31
+ env = os.environ.get("FFAUDIO_LIBRARY")
32
+ if env:
33
+ yield env
34
+ return
35
+ here = os.path.dirname(os.path.abspath(__file__))
36
+ names = (["libffaudio.dll", "libffaudio-4.dll", "ffaudio.dll"] if sys.platform == "win32" else
37
+ ["libffaudio.4.dylib", "libffaudio.dylib"] if sys.platform == "darwin" else
38
+ ["libffaudio.so.4", "libffaudio.so"])
39
+ # A wheel from PyPI (since 4.2): the libraries in ffaudio/_libs
40
+ for n in names:
41
+ yield os.path.join(here, "_libs", n)
42
+ # A release archive: <root>/python/ffaudio, the library in <root>/lib (or <root>/bin on Windows)
43
+ for rel in ("../../bin", "../../lib", "../../lib64", ".."):
44
+ for n in names:
45
+ yield os.path.normpath(os.path.join(here, rel, n))
46
+ yield from names # the system's search path (an installed libffaudio)
47
+
48
+
49
+ def _load():
50
+ errors = []
51
+ for path in _candidates():
52
+ if os.path.isabs(path) and not os.path.exists(path):
53
+ continue
54
+ try:
55
+ if sys.platform == "win32" and os.path.isabs(path):
56
+ # The DLLs it needs (FFmpeg, SDL2, the MinGW runtime) are next to it in a release archive
57
+ os.add_dll_directory(os.path.dirname(path))
58
+ return ctypes.CDLL(path)
59
+ except OSError as e:
60
+ if sys.platform == "win32":
61
+ # A build of your own: its DLLs are on PATH (e.g. MSYS2's ucrt64/bin), which Python 3.8+ leaves
62
+ # out of the search for a DLL's dependencies; winmode=0 is Windows' standard search order
63
+ try:
64
+ return ctypes.CDLL(path, winmode=0)
65
+ except OSError:
66
+ pass
67
+ errors.append(f"{path}: {e}")
68
+ hint = ("\n(on Linux, ffaudio needs the system's SDL2: libsdl2-2.0-0 on Debian/Ubuntu, sdl2 on Arch/Fedora)"
69
+ if sys.platform.startswith("linux") else "")
70
+ raise ImportError("libffaudio (version 4) not found; set FFAUDIO_LIBRARY to its path\n " + "\n ".join(errors)
71
+ + hint)
72
+
73
+
74
+ lib = _load()
75
+
76
+
77
+ #+-----------------------------------------------------+
78
+ #| Structs (ffaudio.h) |
79
+ #+-----------------------------------------------------+
80
+
81
+ class EvLog(Structure):
82
+ _fields_ = [("level", c_int), ("message", c_char_p), ("request", c_int64)]
83
+
84
+
85
+ class EvDevice(Structure):
86
+ _fields_ = [("ok", c_bool), ("fell_back", c_bool), ("name", c_char_p), ("sample_rate", c_int32),
87
+ ("channels", c_int32)]
88
+
89
+
90
+ class EvOpened(Structure):
91
+ _fields_ = [("duration", c_double), ("live", c_bool), ("seekable", c_bool)]
92
+
93
+
94
+ class EvEnded(Structure):
95
+ _fields_ = [("reason", c_int), ("error", c_int32), ("message", c_char_p)]
96
+
97
+
98
+ class EvRestarted(Structure):
99
+ _fields_ = [("position", c_double), ("from_loop", c_bool), ("loops_remaining", c_int32)]
100
+
101
+
102
+ class EvDuration(Structure):
103
+ _fields_ = [("seconds", c_double)]
104
+
105
+
106
+ class EvBuffering(Structure):
107
+ _fields_ = [("active", c_bool), ("buffered_seconds", c_double)]
108
+
109
+
110
+ class EvMetadata(Structure):
111
+ _fields_ = [("title", c_char_p), ("artist", c_char_p)]
112
+
113
+
114
+ class EvOverflow(Structure):
115
+ _fields_ = [("dropped", c_int32)]
116
+
117
+
118
+ class EvData(Union):
119
+ _fields_ = [("log", EvLog), ("device", EvDevice), ("opened", EvOpened), ("ended", EvEnded),
120
+ ("restarted", EvRestarted), ("duration", EvDuration), ("buffering", EvBuffering),
121
+ ("metadata", EvMetadata), ("overflow", EvOverflow), ("padding", c_uint8 * 64)]
122
+
123
+
124
+ class AuEvent(Structure):
125
+ _fields_ = [("type", c_int), ("handle", c_int32), ("data", EvData)]
126
+
127
+
128
+ AuEventFn = CFUNCTYPE(None, POINTER(AuEvent), c_void_p)
129
+ AuFadeCurveFn = CFUNCTYPE(c_float, c_float, c_void_p)
130
+
131
+
132
+ class AuFade(Structure):
133
+ _fields_ = [("seconds", c_double), ("curve", c_int), ("custom", AuFadeCurveFn), ("custom_user", c_void_p)]
134
+
135
+
136
+ class AuCrossfade(Structure):
137
+ _fields_ = [("on_track_end", AuFade), ("on_skip", AuFade), ("on_play", AuFade), ("on_stop", AuFade),
138
+ ("on_pause", AuFade), ("min_track_seconds", c_double)]
139
+
140
+
141
+ class AuReplayGain(Structure):
142
+ _fields_ = [("track_gain_db", c_float), ("track_peak", c_float), ("album_gain_db", c_float),
143
+ ("album_peak", c_float), ("from_r128", c_bool)]
144
+
145
+
146
+ class AuReplayGainSettings(Structure):
147
+ _fields_ = [("mode", c_int), ("preamp_db", c_double), ("fallback_gain_db", c_double),
148
+ ("prevent_clipping", c_bool), ("measure_missing", c_bool), ("measure_wait_seconds", c_double)]
149
+
150
+
151
+ class AuNetworkSettings(Structure):
152
+ _fields_ = [("user_agent", c_char_p), ("timeout_seconds", c_double), ("buffer_seconds", c_double),
153
+ ("max_buffer_seconds", c_double), ("reconnect_attempts", c_int)]
154
+
155
+
156
+ class AuTag(Structure):
157
+ _fields_ = [("key", c_char_p), ("value", c_char_p)]
158
+
159
+
160
+ class AuMediaInfo(Structure):
161
+ _fields_ = [("path", c_char_p), ("container", c_char_p), ("codec", c_char_p), ("channel_layout", c_char_p),
162
+ ("duration", c_double), ("bit_rate", c_int64), ("sample_rate", c_int), ("channels", c_int),
163
+ ("bits_per_sample", c_int), ("live", c_bool), ("seekable", c_bool), ("track_number", c_int),
164
+ ("track_total", c_int), ("disc_number", c_int), ("disc_total", c_int),
165
+ ("replaygain", AuReplayGain), ("tag_count", c_int), ("tags", POINTER(AuTag)),
166
+ ("picture_count", c_int)]
167
+
168
+
169
+ class AuPicture(Structure):
170
+ _fields_ = [("data", POINTER(c_uint8)), ("size", c_size_t), ("mime", c_char_p), ("type", c_int),
171
+ ("width", c_int), ("height", c_int), ("description", c_char_p)]
172
+
173
+
174
+ class AuStatus(Structure):
175
+ _fields_ = [("handle", c_int32), ("position", c_double), ("duration", c_double), ("buffering", c_bool),
176
+ ("paused", c_bool), ("muted", c_bool), ("volume", c_float), ("speed", c_double),
177
+ ("keep_pitch", c_bool), ("loop_count", c_int), ("sample_rate", c_int), ("channels", c_int)]
178
+
179
+
180
+ #+-----------------------------------------------------+
181
+ #| Structs (ffaudio_filters.h) |
182
+ #+-----------------------------------------------------+
183
+
184
+ EQ_BANDS = 10
185
+ PEQ_MAX_BANDS = 32
186
+
187
+
188
+ class AuEqualizer(Structure):
189
+ _fields_ = [("gain_db", c_double * EQ_BANDS), ("frequency_hz", c_double * EQ_BANDS),
190
+ ("width_hz", c_double * EQ_BANDS), ("preamp_db", c_double)]
191
+
192
+
193
+ class AuPeqBand(Structure):
194
+ _fields_ = [("type", c_int), ("frequency_hz", c_double), ("q", c_double), ("gain_db", c_double)]
195
+
196
+
197
+ class AuParametricEq(Structure):
198
+ _fields_ = [("preamp_db", c_double), ("band_count", c_int), ("bands", AuPeqBand * PEQ_MAX_BANDS)]
199
+
200
+
201
+ class AuStereo(Structure):
202
+ _fields_ = [("balance", c_double), ("width", c_double), ("swap", c_bool)]
203
+
204
+
205
+ class AuLimiter(Structure):
206
+ _fields_ = [("ceiling_db", c_double), ("attack_ms", c_double), ("release_ms", c_double)]
207
+
208
+
209
+ class AuCompressor(Structure):
210
+ _fields_ = [("threshold_db", c_double), ("ratio", c_double), ("attack_ms", c_double), ("release_ms", c_double),
211
+ ("knee_db", c_double), ("makeup_db", c_double)]
212
+
213
+
214
+ class AuDeclick(Structure):
215
+ _fields_ = [("window_ms", c_double), ("overlap_percent", c_double), ("threshold", c_double), ("burst", c_double)]
216
+
217
+
218
+ class AuDeclip(Structure):
219
+ _fields_ = [("window_ms", c_double), ("overlap_percent", c_double), ("threshold", c_double)]
220
+
221
+
222
+ class AuCrossfeed(Structure):
223
+ _fields_ = [("strength", c_double), ("range", c_double), ("slope", c_double), ("level_in", c_double),
224
+ ("level_out", c_double)]
225
+
226
+
227
+ #+-----------------------------------------------------+
228
+ #| Structs (ffaudio_loudness.h, _meters.h, _playlist.h)|
229
+ #+-----------------------------------------------------+
230
+
231
+ class AuLoudness(Structure):
232
+ _fields_ = [("silent", c_bool), ("integrated_lufs", c_double), ("loudness_range_lu", c_double),
233
+ ("true_peak", c_double), ("sample_peak", c_double), ("duration", c_double),
234
+ ("replaygain_gain_db", c_double), ("r128_gain_db", c_double), ("r128_gain_q78", c_int32)]
235
+
236
+
237
+ AuLoudnessProgressFn = CFUNCTYPE(c_bool, c_double, c_void_p)
238
+
239
+
240
+ class AuLoudnessOptions(Structure):
241
+ _fields_ = [("skip_true_peak", c_bool), ("progress", AuLoudnessProgressFn), ("progress_user", c_void_p)]
242
+
243
+
244
+ AuGainCachedFn = CFUNCTYPE(None, c_char_p, c_int, POINTER(AuReplayGain), c_void_p)
245
+ AuGainCacheVisitorFn = CFUNCTYPE(c_bool, c_char_p, POINTER(AuReplayGain), c_void_p)
246
+
247
+
248
+ class AuGainScanSettings(Structure):
249
+ _fields_ = [("threads", c_int), ("skip_true_peak", c_bool), ("on_cached", AuGainCachedFn), ("user", c_void_p),
250
+ ("measure_streams", c_bool)]
251
+
252
+
253
+ class AuLevels(Structure):
254
+ _fields_ = [("channels", c_int), ("sample_rate", c_int), ("window_seconds", c_double), ("peak", c_float * 8),
255
+ ("rms", c_float * 8)]
256
+
257
+
258
+ class AuPlaylistEntry(Structure):
259
+ _fields_ = [("path", c_char_p), ("title", c_char_p), ("duration", c_double), ("id", c_int64),
260
+ ("start_seconds", c_double), ("length_seconds", c_double), ("replaygain", AuReplayGain),
261
+ ("user_key", c_char_p)]
262
+
263
+
264
+ AuPlaylistCompareFn = CFUNCTYPE(c_int, POINTER(AuPlaylistEntry), POINTER(AuPlaylistEntry), c_void_p)
265
+
266
+
267
+ class AuPlaylistFile(Structure):
268
+ _fields_ = [("count", c_int), ("entries", POINTER(POINTER(AuPlaylistEntry)))]
269
+
270
+
271
+ class AuCueTrack(Structure):
272
+ _fields_ = [("number", c_int), ("path", c_char_p), ("start_seconds", c_double), ("length_seconds", c_double),
273
+ ("title", c_char_p), ("performer", c_char_p), ("songwriter", c_char_p), ("isrc", c_char_p),
274
+ ("replaygain", AuReplayGain)]
275
+
276
+
277
+ class AuCueSheet(Structure):
278
+ _fields_ = [("count", c_int), ("tracks", POINTER(POINTER(AuCueTrack))), ("title", c_char_p),
279
+ ("performer", c_char_p), ("genre", c_char_p), ("date", c_char_p)]
280
+
281
+
282
+ class AuLyricsLine(Structure):
283
+ _fields_ = [("time", c_double), ("text", c_char_p)]
284
+
285
+
286
+ class AuLyrics(Structure):
287
+ _fields_ = [("synced", c_bool), ("count", c_int), ("lines", POINTER(POINTER(AuLyricsLine))), ("text", c_char_p),
288
+ ("language", c_char_p), ("source", c_int)]
289
+
290
+
291
+ AuWaveformProgressFn = CFUNCTYPE(c_bool, c_double, c_void_p)
292
+
293
+
294
+ class AuWaveform(Structure):
295
+ _fields_ = [("count", c_int), ("seconds_per_point", c_double), ("duration", c_double), ("min", POINTER(c_float)),
296
+ ("max", POINTER(c_float)), ("rms", POINTER(c_float))]
297
+
298
+
299
+ # Every struct, for the layout test
300
+ STRUCTS = [AuEvent, AuFade, AuCrossfade, AuReplayGain, AuReplayGainSettings, AuNetworkSettings, AuTag, AuMediaInfo,
301
+ AuPicture, AuStatus, AuEqualizer, AuPeqBand, AuParametricEq, AuStereo, AuLimiter, AuCompressor, AuDeclick,
302
+ AuDeclip, AuCrossfeed, AuLoudness, AuLoudnessOptions, AuGainScanSettings, AuLevels, AuPlaylistEntry,
303
+ AuPlaylistFile, AuCueTrack, AuCueSheet, AuWaveform, AuLyricsLine, AuLyrics]
304
+
305
+
306
+ #+-----------------------------------------------------+
307
+ #| Functions |
308
+ #+-----------------------------------------------------+
309
+
310
+ _p = POINTER
311
+ _opaque = c_void_p
312
+ _FUNCTIONS = {
313
+ # ffaudio.h
314
+ "au_poll_event": (c_bool, [_p(AuEvent)]),
315
+ "au_wait_event": (c_bool, [_p(AuEvent), c_double]),
316
+ "au_play_options_create": (_opaque, []),
317
+ "au_play_options_free": (None, [_opaque]),
318
+ "au_play_options_set_range": (c_int, [_opaque, c_double, c_double]),
319
+ "au_play_options_set_filters": (c_int, [_opaque, c_char_p]),
320
+ "au_play_options_set_fade_in": (c_int, [_opaque, _p(AuFade)]),
321
+ "au_play_options_set_replaygain": (c_int, [_opaque, _p(AuReplayGain)]),
322
+ "au_play_options_set_http_headers": (c_int, [_opaque, c_char_p]),
323
+ "au_init": (c_int, [c_char_p, AuEventFn, c_void_p]),
324
+ "au_open_device": (c_int, []),
325
+ "au_shutdown": (c_int, []),
326
+ "au_set_device": (c_int, [c_char_p]),
327
+ "au_set_output_format": (c_int, [c_int, c_int]),
328
+ "au_list_devices": (_p(c_char_p), [_p(c_int)]),
329
+ "au_free_devices": (None, [_p(c_char_p), c_int]),
330
+ "au_get_device_name": (c_int, [_p(c_char), c_size_t]),
331
+ "au_play": (c_int32, [c_char_p, _opaque]),
332
+ "au_queue": (c_int32, [c_char_p, _opaque]),
333
+ "au_skip": (c_int, []),
334
+ "au_clear_queue": (c_int, []),
335
+ "au_stop": (c_int, []),
336
+ "au_pause": (c_int, [c_bool]),
337
+ "au_seek": (c_int, [c_double]),
338
+ "au_seek_fraction": (c_int, [c_double]),
339
+ "au_set_crossfade": (c_int, [_p(AuCrossfade)]),
340
+ "au_set_speed": (c_int, [c_double, c_bool]),
341
+ "au_set_volume": (c_int, [c_float]),
342
+ "au_set_muted": (c_int, [c_bool]),
343
+ "au_set_loop_count": (c_int, [c_int]),
344
+ "au_set_prepare_next": (c_int, [c_double]),
345
+ "au_set_network": (c_int, [_p(AuNetworkSettings)]),
346
+ "au_is_network_url": (c_bool, [c_char_p]),
347
+ "au_set_filters": (c_int, [c_char_p]),
348
+ "au_set_track_filters": (c_int, [c_int32, c_char_p]),
349
+ "au_set_source_filters": (c_int, [c_char_p]),
350
+ "au_send_filter_command": (c_int, [c_int32, c_char_p, c_char_p, c_char_p]),
351
+ "au_validate_filters": (c_int, [c_char_p]),
352
+ "au_set_downmix": (c_int, [c_int, c_char_p]),
353
+ "au_set_upmix": (c_int, [c_int, c_char_p]),
354
+ "au_set_replaygain": (c_int, [_p(AuReplayGainSettings)]),
355
+ "au_track_gain_db": (c_int, [c_int32, _p(c_double)]),
356
+ "au_gain_cache_set_file": (c_int, [c_char_p]),
357
+ "au_gain_cache_get_file": (c_int, [_p(c_char), c_size_t]),
358
+ "au_gain_cache_reload": (c_int, []),
359
+ "au_gain_cache_set": (c_int, [c_char_p, _p(AuReplayGain)]),
360
+ "au_gain_cache_get": (c_bool, [c_char_p, _p(AuReplayGain)]),
361
+ "au_gain_cache_remove": (c_int, [c_char_p]),
362
+ "au_gain_cache_clear": (c_int, []),
363
+ "au_gain_cache_count": (c_int, []),
364
+ "au_gain_cache_foreach": (c_int, [AuGainCacheVisitorFn, c_void_p]),
365
+ "au_probe": (_p(AuMediaInfo), [c_char_p, _p(c_int)]),
366
+ "au_track_info": (_p(AuMediaInfo), [c_int32]),
367
+ "au_media_info_release": (None, [_p(AuMediaInfo)]),
368
+ "au_media_tag": (c_char_p, [_p(AuMediaInfo), c_char_p]),
369
+ "au_media_picture": (_p(AuPicture), [c_char_p, c_int, _p(c_int)]),
370
+ "au_picture_release": (None, [_p(AuPicture)]),
371
+ "au_get_status": (None, [_p(AuStatus)]),
372
+ "au_get_version": (c_char_p, []),
373
+ "au_result_string": (c_char_p, [c_int]),
374
+ # ffaudio_filters.h
375
+ "au_fb_create": (_opaque, []),
376
+ "au_fb_free": (None, [_opaque]),
377
+ "au_fb_clear": (None, [_opaque]),
378
+ "au_fb_peek": (c_char_p, [_opaque]),
379
+ "au_fb_last_error": (c_char_p, [_opaque]),
380
+ "au_fb_add": (c_int, [_opaque, c_char_p]),
381
+ "au_filter_available": (c_bool, [c_char_p]),
382
+ "au_fb_add_volume_db": (c_int, [_opaque, c_char_p, c_double]),
383
+ "au_equalizer_defaults": (AuEqualizer, []),
384
+ "au_fb_add_equalizer": (c_int, [_opaque, c_char_p, _p(AuEqualizer)]),
385
+ "au_fb_add_parametric_eq": (c_int, [_opaque, c_char_p, _p(AuParametricEq)]),
386
+ "au_parametric_eq_parse": (c_int, [c_char_p, _p(AuParametricEq), _p(c_char), c_size_t]),
387
+ "au_fb_add_tone": (c_int, [_opaque, c_char_p, c_double, c_double]),
388
+ "au_stereo_defaults": (AuStereo, []),
389
+ "au_fb_add_stereo": (c_int, [_opaque, c_char_p, _p(AuStereo)]),
390
+ "au_limiter_defaults": (AuLimiter, []),
391
+ "au_fb_add_limiter": (c_int, [_opaque, c_char_p, _p(AuLimiter)]),
392
+ "au_compressor_defaults": (AuCompressor, []),
393
+ "au_compressor_night": (AuCompressor, []),
394
+ "au_fb_add_compressor": (c_int, [_opaque, c_char_p, _p(AuCompressor)]),
395
+ "au_declick_defaults": (AuDeclick, []),
396
+ "au_fb_add_declick": (c_int, [_opaque, c_char_p, _p(AuDeclick)]),
397
+ "au_declip_defaults": (AuDeclip, []),
398
+ "au_fb_add_declip": (c_int, [_opaque, c_char_p, _p(AuDeclip)]),
399
+ "au_crossfeed_defaults": (AuCrossfeed, []),
400
+ "au_fb_add_crossfeed": (c_int, [_opaque, c_char_p, _p(AuCrossfeed)]),
401
+ "au_fb_add_bs2b_profile": (c_int, [_opaque, c_char_p, c_int]),
402
+ "au_fb_add_bs2b": (c_int, [_opaque, c_char_p, c_int, c_int]),
403
+ # ffaudio_loudness.h
404
+ "au_loudness_measure": (c_int, [c_char_p, _p(AuLoudnessOptions), _p(_opaque)]),
405
+ "au_loudness_merge": (c_int, [_opaque, _opaque]),
406
+ "au_loudness_result": (c_int, [_opaque, _p(AuLoudness)]),
407
+ "au_loudness_file_count": (c_int, [_opaque]),
408
+ "au_loudness_meter_free": (None, [_opaque]),
409
+ "au_loudness_analyze": (c_int, [c_char_p, _p(AuLoudnessOptions), _p(AuLoudness)]),
410
+ "au_loudness_to_replaygain": (AuReplayGain, [_p(AuLoudness), _p(AuLoudness)]),
411
+ "au_gain_cache_scan": (c_int, [c_char_p, _p(AuLoudnessOptions), _p(AuReplayGain)]),
412
+ "au_set_gain_scan": (c_int, [_p(AuGainScanSettings)]),
413
+ "au_gain_scan_request": (c_int, [_p(c_char_p), c_int, c_int]),
414
+ "au_gain_scan_request_album": (c_int, [_p(c_char_p), c_int, c_int]),
415
+ "au_gain_scan_cancel": (None, []),
416
+ "au_gain_scan_pending": (c_int, []),
417
+ "au_gain_scan_stop": (c_int, []),
418
+ "au_lyrics_read": (_p(AuLyrics), [c_char_p, _p(c_int)]),
419
+ "au_lyrics_parse": (_p(AuLyrics), [c_char_p, c_size_t, _p(c_int)]),
420
+ "au_lyrics_line_at": (c_int, [_p(AuLyrics), c_double]),
421
+ "au_lyrics_release": (None, [_p(AuLyrics)]),
422
+ # ffaudio_meters.h
423
+ "au_get_levels": (c_int, [c_double, _p(AuLevels)]),
424
+ "au_spectrum_create": (_opaque, [c_int]),
425
+ "au_spectrum_read": (c_int, [_opaque, c_int, _p(c_float), c_int, _p(c_int)]),
426
+ "au_spectrum_bands": (c_int, [_p(c_float), c_int, c_int, c_double, c_double, _p(c_float), c_int]),
427
+ "au_spectrum_free": (None, [_opaque]),
428
+ # ffaudio_playlist.h
429
+ "au_playlist_read": (_p(AuPlaylistFile), [c_char_p, _p(c_int)]),
430
+ "au_playlist_parse": (_p(AuPlaylistFile), [c_char_p, c_size_t, c_char_p, _p(c_int)]),
431
+ "au_playlist_file_release": (None, [_p(AuPlaylistFile)]),
432
+ "au_cue_read": (_p(AuCueSheet), [c_char_p, _p(c_int)]),
433
+ "au_cue_parse": (_p(AuCueSheet), [c_char_p, c_size_t, c_char_p, _p(c_int)]),
434
+ "au_cue_release": (None, [_p(AuCueSheet)]),
435
+ "au_playlist_create": (_opaque, []),
436
+ "au_playlist_copy": (_opaque, [_opaque]),
437
+ "au_playlist_free": (None, [_opaque]),
438
+ "au_playlist_add": (c_int64, [_opaque, c_int, c_char_p]),
439
+ "au_playlist_add_from": (c_int64, [_opaque, c_int, _opaque, c_int64]),
440
+ "au_playlist_add_list": (c_int, [_opaque, c_int, _opaque]),
441
+ "au_playlist_add_file": (c_int, [_opaque, c_int, _p(AuPlaylistFile)]),
442
+ "au_playlist_add_cue": (c_int, [_opaque, c_int, _p(AuCueSheet)]),
443
+ "au_playlist_remove": (c_int, [_opaque, c_int64]),
444
+ "au_playlist_clear": (c_int, [_opaque]),
445
+ "au_playlist_move": (c_int, [_opaque, c_int64, c_int]),
446
+ "au_playlist_set_order": (c_int, [_opaque, _p(c_int64), c_int]),
447
+ "au_playlist_set_title": (c_int, [_opaque, c_int64, c_char_p]),
448
+ "au_playlist_set_duration": (c_int, [_opaque, c_int64, c_double]),
449
+ "au_playlist_set_range": (c_int, [_opaque, c_int64, c_double, c_double]),
450
+ "au_playlist_set_replaygain": (c_int, [_opaque, c_int64, _p(AuReplayGain)]),
451
+ "au_playlist_set_user_key": (c_int, [_opaque, c_int64, c_char_p]),
452
+ "au_playlist_count": (c_int, [_opaque]),
453
+ "au_playlist_at": (_p(AuPlaylistEntry), [_opaque, c_int]),
454
+ "au_playlist_find": (_p(AuPlaylistEntry), [_opaque, c_int64]),
455
+ "au_playlist_index_of": (c_int, [_opaque, c_int64]),
456
+ "au_playlist_sort": (c_int, [_opaque, c_int, c_bool]),
457
+ "au_playlist_sort_with": (c_int, [_opaque, AuPlaylistCompareFn, c_void_p]),
458
+ "au_play_queue_create": (_opaque, []),
459
+ "au_play_queue_free": (None, [_opaque]),
460
+ "au_play_queue_set_playlist": (c_int, [_opaque, _opaque, c_int64]),
461
+ "au_play_queue_playlist": (_opaque, [_opaque]),
462
+ "au_play_queue_up_next": (_opaque, [_opaque]),
463
+ "au_play_queue_set_shuffle": (c_int, [_opaque, c_bool]),
464
+ "au_play_queue_shuffled": (c_bool, [_opaque]),
465
+ "au_play_queue_set_repeat": (c_int, [_opaque, c_int]),
466
+ "au_play_queue_set_history_size": (c_int, [_opaque, c_int]),
467
+ "au_play_queue_set_clear_on_new_playlist": (c_int, [_opaque, c_bool]),
468
+ "au_play_queue_set_shuffle_seed": (c_int, [_opaque, c_uint64]),
469
+ "au_play_queue_current": (_p(AuPlaylistEntry), [_opaque]),
470
+ "au_play_queue_peek_next": (_p(AuPlaylistEntry), [_opaque]),
471
+ "au_play_queue_set_current": (c_int, [_opaque, c_int64]),
472
+ "au_play_queue_next": (_p(AuPlaylistEntry), [_opaque]),
473
+ "au_play_queue_previous": (_p(AuPlaylistEntry), [_opaque]),
474
+ "au_play_queue_order_count": (c_int, [_opaque]),
475
+ "au_play_queue_order_at": (_p(AuPlaylistEntry), [_opaque, c_int]),
476
+ "au_play_queue_order_position": (c_int, [_opaque]),
477
+ "au_play_queue_move": (c_int, [_opaque, c_int64, c_int]),
478
+ "au_play_queue_keep_order": (c_int, [_opaque]),
479
+ "au_play_queue_set_order": (c_int, [_opaque, _p(c_int64), c_int]),
480
+ "au_play_queue_history_count": (c_int, [_opaque]),
481
+ "au_play_queue_history_at": (_p(AuPlaylistEntry), [_opaque, c_int]),
482
+ "au_play_queue_clear_history": (c_int, [_opaque]),
483
+ # ffaudio_decoder.h
484
+ "au_decode_options_create": (_opaque, []),
485
+ "au_decode_options_free": (None, [_opaque]),
486
+ "au_decode_options_set_format": (c_int, [_opaque, c_int, c_int]),
487
+ "au_decode_options_set_range": (c_int, [_opaque, c_double, c_double]),
488
+ "au_decode_options_set_filters": (c_int, [_opaque, c_char_p]),
489
+ "au_decode_options_set_http_headers": (c_int, [_opaque, c_char_p]),
490
+ "au_decoder_open": (_opaque, [c_char_p, _opaque, _p(c_int)]),
491
+ "au_decoder_read": (c_int, [_opaque, _p(c_float), c_int]),
492
+ "au_decoder_seek": (c_int, [_opaque, c_double]),
493
+ "au_decoder_channels": (c_int, [_opaque]),
494
+ "au_decoder_sample_rate": (c_int, [_opaque]),
495
+ "au_decoder_duration": (c_double, [_opaque]),
496
+ "au_decoder_position": (c_double, [_opaque]),
497
+ "au_decoder_info": (_p(AuMediaInfo), [_opaque]),
498
+ "au_decoder_interrupt": (None, [_opaque]),
499
+ "au_decoder_close": (None, [_opaque]),
500
+ "au_waveform_analyze": (_p(AuWaveform), [c_char_p, _opaque, c_int, AuWaveformProgressFn, c_void_p, _p(c_int)]),
501
+ "au_waveform_release": (None, [_p(AuWaveform)]),
502
+ }
503
+
504
+ def _missing(name):
505
+ def call(*args, **kwargs):
506
+ raise NotImplementedError(f"{name} is not in libffaudio {lib.au_get_version().decode()}: it needs a newer 4.x")
507
+ return call
508
+
509
+
510
+ # Minor versions only add functions: bindings newer than the library still load, and a function the library does not
511
+ # have (yet) raises NotImplementedError when called, as it would fail to resolve in C# (MISSING lists them)
512
+ MISSING = []
513
+ for _name, (_res, _args) in _FUNCTIONS.items():
514
+ try:
515
+ _f = getattr(lib, _name)
516
+ except AttributeError:
517
+ MISSING.append(_name)
518
+ setattr(lib, _name, _missing(_name))
519
+ continue
520
+ _f.restype = _res
521
+ _f.argtypes = _args
522
+
523
+ FUNCTION_NAMES = sorted(_FUNCTIONS)
524
+
525
+ _major = int(lib.au_get_version().decode().split(".")[0])
526
+ if _major != ABI_MAJOR:
527
+ raise ImportError(f"libffaudio {lib.au_get_version().decode()} found, these bindings are for {ABI_MAJOR}.x")
@@ -0,0 +1,80 @@
1
+ Metadata-Version: 2.1
2
+ Name: ffaudio
3
+ Version: 4.2.0
4
+ Summary: Python bindings (ctypes) for ffaudio, the music playback library on FFmpeg and SDL2
5
+ Home-page: https://github.com/Odalith/ffAudio
6
+ License: LGPL-2.1-or-later
7
+ Requires-Python: >=3.9
8
+ Classifier: License :: OSI Approved :: GNU Lesser General Public License v2 or later (LGPLv2+)
9
+ Classifier: Programming Language :: Python :: 3
10
+ Classifier: Topic :: Multimedia :: Sound/Audio :: Players
11
+ Description-Content-Type: text/markdown
12
+
13
+ # ffaudio for Python
14
+
15
+ Bindings for ffaudio 4 with `ctypes`: nothing to compile, any Python 3.9+. They cover all five public headers.
16
+
17
+ ```python
18
+ import ffaudio
19
+
20
+ ffaudio.init("My Player")
21
+ ffaudio.set_replaygain(ffaudio.ReplayGainSettings(mode=ffaudio.ReplayGainMode.TRACK, preamp_db=4))
22
+ ffaudio.play("/music/song.flac", ffaudio.PlayOptions(start_seconds=30))
23
+
24
+ while True:
25
+ match ffaudio.wait_event(1.0):
26
+ case ffaudio.TrackStarted(handle=h):
27
+ print("playing", ffaudio.track_info(h).title)
28
+ case ffaudio.PrepareNext():
29
+ ffaudio.queue(next_song()) # gapless, or crossfaded
30
+ case ffaudio.TrackEnded(error=err, message=msg) if err:
31
+ print("could not play:", msg)
32
+ ```
33
+
34
+ ## Installing
35
+
36
+ From 4.2, `pip install ffaudio` installs the bindings with ffaudio, FFmpeg (an LGPL build for playback) and soxr
37
+ inside, for Windows x64, Linux x64 and arm64, and macOS (Intel 10.15+, Apple silicon 11+); on Windows and macOS SDL2
38
+ too. On Linux SDL2 comes from the system (`libsdl2-2.0-0` on Debian/Ubuntu, `sdl2` on Arch/Fedora), and glibc 2.39
39
+ or newer is needed (Ubuntu 24.04, Debian 13, Fedora 40). There is no source package: the wheels carry the release's
40
+ libraries.
41
+
42
+ ## Finding the library
43
+
44
+ In this order:
45
+ 1. `FFAUDIO_LIBRARY`, the path to `libffaudio.so.4` / `libffaudio.dll`.
46
+ 2. Inside the package (`ffaudio/_libs`), as the wheels from PyPI have it.
47
+ 3. Next to the package, as in a release archive: `python/ffaudio` with the library in `lib/` (or `bin/`).
48
+ 4. The system's library path, for an installed ffaudio.
49
+
50
+ The bindings check that the library is version 4.
51
+
52
+ ## Differences from the C API
53
+
54
+ The names are the C names without `au_`. `ffaudio.h` and the other headers say what each one does.
55
+
56
+ - **Errors** raise `ffaudio.Error`. Its `.code` is the `AU_RESULT`, and `str()` says what went wrong, including a
57
+ filter builder's reason.
58
+ - **Value structs** are dataclasses: `Fade`, `Crossfade`, `ReplayGain`, `Equalizer`, `Limiter`, and so on. Their
59
+ defaults are read from the library. **Results** are copied into Python objects (`MediaInfo`, `Status`, `CueSheet`,
60
+ `Levels`), so nothing needs releasing.
61
+ - **Per-track options** are a `PlayOptions` dataclass, turned into an `AuPlayOptions` for each `play()`/`queue()`.
62
+ - **Events** are polled: `wait_event()` or `poll_event()`, on a thread of your choice. Each event is its own class
63
+ (`TrackEnded`, `PrepareNext`, `Device`, ...), ready for `match`.
64
+ No Python runs on ffaudio's threads, except callbacks you pass yourself (`GainScanSettings.on_cached`, a custom fade
65
+ curve, a loudness progress function). Keep those short.
66
+ - **`FilterBuilder`** chains: `FilterBuilder().add_equalizer(eq, name="eq").add_limiter().string`.
67
+ - **Strings** are `str` in and out (UTF-8).
68
+
69
+ `ffaudio._native` is the C API one to one (ctypes structs and prototypes), for anything the Pythonic layer leaves out.
70
+
71
+ ## Tests
72
+
73
+ ```sh
74
+ FFAUDIO_LIBRARY=build/libffaudio.so.4 FFAUDIO_LAYOUT=build/ffaudio_layout FFAUDIO_FIXTURES=build/fixtures \
75
+ SDL_AUDIODRIVER=dummy python3 -m unittest discover -s bindings/python/tests
76
+ ```
77
+ CTest runs them as `python_bindings`. The layout test compares every struct's size and every field's offset with what
78
+ the C compiler says (`tests/layout.c`). Run `tests/make_layout.py` after changing a struct in `_native.py`.
79
+
80
+ The player in `player/` is a complete program built on these bindings.
@@ -0,0 +1,32 @@
1
+ ffaudio/__init__.py,sha256=rZjkfDoRjX5Qz-L_MPQq3sPR9suX_VXy7iNXdlT6Rm4,56322
2
+ ffaudio/_native.py,sha256=GY5-QOk-_ICw7Atqd0dyAUi5AKCA7u1H4O9atiAPBIw,23838
3
+ ffaudio/_libs/SDL2.dll,sha256=PHAb1yivgT8ch9ysrruLSf7_AqCiCy4QtD6nKLYCyeQ,3035793
4
+ ffaudio/_libs/avcodec-63.dll,sha256=rciE_Y1zzlmKXqIG5MRxXdKk62OjQCccTk0fNaMIoCw,6109184
5
+ ffaudio/_libs/avfilter-12.dll,sha256=OIjcx1HRgDWR0Yr_is-sPz4iqkkTdU6UU2qvpGAUlKc,1312256
6
+ ffaudio/_libs/avformat-63.dll,sha256=pbLJ3EbzIqi4W78tl6rOuWKsQEAMsi_d6GAzs3S7Sw8,1835008
7
+ ffaudio/_libs/avutil-61.dll,sha256=MHwcMhVTto6LcRDvkqbeV0o5anLdX7MroGF1zNYsGcc,1055232
8
+ ffaudio/_libs/libffaudio.dll,sha256=FG58HI4WxoY3P8WqXw7yFs4thQtSO9XIZPVgsUbv0XI,353444
9
+ ffaudio/_libs/libsoxr.dll,sha256=EA0TrKynAFy2oHzORN3VWfTf_GcoXLbLyGMq9plmDFg,309760
10
+ ffaudio/_libs/libwinpthread-1.dll,sha256=SlvR7b_fdxvsRDV18GrJHmrnK818GXXbAQU0k2EIcco,73341
11
+ ffaudio/_libs/libz-1.dll,sha256=k0EDxQYjMCVIoc9m-8IvACnk60VWNDJSpQXi_ABeg18,148154
12
+ ffaudio/_libs/swresample-7.dll,sha256=Kqi19VNQDSyT5E51xKW8umK-WeAebPhVDZLFQvypcYk,180736
13
+ ffaudio/_libs/licenses/README.txt,sha256=DbnbUgnDmPhiTmtihxg4EiBoXf5BQ6tiKglsgXEKJdE,1497
14
+ ffaudio/_libs/licenses/SDL2/BUILD.txt,sha256=namEwKNYKkOsNjRC41gizRriC9QRH2ZdZ5LtKDaEqkw,108
15
+ ffaudio/_libs/licenses/SDL2/LICENSE.txt,sha256=l_NbMCs2FoDsHokeldLVIJe7lav_NhQ0kW2Z3BMF8Sc,884
16
+ ffaudio/_libs/licenses/bs2b/AUTHORS,sha256=BBZ1qxmFLdpYXK-iqMwIQPyW5f63UOqYHY4Ff0Fl7SQ,137
17
+ ffaudio/_libs/licenses/bs2b/BUILD.txt,sha256=hZCiIHQXUIMq74h-IEA3MN1v4Z1sLIy3W2G64aHVInA,68
18
+ ffaudio/_libs/licenses/bs2b/COPYING,sha256=39Wo19xQFEe_DViw_J74WrnnE5Y9fc9FmJet76THEMo,1059
19
+ ffaudio/_libs/licenses/ffaudio/license.txt,sha256=Hn5rrlpb3jLxrlp8N6CC0asDz4k1T3-TasQL6eOaZTE,27032
20
+ ffaudio/_libs/licenses/ffmpeg/BUILD.txt,sha256=m_m520HZGAUPO2CFNYaB-oZR89Gb04NGYfz-4PRYkVc,4171
21
+ ffaudio/_libs/licenses/ffmpeg/COPYING.LGPLv2.1,sha256=JGBBtuz5vDLXGKYsV4d8eLXrOXtkZ-dO164mJqsYnDA,26517
22
+ ffaudio/_libs/licenses/ffmpeg/LICENSE.md,sha256=Lh0Wxy_XThIGN3Y3HadXMi-Ld1iThlMvT9hjS9594a8,4346
23
+ ffaudio/_libs/licenses/libwinpthread/COPYING,sha256=YyY2FM3Sny-Ty6hemS8EGzH5_HtAM2kvMSaUiaihsXc,2883
24
+ ffaudio/_libs/licenses/soxr/BUILD.txt,sha256=NhXRbjI0OXpuo9DCYHZ_3yR9Dn3Nld1IuhW0ICDpBKQ,268
25
+ ffaudio/_libs/licenses/soxr/COPYING.LGPL,sha256=8vEYuQKewYcblTY57MRmUbL8e2LilebPPvKsTJoFizM,26432
26
+ ffaudio/_libs/licenses/soxr/LICENCE,sha256=3JhnY0H9zSnZ8nnJZ51qdSiHhbF03tjRsuMWw2YWYTU,1024
27
+ ffaudio/_libs/licenses/soxr/ccrw2.h,sha256=pV2zDSDPNiCgOEANBOfXIaOuZcXLwjUgwuJmNjQ92TY,2336
28
+ ffaudio/_libs/licenses/zlib/LICENSE,sha256=4y_04A2dlJMFN2NSkdo55-YScDM0v2_ejH8Whv6KRaI,1002
29
+ ffaudio-4.2.0.dist-info/METADATA,sha256=6sBd_HSAXZxqG_W-fzs0IQi9NkCKyPtkWDPDR83cKKc,3893
30
+ ffaudio-4.2.0.dist-info/WHEEL,sha256=vAvnci1Fk4ao0jhNhupjtH9ABmvmoEOm6gMP064PhP8,101
31
+ ffaudio-4.2.0.dist-info/top_level.txt,sha256=oy9LYM5C7nhdnovi4278oB1iq4T0p-ReRwg-2GTptvo,8
32
+ ffaudio-4.2.0.dist-info/RECORD,,
@@ -0,0 +1,4 @@
1
+ Wheel-Version: 1.0
2
+ Generator: ffaudio build_wheels.py
3
+ Root-Is-Purelib: false
4
+ Tag: py3-none-win_amd64
@@ -0,0 +1 @@
1
+ ffaudio