Skip to content

Commit d4650d4

Browse files
authored
Merge branch 'master' into python-3.13
2 parents 7e9bc8b + 33adf22 commit d4650d4

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

CHANGELOG.md

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

5659
### Deprecated
5760

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):

0 commit comments

Comments
 (0)