opuslib-next 1.3.0__tar.gz → 1.3.2__tar.gz
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.
- {opuslib_next-1.3.0 → opuslib_next-1.3.2}/.github/workflows/ci.yml +0 -14
- {opuslib_next-1.3.0 → opuslib_next-1.3.2}/.github/workflows/release.yml +0 -14
- opuslib_next-1.3.2/.gitignore +9 -0
- {opuslib_next-1.3.0 → opuslib_next-1.3.2}/PKG-INFO +5 -3
- {opuslib_next-1.3.0 → opuslib_next-1.3.2}/README.md +3 -1
- {opuslib_next-1.3.0 → opuslib_next-1.3.2}/benchmarks/compare_versions.py +4 -4
- {opuslib_next-1.3.0 → opuslib_next-1.3.2}/benchmarks/render_summary.py +0 -2
- {opuslib_next-1.3.0 → opuslib_next-1.3.2}/opuslib_next/__init__.py +3 -12
- {opuslib_next-1.3.0 → opuslib_next-1.3.2}/opuslib_next/api/__init__.py +2 -11
- {opuslib_next-1.3.0 → opuslib_next-1.3.2}/opuslib_next/api/ctl.py +7 -15
- {opuslib_next-1.3.0 → opuslib_next-1.3.2}/opuslib_next/api/decoder.py +8 -16
- {opuslib_next-1.3.0 → opuslib_next-1.3.2}/opuslib_next/api/encoder.py +2 -11
- {opuslib_next-1.3.0 → opuslib_next-1.3.2}/opuslib_next/api/info.py +1 -10
- {opuslib_next-1.3.0 → opuslib_next-1.3.2}/opuslib_next/api/multistream_decoder.py +7 -15
- {opuslib_next-1.3.0 → opuslib_next-1.3.2}/opuslib_next/api/multistream_encoder.py +2 -11
- {opuslib_next-1.3.0 → opuslib_next-1.3.2}/opuslib_next/api/projection_decoder.py +7 -15
- {opuslib_next-1.3.0 → opuslib_next-1.3.2}/opuslib_next/api/projection_encoder.py +2 -11
- {opuslib_next-1.3.0 → opuslib_next-1.3.2}/opuslib_next/classes.py +0 -7
- {opuslib_next-1.3.0 → opuslib_next-1.3.2}/opuslib_next/constants.py +0 -7
- {opuslib_next-1.3.0 → opuslib_next-1.3.2}/opuslib_next/exceptions.py +0 -7
- {opuslib_next-1.3.0 → opuslib_next-1.3.2}/pyproject.toml +2 -6
- {opuslib_next-1.3.0 → opuslib_next-1.3.2}/tests/decoder.py +3 -15
- {opuslib_next-1.3.0 → opuslib_next-1.3.2}/tests/encoder.py +1 -19
- {opuslib_next-1.3.0 → opuslib_next-1.3.2}/tests/hl_decoder.py +9 -11
- {opuslib_next-1.3.0 → opuslib_next-1.3.2}/tests/hl_encoder.py +0 -9
- {opuslib_next-1.3.0 → opuslib_next-1.3.2}/tests/hl_multistream.py +5 -8
- {opuslib_next-1.3.0 → opuslib_next-1.3.2}/tests/hl_projection.py +5 -8
- {opuslib_next-1.3.0 → opuslib_next-1.3.2}/tests/multistream.py +1 -6
- {opuslib_next-1.3.0 → opuslib_next-1.3.2}/tests/projection.py +1 -6
- {opuslib_next-1.3.0 → opuslib_next-1.3.2}/tests/test_exceptions.py +0 -3
- opuslib_next-1.3.2/uv.lock +156 -0
- opuslib_next-1.3.0/.gitignore +0 -34
- opuslib_next-1.3.0/Makefile +0 -19
- opuslib_next-1.3.0/tests/__init__.py +0 -8
- opuslib_next-1.3.0/uv.lock +0 -695
- {opuslib_next-1.3.0 → opuslib_next-1.3.2}/.github/workflows/performance.yml +0 -0
- {opuslib_next-1.3.0 → opuslib_next-1.3.2}/LICENSE +0 -0
|
@@ -40,20 +40,6 @@ jobs:
|
|
|
40
40
|
- name: Sync dependencies
|
|
41
41
|
run: uv sync --dev --frozen --python ${{ matrix.python-version }}
|
|
42
42
|
|
|
43
|
-
- name: Verify libopus APIs
|
|
44
|
-
run: |
|
|
45
|
-
uv run --python ${{ matrix.python-version }} python - <<'PY'
|
|
46
|
-
import opuslib_next.api.multistream_decoder as msd
|
|
47
|
-
import opuslib_next.api.multistream_encoder as mse
|
|
48
|
-
import opuslib_next.api.projection_decoder as pd
|
|
49
|
-
import opuslib_next.api.projection_encoder as pe
|
|
50
|
-
|
|
51
|
-
print("multistream encoder size:", mse.get_size(1, 1))
|
|
52
|
-
print("multistream decoder size:", msd.get_size(1, 1))
|
|
53
|
-
print("projection encoder size:", pe.get_size(4, 3))
|
|
54
|
-
print("projection decoder size:", pd.get_size(4, 2, 2))
|
|
55
|
-
PY
|
|
56
|
-
|
|
57
43
|
- name: Run tests
|
|
58
44
|
run: uv run --python ${{ matrix.python-version }} pytest -q
|
|
59
45
|
|
|
@@ -36,20 +36,6 @@ jobs:
|
|
|
36
36
|
- name: Sync dependencies
|
|
37
37
|
run: uv sync --dev --frozen --python 3.12
|
|
38
38
|
|
|
39
|
-
- name: Verify libopus APIs
|
|
40
|
-
run: |
|
|
41
|
-
uv run --python 3.12 python - <<'PY'
|
|
42
|
-
import opuslib_next.api.multistream_decoder as msd
|
|
43
|
-
import opuslib_next.api.multistream_encoder as mse
|
|
44
|
-
import opuslib_next.api.projection_decoder as pd
|
|
45
|
-
import opuslib_next.api.projection_encoder as pe
|
|
46
|
-
|
|
47
|
-
print("multistream encoder size:", mse.get_size(1, 1))
|
|
48
|
-
print("multistream decoder size:", msd.get_size(1, 1))
|
|
49
|
-
print("projection encoder size:", pe.get_size(4, 3))
|
|
50
|
-
print("projection decoder size:", pd.get_size(4, 2, 2))
|
|
51
|
-
PY
|
|
52
|
-
|
|
53
39
|
- name: Run tests
|
|
54
40
|
run: uv run --python 3.12 pytest -q
|
|
55
41
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
Metadata-Version: 2.
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
2
|
Name: opuslib-next
|
|
3
|
-
Version: 1.3.
|
|
3
|
+
Version: 1.3.2
|
|
4
4
|
Summary: Python bindings to the libopus, IETF low-delay audio codec
|
|
5
5
|
Project-URL: Homepage, https://github.com/kalicyh/opuslib-next
|
|
6
6
|
Project-URL: Documentation, https://github.com/kalicyh/opuslib-next
|
|
@@ -25,7 +25,9 @@ Classifier: Topic :: Software Development :: Libraries
|
|
|
25
25
|
Requires-Python: >=3.10
|
|
26
26
|
Description-Content-Type: text/markdown
|
|
27
27
|
|
|
28
|
-
#
|
|
28
|
+
# opuslib-next
|
|
29
|
+
|
|
30
|
+
[](https://pypistats.org/packages/opuslib-next)
|
|
29
31
|
|
|
30
32
|
Python bindings to the libopus, IETF low-delay audio codec.
|
|
31
33
|
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
#!/usr/bin/env python3
|
|
2
|
-
|
|
3
1
|
from __future__ import annotations
|
|
4
2
|
|
|
5
3
|
import argparse
|
|
@@ -12,6 +10,7 @@ from pathlib import Path
|
|
|
12
10
|
|
|
13
11
|
BENCHMARK_CODE = r"""
|
|
14
12
|
import array
|
|
13
|
+
from importlib.metadata import version
|
|
15
14
|
import json
|
|
16
15
|
import math
|
|
17
16
|
import statistics
|
|
@@ -101,7 +100,8 @@ results = [
|
|
|
101
100
|
]
|
|
102
101
|
|
|
103
102
|
print(json.dumps({
|
|
104
|
-
"package_version":
|
|
103
|
+
"package_version": version("opuslib-next"),
|
|
104
|
+
"package_path": opuslib_next.__file__,
|
|
105
105
|
"results": results,
|
|
106
106
|
}))
|
|
107
107
|
"""
|
|
@@ -149,7 +149,7 @@ def install_requirement(
|
|
|
149
149
|
|
|
150
150
|
|
|
151
151
|
def run_benchmark(python_path: Path) -> dict:
|
|
152
|
-
completed = run([str(python_path), "-c", BENCHMARK_CODE])
|
|
152
|
+
completed = run([str(python_path), "-I", "-c", BENCHMARK_CODE])
|
|
153
153
|
return json.loads(completed.stdout)
|
|
154
154
|
|
|
155
155
|
|
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
#!/usr/bin/env python
|
|
2
|
-
# -*- coding: utf-8 -*-
|
|
3
|
-
|
|
4
1
|
# OpusLib Python Module.
|
|
5
2
|
|
|
6
3
|
"""
|
|
@@ -16,13 +13,11 @@ Python bindings to the libopus, IETF low-delay audio codec
|
|
|
16
13
|
|
|
17
14
|
"""
|
|
18
15
|
|
|
19
|
-
from .exceptions import OpusError
|
|
20
|
-
|
|
21
|
-
from .constants import * # NOQA
|
|
16
|
+
from .exceptions import OpusError
|
|
22
17
|
|
|
23
|
-
from .constants import
|
|
18
|
+
from .constants import *
|
|
24
19
|
|
|
25
|
-
from .classes import (
|
|
20
|
+
from .classes import (
|
|
26
21
|
Decoder,
|
|
27
22
|
Encoder,
|
|
28
23
|
MultiStreamDecoder,
|
|
@@ -30,7 +25,3 @@ from .classes import ( # NOQA
|
|
|
30
25
|
ProjectionDecoder,
|
|
31
26
|
ProjectionEncoder,
|
|
32
27
|
)
|
|
33
|
-
|
|
34
|
-
__author__ = 'kalicyh <kalicyh@qq.com>'
|
|
35
|
-
__copyright__ = 'Copyright (c) 2025, Kalicyh'
|
|
36
|
-
__license__ = 'BSD 3-Clause License'
|
|
@@ -1,18 +1,9 @@
|
|
|
1
|
-
#!/usr/bin/env python
|
|
2
|
-
# -*- coding: utf-8 -*-
|
|
3
|
-
# pylint: disable=invalid-name
|
|
4
|
-
#
|
|
5
|
-
|
|
6
1
|
"""OpusLib Package."""
|
|
7
2
|
|
|
8
|
-
import ctypes
|
|
3
|
+
import ctypes
|
|
9
4
|
import os
|
|
10
5
|
import platform
|
|
11
|
-
from ctypes.util import find_library
|
|
12
|
-
|
|
13
|
-
__author__ = "kalicyh <kalicyh@qq.com>"
|
|
14
|
-
__copyright__ = "Copyright (c) 2025, Kalicyh"
|
|
15
|
-
__license__ = "BSD 3-Clause License"
|
|
6
|
+
from ctypes.util import find_library
|
|
16
7
|
|
|
17
8
|
|
|
18
9
|
lib_location = find_library("opus")
|
|
@@ -1,25 +1,17 @@
|
|
|
1
|
-
#!/usr/bin/env python
|
|
2
|
-
# -*- coding: utf-8 -*-
|
|
3
|
-
# pylint: disable=invalid-name
|
|
4
|
-
|
|
5
1
|
"""CTL macros rewritten to Python
|
|
6
2
|
|
|
7
3
|
Usage example:
|
|
8
4
|
|
|
9
|
-
>>> import
|
|
10
|
-
>>> import
|
|
11
|
-
>>> dec =
|
|
12
|
-
>>>
|
|
13
|
-
>>> gain_value =
|
|
5
|
+
>>> import opuslib_next.api.decoder
|
|
6
|
+
>>> import opuslib_next.api.ctl
|
|
7
|
+
>>> dec = opuslib_next.api.decoder.create_state(48000, 2)
|
|
8
|
+
>>> opuslib_next.api.decoder.decoder_ctl(dec, opuslib_next.api.ctl.set_gain, -15)
|
|
9
|
+
>>> gain_value = opuslib_next.api.decoder.decoder_ctl(dec, opuslib_next.api.ctl.get_gain)
|
|
14
10
|
|
|
15
11
|
"""
|
|
16
12
|
|
|
17
|
-
__author__ = 'kalicyh <kalicyh@qq.com>'
|
|
18
|
-
__copyright__ = 'Copyright (c) 2025, Kalicyh'
|
|
19
|
-
__license__ = 'BSD 3-Clause License'
|
|
20
|
-
|
|
21
13
|
|
|
22
|
-
import ctypes
|
|
14
|
+
import ctypes
|
|
23
15
|
|
|
24
16
|
import opuslib_next.api
|
|
25
17
|
import opuslib_next.exceptions
|
|
@@ -72,7 +64,7 @@ def ctl_set(request):
|
|
|
72
64
|
#
|
|
73
65
|
|
|
74
66
|
# Resets the codec state to be equivalent to a freshly initialized state
|
|
75
|
-
reset_state = query(opuslib_next.RESET_STATE)
|
|
67
|
+
reset_state = query(opuslib_next.RESET_STATE)
|
|
76
68
|
|
|
77
69
|
# Gets the final state of the codec's entropy coder
|
|
78
70
|
get_final_range = get(
|
|
@@ -1,23 +1,13 @@
|
|
|
1
|
-
#!/usr/bin/env python
|
|
2
|
-
# -*- coding: utf-8 -*-
|
|
3
|
-
# pylint: disable=invalid-name,too-few-public-methods
|
|
4
|
-
#
|
|
5
|
-
|
|
6
1
|
"""
|
|
7
2
|
CTypes mapping between libopus functions and Python.
|
|
8
3
|
"""
|
|
9
4
|
|
|
10
|
-
import
|
|
11
|
-
import ctypes # type: ignore
|
|
5
|
+
import ctypes
|
|
12
6
|
import typing
|
|
13
7
|
|
|
14
8
|
import opuslib_next
|
|
15
9
|
import opuslib_next.api
|
|
16
10
|
|
|
17
|
-
__author__ = 'kalicyh <kalicyh@qq.com>'
|
|
18
|
-
__copyright__ = 'Copyright (c) 2025, Kalicyh'
|
|
19
|
-
__license__ = 'BSD 3-Clause License'
|
|
20
|
-
|
|
21
11
|
|
|
22
12
|
class Decoder(ctypes.Structure):
|
|
23
13
|
"""Opus decoder state.
|
|
@@ -95,7 +85,7 @@ def packet_get_bandwidth(data: bytes) -> typing.Union[int, typing.Any]:
|
|
|
95
85
|
return result
|
|
96
86
|
|
|
97
87
|
|
|
98
|
-
libopus_packet_get_nb_channels = opuslib_next.api.libopus.opus_packet_get_nb_channels
|
|
88
|
+
libopus_packet_get_nb_channels = opuslib_next.api.libopus.opus_packet_get_nb_channels
|
|
99
89
|
# `argtypes` must be a sequence (,) of types!
|
|
100
90
|
libopus_packet_get_nb_channels.argtypes = (ctypes.c_char_p,)
|
|
101
91
|
libopus_packet_get_nb_channels.restype = ctypes.c_int
|
|
@@ -215,7 +205,7 @@ libopus_decode.restype = ctypes.c_int
|
|
|
215
205
|
|
|
216
206
|
|
|
217
207
|
# FIXME: Remove typing.Any once we have a stub for ctypes
|
|
218
|
-
def decode(
|
|
208
|
+
def decode(
|
|
219
209
|
decoder_state: ctypes.Structure,
|
|
220
210
|
opus_data: bytes,
|
|
221
211
|
length: int,
|
|
@@ -248,7 +238,8 @@ def decode( # pylint: disable=too-many-arguments
|
|
|
248
238
|
if result < 0:
|
|
249
239
|
raise opuslib_next.exceptions.OpusError(result)
|
|
250
240
|
|
|
251
|
-
|
|
241
|
+
byte_count = result * channels * ctypes.sizeof(ctypes.c_int16)
|
|
242
|
+
return ctypes.string_at(pcm, byte_count)
|
|
252
243
|
|
|
253
244
|
|
|
254
245
|
libopus_decode_float = opuslib_next.api.libopus.opus_decode_float
|
|
@@ -264,7 +255,7 @@ libopus_decode_float.restype = ctypes.c_int
|
|
|
264
255
|
|
|
265
256
|
|
|
266
257
|
# FIXME: Remove typing.Any once we have a stub for ctypes
|
|
267
|
-
def decode_float(
|
|
258
|
+
def decode_float(
|
|
268
259
|
decoder_state: ctypes.Structure,
|
|
269
260
|
opus_data: bytes,
|
|
270
261
|
length: int,
|
|
@@ -296,7 +287,8 @@ def decode_float( # pylint: disable=too-many-arguments
|
|
|
296
287
|
if result < 0:
|
|
297
288
|
raise opuslib_next.exceptions.OpusError(result)
|
|
298
289
|
|
|
299
|
-
|
|
290
|
+
byte_count = result * channels * ctypes.sizeof(ctypes.c_float)
|
|
291
|
+
return ctypes.string_at(pcm, byte_count)
|
|
300
292
|
|
|
301
293
|
|
|
302
294
|
libopus_ctl = opuslib_next.api.libopus.opus_decoder_ctl
|
|
@@ -1,25 +1,16 @@
|
|
|
1
|
-
#!/usr/bin/env python
|
|
2
|
-
# -*- coding: utf-8 -*-
|
|
3
|
-
# pylint: disable=invalid-name
|
|
4
|
-
#
|
|
5
|
-
|
|
6
1
|
"""
|
|
7
2
|
CTypes mapping between libopus functions and Python.
|
|
8
3
|
"""
|
|
9
4
|
|
|
10
5
|
import array
|
|
11
|
-
import ctypes
|
|
6
|
+
import ctypes
|
|
12
7
|
import typing
|
|
13
8
|
|
|
14
9
|
import opuslib_next
|
|
15
10
|
import opuslib_next.api
|
|
16
11
|
|
|
17
|
-
__author__ = 'kalicyh <kalicyh@qq.com>'
|
|
18
|
-
__copyright__ = 'Copyright (c) 2025, Kalicyh'
|
|
19
|
-
__license__ = 'BSD 3-Clause License'
|
|
20
|
-
|
|
21
12
|
|
|
22
|
-
class Encoder(ctypes.Structure):
|
|
13
|
+
class Encoder(ctypes.Structure):
|
|
23
14
|
"""Opus encoder state.
|
|
24
15
|
This contains the complete state of an Opus encoder.
|
|
25
16
|
"""
|
|
@@ -1,16 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
# -*- coding: utf-8 -*-
|
|
3
|
-
# pylint: disable=invalid-name
|
|
4
|
-
#
|
|
5
|
-
|
|
6
|
-
import ctypes # type: ignore
|
|
1
|
+
import ctypes
|
|
7
2
|
|
|
8
3
|
import opuslib_next.api
|
|
9
4
|
|
|
10
|
-
__author__ = 'kalicyh <kalicyh@qq.com>'
|
|
11
|
-
__copyright__ = 'Copyright (c) 2025, Kalicyh'
|
|
12
|
-
__license__ = 'BSD 3-Clause License'
|
|
13
|
-
|
|
14
5
|
|
|
15
6
|
strerror = opuslib_next.api.libopus.opus_strerror
|
|
16
7
|
strerror.argtypes = (ctypes.c_int,) # must be sequence (,) of types!
|
|
@@ -1,24 +1,14 @@
|
|
|
1
|
-
#!/usr/bin/env python
|
|
2
|
-
# -*- coding: utf-8 -*-
|
|
3
|
-
# pylint: disable=invalid-name,too-few-public-methods
|
|
4
|
-
#
|
|
5
|
-
|
|
6
1
|
"""
|
|
7
2
|
CTypes mapping between libopus multistream decoder functions and Python.
|
|
8
3
|
"""
|
|
9
4
|
|
|
10
|
-
import
|
|
11
|
-
import ctypes # type: ignore
|
|
5
|
+
import ctypes
|
|
12
6
|
import functools
|
|
13
7
|
import typing
|
|
14
8
|
|
|
15
9
|
import opuslib_next
|
|
16
10
|
import opuslib_next.api
|
|
17
11
|
|
|
18
|
-
__author__ = 'kalicyh <kalicyh@qq.com>'
|
|
19
|
-
__copyright__ = 'Copyright (c) 2025, Kalicyh'
|
|
20
|
-
__license__ = 'BSD 3-Clause License'
|
|
21
|
-
|
|
22
12
|
|
|
23
13
|
class MultiStreamDecoder(ctypes.Structure):
|
|
24
14
|
"""Opus multistream decoder state."""
|
|
@@ -113,7 +103,7 @@ def _libopus_decode():
|
|
|
113
103
|
|
|
114
104
|
|
|
115
105
|
# FIXME: Remove typing.Any once we have a stub for ctypes
|
|
116
|
-
def decode(
|
|
106
|
+
def decode(
|
|
117
107
|
decoder_state: ctypes.Structure,
|
|
118
108
|
opus_data: bytes,
|
|
119
109
|
length: int,
|
|
@@ -138,7 +128,8 @@ def decode( # pylint: disable=too-many-arguments
|
|
|
138
128
|
if result < 0:
|
|
139
129
|
raise opuslib_next.exceptions.OpusError(result)
|
|
140
130
|
|
|
141
|
-
|
|
131
|
+
byte_count = result * channels * ctypes.sizeof(ctypes.c_int16)
|
|
132
|
+
return ctypes.string_at(pcm, byte_count)
|
|
142
133
|
|
|
143
134
|
|
|
144
135
|
@functools.lru_cache(maxsize=None)
|
|
@@ -158,7 +149,7 @@ def _libopus_decode_float():
|
|
|
158
149
|
|
|
159
150
|
|
|
160
151
|
# FIXME: Remove typing.Any once we have a stub for ctypes
|
|
161
|
-
def decode_float(
|
|
152
|
+
def decode_float(
|
|
162
153
|
decoder_state: ctypes.Structure,
|
|
163
154
|
opus_data: bytes,
|
|
164
155
|
length: int,
|
|
@@ -183,7 +174,8 @@ def decode_float( # pylint: disable=too-many-arguments
|
|
|
183
174
|
if result < 0:
|
|
184
175
|
raise opuslib_next.exceptions.OpusError(result)
|
|
185
176
|
|
|
186
|
-
|
|
177
|
+
byte_count = result * channels * ctypes.sizeof(ctypes.c_float)
|
|
178
|
+
return ctypes.string_at(pcm, byte_count)
|
|
187
179
|
|
|
188
180
|
|
|
189
181
|
@functools.lru_cache(maxsize=None)
|
|
@@ -1,26 +1,17 @@
|
|
|
1
|
-
#!/usr/bin/env python
|
|
2
|
-
# -*- coding: utf-8 -*-
|
|
3
|
-
# pylint: disable=invalid-name
|
|
4
|
-
#
|
|
5
|
-
|
|
6
1
|
"""
|
|
7
2
|
CTypes mapping between libopus multistream encoder functions and Python.
|
|
8
3
|
"""
|
|
9
4
|
|
|
10
5
|
import array
|
|
11
|
-
import ctypes
|
|
6
|
+
import ctypes
|
|
12
7
|
import functools
|
|
13
8
|
import typing
|
|
14
9
|
|
|
15
10
|
import opuslib_next
|
|
16
11
|
import opuslib_next.api
|
|
17
12
|
|
|
18
|
-
__author__ = 'kalicyh <kalicyh@qq.com>'
|
|
19
|
-
__copyright__ = 'Copyright (c) 2025, Kalicyh'
|
|
20
|
-
__license__ = 'BSD 3-Clause License'
|
|
21
|
-
|
|
22
13
|
|
|
23
|
-
class MultiStreamEncoder(ctypes.Structure):
|
|
14
|
+
class MultiStreamEncoder(ctypes.Structure):
|
|
24
15
|
"""Opus multistream encoder state."""
|
|
25
16
|
pass
|
|
26
17
|
|
|
@@ -1,24 +1,14 @@
|
|
|
1
|
-
#!/usr/bin/env python
|
|
2
|
-
# -*- coding: utf-8 -*-
|
|
3
|
-
# pylint: disable=invalid-name,too-few-public-methods
|
|
4
|
-
#
|
|
5
|
-
|
|
6
1
|
"""
|
|
7
2
|
CTypes mapping between libopus projection decoder functions and Python.
|
|
8
3
|
"""
|
|
9
4
|
|
|
10
|
-
import
|
|
11
|
-
import ctypes # type: ignore
|
|
5
|
+
import ctypes
|
|
12
6
|
import functools
|
|
13
7
|
import typing
|
|
14
8
|
|
|
15
9
|
import opuslib_next
|
|
16
10
|
import opuslib_next.api
|
|
17
11
|
|
|
18
|
-
__author__ = 'kalicyh <kalicyh@qq.com>'
|
|
19
|
-
__copyright__ = 'Copyright (c) 2025, Kalicyh'
|
|
20
|
-
__license__ = 'BSD 3-Clause License'
|
|
21
|
-
|
|
22
12
|
|
|
23
13
|
class ProjectionDecoder(ctypes.Structure):
|
|
24
14
|
"""Opus projection decoder state."""
|
|
@@ -125,7 +115,7 @@ def _libopus_decode():
|
|
|
125
115
|
|
|
126
116
|
|
|
127
117
|
# FIXME: Remove typing.Any once we have a stub for ctypes
|
|
128
|
-
def decode(
|
|
118
|
+
def decode(
|
|
129
119
|
decoder_state: ctypes.Structure,
|
|
130
120
|
opus_data: bytes,
|
|
131
121
|
length: int,
|
|
@@ -150,7 +140,8 @@ def decode( # pylint: disable=too-many-arguments
|
|
|
150
140
|
if result < 0:
|
|
151
141
|
raise opuslib_next.OpusError(result)
|
|
152
142
|
|
|
153
|
-
|
|
143
|
+
byte_count = result * channels * ctypes.sizeof(ctypes.c_int16)
|
|
144
|
+
return ctypes.string_at(pcm, byte_count)
|
|
154
145
|
|
|
155
146
|
|
|
156
147
|
@functools.lru_cache(maxsize=None)
|
|
@@ -170,7 +161,7 @@ def _libopus_decode_float():
|
|
|
170
161
|
|
|
171
162
|
|
|
172
163
|
# FIXME: Remove typing.Any once we have a stub for ctypes
|
|
173
|
-
def decode_float(
|
|
164
|
+
def decode_float(
|
|
174
165
|
decoder_state: ctypes.Structure,
|
|
175
166
|
opus_data: bytes,
|
|
176
167
|
length: int,
|
|
@@ -195,7 +186,8 @@ def decode_float( # pylint: disable=too-many-arguments
|
|
|
195
186
|
if result < 0:
|
|
196
187
|
raise opuslib_next.OpusError(result)
|
|
197
188
|
|
|
198
|
-
|
|
189
|
+
byte_count = result * channels * ctypes.sizeof(ctypes.c_float)
|
|
190
|
+
return ctypes.string_at(pcm, byte_count)
|
|
199
191
|
|
|
200
192
|
|
|
201
193
|
@functools.lru_cache(maxsize=None)
|
|
@@ -1,26 +1,17 @@
|
|
|
1
|
-
#!/usr/bin/env python
|
|
2
|
-
# -*- coding: utf-8 -*-
|
|
3
|
-
# pylint: disable=invalid-name
|
|
4
|
-
#
|
|
5
|
-
|
|
6
1
|
"""
|
|
7
2
|
CTypes mapping between libopus projection encoder functions and Python.
|
|
8
3
|
"""
|
|
9
4
|
|
|
10
5
|
import array
|
|
11
|
-
import ctypes
|
|
6
|
+
import ctypes
|
|
12
7
|
import functools
|
|
13
8
|
import typing
|
|
14
9
|
|
|
15
10
|
import opuslib_next
|
|
16
11
|
import opuslib_next.api
|
|
17
12
|
|
|
18
|
-
__author__ = 'kalicyh <kalicyh@qq.com>'
|
|
19
|
-
__copyright__ = 'Copyright (c) 2025, Kalicyh'
|
|
20
|
-
__license__ = 'BSD 3-Clause License'
|
|
21
|
-
|
|
22
13
|
|
|
23
|
-
class ProjectionEncoder(ctypes.Structure):
|
|
14
|
+
class ProjectionEncoder(ctypes.Structure):
|
|
24
15
|
"""Opus projection encoder state."""
|
|
25
16
|
pass
|
|
26
17
|
|
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
#!/usr/bin/env python
|
|
2
|
-
# -*- coding: utf-8 -*-
|
|
3
|
-
|
|
4
1
|
"""High-level interface to a Opus decoder functions"""
|
|
5
2
|
|
|
6
3
|
import typing
|
|
@@ -15,10 +12,6 @@ import opuslib_next.api.multistream_encoder
|
|
|
15
12
|
import opuslib_next.api.projection_decoder
|
|
16
13
|
import opuslib_next.api.projection_encoder
|
|
17
14
|
|
|
18
|
-
__author__ = 'kalicyh <kalicyh@qq.com>'
|
|
19
|
-
__copyright__ = 'Copyright (c) 2025, Kalicyh'
|
|
20
|
-
__license__ = 'BSD 3-Clause License'
|
|
21
|
-
|
|
22
15
|
|
|
23
16
|
class Decoder(object):
|
|
24
17
|
|
|
@@ -1,15 +1,8 @@
|
|
|
1
|
-
#!/usr/bin/env python
|
|
2
|
-
# -*- coding: utf-8 -*-
|
|
3
|
-
|
|
4
1
|
"""
|
|
5
2
|
OpusLib constants.
|
|
6
3
|
Matches to `opus_defines.h`
|
|
7
4
|
"""
|
|
8
5
|
|
|
9
|
-
__author__ = 'kalicyh <kalicyh@qq.com>'
|
|
10
|
-
__copyright__ = 'Copyright (c) 2025, Kalicyh'
|
|
11
|
-
__license__ = 'BSD 3-Clause License'
|
|
12
|
-
|
|
13
6
|
|
|
14
7
|
# No Error
|
|
15
8
|
OK = 0
|
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
#!/usr/bin/env python
|
|
2
|
-
# -*- coding: utf-8 -*-
|
|
3
|
-
|
|
4
1
|
"""
|
|
5
2
|
Exceptions for OpusLib.
|
|
6
3
|
"""
|
|
@@ -9,10 +6,6 @@ import typing
|
|
|
9
6
|
|
|
10
7
|
import opuslib_next.api.info
|
|
11
8
|
|
|
12
|
-
__author__ = 'kalicyh <kalicyh@qq.com>'
|
|
13
|
-
__copyright__ = 'Copyright (c) 2025, Kalicyh'
|
|
14
|
-
__license__ = 'BSD 3-Clause License'
|
|
15
|
-
|
|
16
9
|
|
|
17
10
|
class OpusError(Exception):
|
|
18
11
|
|
|
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "opuslib-next"
|
|
7
|
-
version = "1.3.
|
|
7
|
+
version = "1.3.2"
|
|
8
8
|
description = "Python bindings to the libopus, IETF low-delay audio codec"
|
|
9
9
|
readme = "README.md"
|
|
10
10
|
requires-python = ">=3.10"
|
|
@@ -35,11 +35,7 @@ Repository = "https://github.com/kalicyh/opuslib-next"
|
|
|
35
35
|
Issues = "https://github.com/kalicyh/opuslib-next/issues"
|
|
36
36
|
|
|
37
37
|
[dependency-groups]
|
|
38
|
-
dev = [
|
|
39
|
-
"build>=1.2.2",
|
|
40
|
-
"pytest>=8.3.5",
|
|
41
|
-
"twine>=6.1.0",
|
|
42
|
-
]
|
|
38
|
+
dev = ["pytest>=8.3.5"]
|
|
43
39
|
|
|
44
40
|
[tool.hatch.build.targets.wheel]
|
|
45
41
|
packages = ["opuslib_next"]
|
|
@@ -1,8 +1,3 @@
|
|
|
1
|
-
#!/usr/bin/env python
|
|
2
|
-
# -*- coding: utf-8 -*-
|
|
3
|
-
# pylint: disable=missing-docstring
|
|
4
|
-
#
|
|
5
|
-
|
|
6
1
|
import sys
|
|
7
2
|
import unittest
|
|
8
3
|
|
|
@@ -10,10 +5,6 @@ import opuslib_next.api
|
|
|
10
5
|
import opuslib_next.api.decoder
|
|
11
6
|
import opuslib_next.api.ctl
|
|
12
7
|
|
|
13
|
-
__author__ = 'kalicyh <kalicyh@qq.com>'
|
|
14
|
-
__copyright__ = 'Copyright (c) 2025, Kalicyh'
|
|
15
|
-
__license__ = 'BSD 3-Clause License'
|
|
16
|
-
|
|
17
8
|
|
|
18
9
|
class DecoderTest(unittest.TestCase):
|
|
19
10
|
"""Decoder basic API tests
|
|
@@ -67,9 +58,6 @@ class DecoderTest(unittest.TestCase):
|
|
|
67
58
|
else:
|
|
68
59
|
opuslib_next.api.decoder.destroy(dec)
|
|
69
60
|
|
|
70
|
-
# TODO: rewrite this code
|
|
71
|
-
# VG_CHECK(dec,opus_decoder_get_size(2));
|
|
72
|
-
|
|
73
61
|
@classmethod
|
|
74
62
|
def test_get_final_range(cls):
|
|
75
63
|
dec = opuslib_next.api.decoder.create_state(48000, 2)
|
|
@@ -193,19 +181,19 @@ class DecoderTest(unittest.TestCase):
|
|
|
193
181
|
packet = bytes([ixc, jxc])
|
|
194
182
|
|
|
195
183
|
self.assertEqual(
|
|
196
|
-
expected_result if expected_result != 3 else (packet[1] & 63),
|
|
184
|
+
expected_result if expected_result != 3 else (packet[1] & 63),
|
|
197
185
|
opuslib_next.api.decoder.packet_get_nb_frames(packet, 2)
|
|
198
186
|
)
|
|
199
187
|
|
|
200
188
|
def test_packet_get_bandwidth(self):
|
|
201
|
-
"""Tests `
|
|
189
|
+
"""Tests `opuslib_next.api.decoder.packet_get_bandwidth()`."""
|
|
202
190
|
|
|
203
191
|
for ixc in range(0, 256):
|
|
204
192
|
packet = bytes([ixc])
|
|
205
193
|
bwx = ixc >> 4
|
|
206
194
|
|
|
207
195
|
# Very cozy code from the test_opus_api.c
|
|
208
|
-
_bwx = opuslib_next.BANDWIDTH_NARROWBAND + (((((bwx & 7) * 9) & (63 - (bwx & 8))) + 2 + 12 * ((bwx & 8) != 0)) >> 4)
|
|
196
|
+
_bwx = opuslib_next.BANDWIDTH_NARROWBAND + (((((bwx & 7) * 9) & (63 - (bwx & 8))) + 2 + 12 * ((bwx & 8) != 0)) >> 4)
|
|
209
197
|
|
|
210
198
|
self.assertEqual(
|
|
211
199
|
_bwx, opuslib_next.api.decoder.packet_get_bandwidth(packet)
|