Skip to content

Commit 7f731ba

Browse files
authored
Merge branch 'master' into fix-is-integration
2 parents aedefdb + 33adf22 commit 7f731ba

File tree

3 files changed

+16
-3
lines changed

3 files changed

+16
-3
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,9 @@ These changes are available on the `master` branch, but have not yet been releas
5555
([#2496](https://github.com/Pycord-Development/pycord/pull/2496))
5656
- ⚠️ **Removed support for Python 3.8.**
5757
([#2521](https://github.com/Pycord-Development/pycord/pull/2521))
58+
- Replaced audioop (deprecated module) implementation of `PCMVolumeTransformer.read`
59+
method with a pure Python equivalent.
60+
([#2176](https://github.com/Pycord-Development/pycord/pull/2176))
5861

5962
### Deprecated
6063

discord/player.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@
2525

2626
from __future__ import annotations
2727

28+
import array
2829
import asyncio
29-
import audioop
3030
import io
3131
import json
3232
import logging
@@ -37,6 +37,7 @@
3737
import threading
3838
import time
3939
import traceback
40+
from math import floor
4041
from typing import IO, TYPE_CHECKING, Any, Callable, Generic, TypeVar
4142

4243
from .errors import ClientException
@@ -704,8 +705,17 @@ def cleanup(self) -> None:
704705
self.original.cleanup()
705706

706707
def read(self) -> bytes:
708+
maxval = 0x7FFF
709+
minval = -0x8000
710+
711+
volume = min(self._volume, 2.0)
707712
ret = self.original.read()
708-
return audioop.mul(ret, 2, min(self._volume, 2.0))
713+
samples = array.array("h")
714+
samples.frombytes(ret)
715+
for i in range(len(samples)):
716+
samples[i] = int(floor(min(maxval, max(samples[i] * volume, minval))))
717+
718+
return samples.tobytes()
709719

710720

711721
class AudioPlayer(threading.Thread):

requirements/dev.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ pylint~=3.3.1
33
pytest~=8.3.3
44
pytest-asyncio~=0.23.8
55
# pytest-order~=1.0.1
6-
mypy~=1.11.2
6+
mypy~=1.12.0
77
coverage~=7.6
88
pre-commit==4.0.1
99
codespell==2.3.0

0 commit comments

Comments
 (0)