Adding all current customizations to the original forked code.
This commit is contained in:
@ -1,15 +1,18 @@
|
||||
from csdr.chain import Chain
|
||||
from pycsdr.modules import AudioResampler, Convert, AdpcmEncoder, Limit
|
||||
from pycsdr.modules import AudioResampler, Convert, AdpcmEncoder, Limit, NoiseFilter
|
||||
from pycsdr.types import Format
|
||||
|
||||
|
||||
class Converter(Chain):
|
||||
def __init__(self, format: Format, inputRate: int, clientRate: int):
|
||||
def __init__(self, format: Format, inputRate: int, clientRate: int, nrEnabled: bool, nrThreshold: int):
|
||||
workers = []
|
||||
# we only have an audio resampler and noise filter for float ATM,
|
||||
# so if we need to resample or remove noise, we need to convert
|
||||
if (inputRate != clientRate or nrEnabled) and format != Format.FLOAT:
|
||||
workers += [Convert(format, Format.FLOAT)]
|
||||
if nrEnabled:
|
||||
workers += [NoiseFilter(nrThreshold)]
|
||||
if inputRate != clientRate:
|
||||
# we only have an audio resampler for float ATM so if we need to resample, we need to convert
|
||||
if format != Format.FLOAT:
|
||||
workers += [Convert(format, Format.FLOAT)]
|
||||
workers += [AudioResampler(inputRate, clientRate), Limit(), Convert(Format.FLOAT, Format.SHORT)]
|
||||
elif format != Format.SHORT:
|
||||
workers += [Convert(format, Format.SHORT)]
|
||||
@ -17,10 +20,12 @@ class Converter(Chain):
|
||||
|
||||
|
||||
class ClientAudioChain(Chain):
|
||||
def __init__(self, format: Format, inputRate: int, clientRate: int, compression: str):
|
||||
def __init__(self, format: Format, inputRate: int, clientRate: int, compression: str, nrEnabled: bool, nrThreshold: int):
|
||||
self.format = format
|
||||
self.inputRate = inputRate
|
||||
self.clientRate = clientRate
|
||||
self.nrEnabled = nrEnabled
|
||||
self.nrThreshold = nrThreshold
|
||||
workers = []
|
||||
converter = self._buildConverter()
|
||||
if not converter.empty():
|
||||
@ -30,7 +35,7 @@ class ClientAudioChain(Chain):
|
||||
super().__init__(workers)
|
||||
|
||||
def _buildConverter(self):
|
||||
return Converter(self.format, self.inputRate, self.clientRate)
|
||||
return Converter(self.format, self.inputRate, self.clientRate, self.nrEnabled, self.nrThreshold)
|
||||
|
||||
def _updateConverter(self):
|
||||
converter = self._buildConverter()
|
||||
@ -70,3 +75,15 @@ class ClientAudioChain(Chain):
|
||||
else:
|
||||
if index >= 0:
|
||||
self.remove(index)
|
||||
|
||||
def setNrEnabled(self, nrEnabled: bool) -> None:
|
||||
if nrEnabled == self.nrEnabled:
|
||||
return
|
||||
self.nrEnabled = nrEnabled
|
||||
self._updateConverter()
|
||||
|
||||
def setNrThreshold(self, nrThreshold: int) -> None:
|
||||
if nrThreshold == self.nrThreshold:
|
||||
return
|
||||
self.nrThreshold = nrThreshold
|
||||
self._updateConverter()
|
||||
|
Reference in New Issue
Block a user