forked from M-Labs/artiq
wavesynth: implement silence, add defaults, fix bias
This commit is contained in:
parent
051b01f58e
commit
1f545346e3
@ -11,8 +11,8 @@ class Spline:
|
||||
|
||||
def next(self):
|
||||
r = self.c[0]
|
||||
for i in range(len(self.c)-1):
|
||||
self.c[i] += self.c[i+1]
|
||||
for i in range(len(self.c) - 1):
|
||||
self.c[i] += self.c[i + 1]
|
||||
return r
|
||||
|
||||
|
||||
@ -30,8 +30,8 @@ class SplinePhase:
|
||||
|
||||
def next(self):
|
||||
r = self.c[0] + self.c0
|
||||
for i in range(len(self.c)-1):
|
||||
self.c[i] = (self.c[i] + self.c[i+1]) % 1.0
|
||||
for i in range(len(self.c) - 1):
|
||||
self.c[i] = (self.c[i] + self.c[i + 1]) % 1.0
|
||||
return r
|
||||
|
||||
|
||||
@ -48,9 +48,14 @@ class Wave:
|
||||
def __init__(self):
|
||||
self.bias = Spline()
|
||||
self.dds = DDS()
|
||||
self.last = 0.
|
||||
self.silence = False
|
||||
|
||||
def next(self):
|
||||
return self.bias.next() + self.dds.next()
|
||||
v = self.bias.next() + self.dds.next()
|
||||
if not self.silence:
|
||||
self.last = v
|
||||
return self.last
|
||||
|
||||
|
||||
class TriggerError(Exception):
|
||||
@ -60,7 +65,7 @@ class TriggerError(Exception):
|
||||
class Synthesizer:
|
||||
def __init__(self, nchannels, program):
|
||||
self.channels = [Wave() for _ in range(nchannels)]
|
||||
self.program = program
|
||||
self.program = program
|
||||
# line_iter is None: "wait for segment selection" state
|
||||
# otherwise: iterator on the current position in the segment
|
||||
self.line_iter = None
|
||||
@ -78,33 +83,41 @@ class Synthesizer:
|
||||
while True:
|
||||
line = next(self.line_iter)
|
||||
|
||||
if line["dac_divider"] != 1:
|
||||
if line.get("dac_divider", 1) != 1:
|
||||
raise NotImplementedError
|
||||
|
||||
for channel, channel_data in zip(self.channels,
|
||||
line["channel_data"]):
|
||||
if "bias" in channel_data:
|
||||
channel.bias.set_coefficients(channel_data["bias"])
|
||||
channel.bias.set_coefficients(channel_data["bias"]["amplitude"])
|
||||
if "dds" in channel_data:
|
||||
channel.dds.amplitude.set_coefficients(
|
||||
channel_data["dds"]["amplitude"])
|
||||
channel.dds.phase.set_coefficients(
|
||||
channel_data["dds"]["phase"])
|
||||
if channel_data["dds"]["clear"]:
|
||||
if "phase" in channel_data["dds"]:
|
||||
channel.dds.phase.set_coefficients(
|
||||
channel_data["dds"]["phase"])
|
||||
if channel_data["dds"].get("clear", False):
|
||||
channel.dds.phase.clear()
|
||||
channel.silence = channel_data.get("silence", False)
|
||||
|
||||
for channel, rc in zip(self.channels, r):
|
||||
for i in range(line["duration"]):
|
||||
rc.append(channel.next())
|
||||
|
||||
if line["wait_trigger"] and line["jump"]:
|
||||
raise ValueError("Line cannot both jump and wait for trigger")
|
||||
if line["wait_trigger"]:
|
||||
if line.get("wait_trigger", False):
|
||||
return r
|
||||
if line["jump"]:
|
||||
if line.get("jump", False):
|
||||
if not line.get("wait_trigger", False):
|
||||
raise ValueError("Jumps should be with wait_trigger")
|
||||
try:
|
||||
next(self.line_iter)
|
||||
raise ValueError("Jump in the middle of a frame")
|
||||
except StopIteration:
|
||||
pass
|
||||
self.line_iter = None
|
||||
return r
|
||||
|
||||
|
||||
def main():
|
||||
from artiq.test.wavesynth import TestSynthesizer
|
||||
import cairoplot
|
||||
@ -114,5 +127,6 @@ def main():
|
||||
x, y = t.drive()
|
||||
cairoplot.scatter_plot("plot.png", [x, y])
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
Loading…
Reference in New Issue
Block a user