Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ These changes are available on the `master` branch, but have not yet been releas

### Changed

- Replaced audioop (deprecated module) implementation of `PCMVolumeTransformer.read`
method with a pure Python equivalent.
([#2176](https://github.com/Pycord-Development/pycord/pull/2176))
- Suppressed FFMPEG output when recording voice channels.
([#1993](https://github.com/Pycord-Development/pycord/pull/1993))
- Changed file-upload size limit from 8 MB to 25 MB accordingly.
Expand Down
32 changes: 30 additions & 2 deletions discord/player.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
from __future__ import annotations

import asyncio
import audioop
import io
import json
import logging
Expand All @@ -36,6 +35,8 @@
import threading
import time
import traceback
from itertools import chain
from math import floor
from typing import IO, TYPE_CHECKING, Any, Callable, Generic, TypeVar

from .errors import ClientException
Expand Down Expand Up @@ -652,6 +653,11 @@ class PCMVolumeTransformer(AudioSource, Generic[AT]):
This does not work on audio sources that have :meth:`AudioSource.is_opus`
set to ``True``.

.. versionchanged:: 2.5

Replaced audioop implementation of :py:meth:`discord.PCMVolumeTransformer.read`
method with a pure Python equivalent.

Parameters
----------
original: :class:`AudioSource`
Expand Down Expand Up @@ -691,8 +697,30 @@ def cleanup(self) -> None:
self.original.cleanup()

def read(self) -> bytes:
maxval = 0x7FFF
minval = -0x8000

ret = self.original.read()
return audioop.mul(ret, 2, min(self._volume, 2.0))
samples = bytes(
chain.from_iterable(
int(
floor(
min(
maxval,
max(
int.from_bytes(
ret[i * 2 : (i + 1) * 2], "little", signed=True
)
* min(self._volume, 2.0),
minval,
),
)
)
).to_bytes(2, "little", signed=True)
for i in range(len(ret) // 2)
)
)
return samples


class AudioPlayer(threading.Thread):
Expand Down