Skip to content

Commit 8eec8da

Browse files
davidhozicpre-commit-ci[bot]DorukyumLulalabyplun1331
authored andcommitted
refactor: python implementation of audioop.mul (Pycord-Development#2176)
* Replace audioop * style(pre-commit): auto fixes from pre-commit.com hooks * versionchanged * changelog * style(pre-commit): auto fixes from pre-commit.com hooks * speed * style(pre-commit): auto fixes from pre-commit.com hooks * changelog * Optimization (1 ms) * Update discord/player.py Co-authored-by: Dorukyum <[email protected]> Signed-off-by: David Hozic <[email protected]> * Update CHANGELOG.md Co-authored-by: Lala Sabathil <[email protected]> Signed-off-by: David Hozic <[email protected]> --------- Signed-off-by: David Hozic <[email protected]> Signed-off-by: Lala Sabathil <[email protected]> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Dorukyum <[email protected]> Co-authored-by: Lala Sabathil <[email protected]> Co-authored-by: plun1331 <[email protected]> Co-authored-by: Lala Sabathil <[email protected]>
1 parent 54b8572 commit 8eec8da

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)