forked from M-Labs/artiq
wavesynth: silence is a channel property (closes #348)
This commit is contained in:
parent
6a783ead24
commit
13b4929dd8
|
@ -198,13 +198,14 @@ class Pdq2:
|
||||||
duration = line["duration"]
|
duration = line["duration"]
|
||||||
trigger = line.get("trigger", False)
|
trigger = line.get("trigger", False)
|
||||||
for segment, data in zip(segments, line["channel_data"]):
|
for segment, data in zip(segments, line["channel_data"]):
|
||||||
|
silence = data.pop("silence", False)
|
||||||
if len(data) != 1:
|
if len(data) != 1:
|
||||||
raise ValueError("only one target per channel and line "
|
raise ValueError("only one target per channel and line "
|
||||||
"supported")
|
"supported")
|
||||||
for target, target_data in data.items():
|
for target, target_data in data.items():
|
||||||
getattr(segment, target)(
|
getattr(segment, target)(
|
||||||
shift=shift, duration=duration, trigger=trigger,
|
shift=shift, duration=duration, trigger=trigger,
|
||||||
**target_data)
|
silence=silence, **target_data)
|
||||||
|
|
||||||
def program(self, program, channels=None):
|
def program(self, program, channels=None):
|
||||||
if channels is None:
|
if channels is None:
|
||||||
|
|
|
@ -103,10 +103,10 @@ _test_program = [
|
||||||
"duration": 40,
|
"duration": 40,
|
||||||
"channel_data": [
|
"channel_data": [
|
||||||
{"bias": {"amplitude": [.4, .04, -2e-3]}},
|
{"bias": {"amplitude": [.4, .04, -2e-3]}},
|
||||||
{"bias": {
|
{
|
||||||
"amplitude": [.5],
|
"bias": {"amplitude": [.5]},
|
||||||
"silence": True,
|
"silence": True,
|
||||||
}},
|
},
|
||||||
{"dds": {
|
{"dds": {
|
||||||
"amplitude": [.8, .08, -4e-3, 0],
|
"amplitude": [.8, .08, -4e-3, 0],
|
||||||
"phase": [.25, .025, .02/40],
|
"phase": [.25, .025, .02/40],
|
||||||
|
|
|
@ -57,7 +57,7 @@ class DDS:
|
||||||
return self.amplitude.next()*cos(2*pi*self.phase.next())
|
return self.amplitude.next()*cos(2*pi*self.phase.next())
|
||||||
|
|
||||||
|
|
||||||
class Wave:
|
class Channel:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.bias = Spline()
|
self.bias = Spline()
|
||||||
self.dds = DDS()
|
self.dds = DDS()
|
||||||
|
@ -80,7 +80,7 @@ class TriggerError(Exception):
|
||||||
|
|
||||||
class Synthesizer:
|
class Synthesizer:
|
||||||
def __init__(self, nchannels, program):
|
def __init__(self, nchannels, program):
|
||||||
self.channels = [Wave() for _ in range(nchannels)]
|
self.channels = [Channel() for _ in range(nchannels)]
|
||||||
self.program = program
|
self.program = program
|
||||||
# line_iter is None: "wait for segment selection" state
|
# line_iter is None: "wait for segment selection" state
|
||||||
# otherwise: iterator on the current position in the frame
|
# otherwise: iterator on the current position in the frame
|
||||||
|
@ -104,6 +104,7 @@ class Synthesizer:
|
||||||
while True:
|
while True:
|
||||||
for channel, channel_data in zip(self.channels,
|
for channel, channel_data in zip(self.channels,
|
||||||
line["channel_data"]):
|
line["channel_data"]):
|
||||||
|
channel.set_silence(channel_data.get("silence", False))
|
||||||
if "bias" in channel_data:
|
if "bias" in channel_data:
|
||||||
channel.bias.set_coefficients(
|
channel.bias.set_coefficients(
|
||||||
channel_data["bias"]["amplitude"])
|
channel_data["bias"]["amplitude"])
|
||||||
|
@ -115,7 +116,6 @@ class Synthesizer:
|
||||||
channel_data["dds"]["phase"])
|
channel_data["dds"]["phase"])
|
||||||
if channel_data["dds"].get("clear", False):
|
if channel_data["dds"].get("clear", False):
|
||||||
channel.dds.phase.clear()
|
channel.dds.phase.clear()
|
||||||
channel.set_silence(channel_data.get("silence", False))
|
|
||||||
|
|
||||||
if line.get("dac_divider", 1) != 1:
|
if line.get("dac_divider", 1) != 1:
|
||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
|
|
Loading…
Reference in New Issue