mirror of
https://github.com/Rapptz/discord.py.git
synced 2025-05-16 10:49:24 +00:00
Add ability to set opus encoder input signal type.
This commit is contained in:
parent
31cd9ad37a
commit
643950abf8
@ -166,6 +166,7 @@ CTL_SET_BITRATE = 4002
|
||||
CTL_SET_BANDWIDTH = 4008
|
||||
CTL_SET_FEC = 4012
|
||||
CTL_SET_PLP = 4014
|
||||
CTL_SET_SIGNAL = 4024
|
||||
|
||||
band_ctl = {
|
||||
'narrow': 1101,
|
||||
@ -175,6 +176,12 @@ band_ctl = {
|
||||
'full': 1105,
|
||||
}
|
||||
|
||||
signal_ctl = {
|
||||
'auto': -1000,
|
||||
'voice': 3001,
|
||||
'music': 3002,
|
||||
}
|
||||
|
||||
class Encoder:
|
||||
def __init__(self, sampling, channels, application=APPLICATION_AUDIO):
|
||||
self.sampling_rate = sampling
|
||||
@ -194,6 +201,7 @@ class Encoder:
|
||||
self.set_fec(True)
|
||||
self.set_expected_packet_loss_percent(0.15)
|
||||
self.set_bandwidth('full')
|
||||
self.set_signal_type('auto')
|
||||
|
||||
def __del__(self):
|
||||
if hasattr(self, '_state'):
|
||||
@ -231,6 +239,17 @@ class Encoder:
|
||||
log.info('error has happened in set_bandwidth')
|
||||
raise OpusError(ret)
|
||||
|
||||
def set_signal_type(self, req):
|
||||
if req not in signal_ctl:
|
||||
raise KeyError('%r is not a valid signal setting. Try one of: %s' % (req, ','.join(signal_ctl)))
|
||||
|
||||
k = signal_ctl[req]
|
||||
ret = _lib.opus_encoder_ctl(self._state, CTL_SET_SIGNAL, k)
|
||||
|
||||
if ret < 0:
|
||||
log.info('error has happened in set_signal_type')
|
||||
raise OpusError(ret)
|
||||
|
||||
def set_fec(self, enabled=True):
|
||||
ret = _lib.opus_encoder_ctl(self._state, CTL_SET_FEC, 1 if enabled else 0)
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user