forked from M-Labs/artiq
1
0
Fork 0

wavesynth: implement silence, add defaults, fix bias

This commit is contained in:
Robert Jördens 2015-04-05 01:14:19 -06:00
parent 051b01f58e
commit 1f545346e3
1 changed files with 29 additions and 15 deletions

View File

@ -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):
@ -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()