wavesynth: silence is a channel property (closes #348)

pull/605/head
Robert Jördens 2016-04-07 21:51:29 +08:00
parent 6a783ead24
commit 13b4929dd8
3 changed files with 9 additions and 8 deletions

View File

@ -198,13 +198,14 @@ class Pdq2:
duration = line["duration"]
trigger = line.get("trigger", False)
for segment, data in zip(segments, line["channel_data"]):
silence = data.pop("silence", False)
if len(data) != 1:
raise ValueError("only one target per channel and line "
"supported")
for target, target_data in data.items():
getattr(segment, target)(
shift=shift, duration=duration, trigger=trigger,
**target_data)
silence=silence, **target_data)
def program(self, program, channels=None):
if channels is None:

View File

@ -31,7 +31,7 @@ class TestPdq2(unittest.TestCase):
self.dev.program(_test_program)
self.dev.cmd("START", True)
self.dev.cmd("ARM", True)
#self.dev.cmd("TRIGGER", True)
# self.dev.cmd("TRIGGER", True)
return self.dev.dev.getvalue()
def test_synth(self):
@ -103,10 +103,10 @@ _test_program = [
"duration": 40,
"channel_data": [
{"bias": {"amplitude": [.4, .04, -2e-3]}},
{"bias": {
"amplitude": [.5],
{
"bias": {"amplitude": [.5]},
"silence": True,
}},
},
{"dds": {
"amplitude": [.8, .08, -4e-3, 0],
"phase": [.25, .025, .02/40],

View File

@ -57,7 +57,7 @@ class DDS:
return self.amplitude.next()*cos(2*pi*self.phase.next())
class Wave:
class Channel:
def __init__(self):
self.bias = Spline()
self.dds = DDS()
@ -80,7 +80,7 @@ class TriggerError(Exception):
class Synthesizer:
def __init__(self, nchannels, program):
self.channels = [Wave() for _ in range(nchannels)]
self.channels = [Channel() for _ in range(nchannels)]
self.program = program
# line_iter is None: "wait for segment selection" state
# otherwise: iterator on the current position in the frame
@ -104,6 +104,7 @@ class Synthesizer:
while True:
for channel, channel_data in zip(self.channels,
line["channel_data"]):
channel.set_silence(channel_data.get("silence", False))
if "bias" in channel_data:
channel.bias.set_coefficients(
channel_data["bias"]["amplitude"])
@ -115,7 +116,6 @@ class Synthesizer:
channel_data["dds"]["phase"])
if channel_data["dds"].get("clear", False):
channel.dds.phase.clear()
channel.set_silence(channel_data.get("silence", False))
if line.get("dac_divider", 1) != 1:
raise NotImplementedError