From fce73969c3710229a0778323505ebe01a2b57e05 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 15 Oct 2024 16:54:32 +0200 Subject: [PATCH 1/2] chore(deps-dev): update mypy requirement from ~=1.11.2 to ~=1.12.0 (#2608) Updates the requirements on [mypy](https://github.com/python/mypy) to permit the latest version. - [Changelog](https://github.com/python/mypy/blob/master/CHANGELOG.md) - [Commits](https://github.com/python/mypy/compare/v1.11.2...v1.12.0) --- updated-dependencies: - dependency-name: mypy dependency-type: direct:development ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- requirements/dev.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements/dev.txt b/requirements/dev.txt index 3a4a5a1a28..744004f276 100644 --- a/requirements/dev.txt +++ b/requirements/dev.txt @@ -3,7 +3,7 @@ pylint~=3.3.1 pytest~=8.3.3 pytest-asyncio~=0.23.8 # pytest-order~=1.0.1 -mypy~=1.11.2 +mypy~=1.12.0 coverage~=7.6 pre-commit==4.0.1 codespell==2.3.0 From 33adf222b931a33fe596e7551ddcdb491c072193 Mon Sep 17 00:00:00 2001 From: David Hozic Date: Thu, 17 Oct 2024 17:28:51 +0200 Subject: [PATCH 2/2] refactor: python implementation of `audioop.mul` (#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 <53639936+Dorukyum@users.noreply.github.com> Signed-off-by: David Hozic * Update CHANGELOG.md Co-authored-by: Lala Sabathil Signed-off-by: David Hozic --------- Signed-off-by: David Hozic Signed-off-by: Lala Sabathil Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Dorukyum <53639936+Dorukyum@users.noreply.github.com> Co-authored-by: Lala Sabathil Co-authored-by: plun1331 Co-authored-by: Lala Sabathil --- CHANGELOG.md | 3 +++ discord/player.py | 14 ++++++++++++-- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0e18ad29c0..3405068a18 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -52,6 +52,9 @@ These changes are available on the `master` branch, but have not yet been releas ([#2496](https://github.com/Pycord-Development/pycord/pull/2496)) - ⚠️ **Removed support for Python 3.8.** ([#2521](https://github.com/Pycord-Development/pycord/pull/2521)) +- Replaced audioop (deprecated module) implementation of `PCMVolumeTransformer.read` + method with a pure Python equivalent. + ([#2176](https://github.com/Pycord-Development/pycord/pull/2176)) ### Deprecated diff --git a/discord/player.py b/discord/player.py index 9868aabe70..65b23ed42a 100644 --- a/discord/player.py +++ b/discord/player.py @@ -25,8 +25,8 @@ from __future__ import annotations +import array import asyncio -import audioop import io import json import logging @@ -37,6 +37,7 @@ import threading import time import traceback +from math import floor from typing import IO, TYPE_CHECKING, Any, Callable, Generic, TypeVar from .errors import ClientException @@ -704,8 +705,17 @@ def cleanup(self) -> None: self.original.cleanup() def read(self) -> bytes: + maxval = 0x7FFF + minval = -0x8000 + + volume = min(self._volume, 2.0) ret = self.original.read() - return audioop.mul(ret, 2, min(self._volume, 2.0)) + samples = array.array("h") + samples.frombytes(ret) + for i in range(len(samples)): + samples[i] = int(floor(min(maxval, max(samples[i] * volume, minval)))) + + return samples.tobytes() class AudioPlayer(threading.Thread):