Skip to content

Commit 2930699

Browse files
authored
Merge branch 'master' into app_emojis
Signed-off-by: UK <[email protected]>
2 parents 7872075 + 33adf22 commit 2930699

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
@@ -58,6 +58,9 @@ These changes are available on the `master` branch, but have not yet been releas
5858
([#2521](https://github.com/Pycord-Development/pycord/pull/2521))
5959
- `Emoji` has been renamed to `GuildEmoji`.
6060
([#2501](https://github.com/Pycord-Development/pycord/pull/2501))
61+
- Replaced audioop (deprecated module) implementation of `PCMVolumeTransformer.read`
62+
method with a pure Python equivalent.
63+
([#2176](https://github.com/Pycord-Development/pycord/pull/2176))
6164

6265
### Deprecated
6366

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)