Added mute option to siggen

This commit is contained in:
Anne de Jong 2021-10-18 09:18:39 +02:00
parent 60afface35
commit a1bcae508b

View File

@ -68,6 +68,7 @@ class SiggenMessage(Enum):
newSiggenData = auto() # Forward new equalizer settings
ready = auto() # Send out once, once the signal generator is ready with
# pre-generating data.
mute = auto() # Mute / unmute siggen
# These messages are send back to the main thread over the pipe
error = auto()
@ -87,6 +88,9 @@ class SiggenData:
# The data type to output
dtype: np.dtype
# Muted?
muted: bool
# Level of output signal [dBFS]el
level_dB: float
@ -146,6 +150,9 @@ class SiggenProcess(mp.Process):
signaltype = siggendata.signaltype
signaltypedata = siggendata.signaltypedata
# Muted state
self.muted = siggendata.muted
if signaltype == SignalType.Periodic:
freq, = signaltypedata
siggen = pyxSiggen.sineWave(fs, freq, level_dB)
@ -181,6 +188,9 @@ class SiggenProcess(mp.Process):
if np.issubdtype(dtype, np.integer):
bitdepth_fixed = dtype.itemsize * 8
signal *= 2 ** (bitdepth_fixed - 1) - 1
if self.muted:
# Mute it
signal *= 0
try:
self.dataq.put(signal.astype(dtype))
except ValueError:
@ -253,6 +263,8 @@ class SiggenProcess(mp.Process):
if msg == SiggenMessage.endProcess:
logging.debug("Signal generator caught 'endProcess' message. Exiting.")
return 0
elif msg == SiggenMessage.mute:
self.muted = data
elif msg == SiggenMessage.adjustVolume:
level_dB = data
logging.debug(f"Signal generator caught 'adjustVolume' message. New volume = {level_dB:.1f} dB FS")
@ -320,6 +332,9 @@ class Siggen:
"""
self.pipe.send((SiggenMessage.adjustVolume, new_level))
def mute(self, mute):
self.pipe.send((SiggenMessage.mute, mute))
def setEqData(self, eqdata):
self.pipe.send((SiggenMessage.newEqSettings, eqdata))