Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 6a1a901

Browse files
committedJul 27, 2023
speed
1 parent fb785c2 commit 6a1a901

File tree

1 file changed

+5
-20
lines changed

1 file changed

+5
-20
lines changed
 

‎discord/player.py

Lines changed: 5 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@
3535
import threading
3636
import time
3737
import traceback
38-
from itertools import chain
38+
import array
39+
3940
from math import floor
4041
from typing import IO, TYPE_CHECKING, Any, Callable, Generic, TypeVar
4142

@@ -701,25 +702,9 @@ def read(self) -> bytes:
701702
minval = -0x8000
702703

703704
ret = self.original.read()
704-
samples = bytes(
705-
chain.from_iterable(
706-
int(
707-
floor(
708-
min(
709-
maxval,
710-
max(
711-
int.from_bytes(
712-
ret[i * 2 : (i + 1) * 2], "little", signed=True
713-
)
714-
* min(self._volume, 2.0),
715-
minval,
716-
),
717-
)
718-
)
719-
).to_bytes(2, "little", signed=True)
720-
for i in range(len(ret) // 2)
721-
)
722-
)
705+
samples = array.array("h")
706+
samples.frombytes(ret)
707+
samples = array.array('h', map(lambda sample: int(floor(min(maxval, max(sample * min(self._volume, 2.0), minval)))), samples)).tobytes()
723708
return samples
724709

725710

0 commit comments

Comments
 (0)
Please sign in to comment.