mirror of https://github.com/m-labs/artiq.git
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):
|
def next(self):
|
||||||
r = self.c[0]
|
r = self.c[0]
|
||||||
for i in range(len(self.c)-1):
|
for i in range(len(self.c) - 1):
|
||||||
self.c[i] += self.c[i+1]
|
self.c[i] += self.c[i + 1]
|
||||||
return r
|
return r
|
||||||
|
|
||||||
|
|
||||||
|
@ -30,8 +30,8 @@ class SplinePhase:
|
||||||
|
|
||||||
def next(self):
|
def next(self):
|
||||||
r = self.c[0] + self.c0
|
r = self.c[0] + self.c0
|
||||||
for i in range(len(self.c)-1):
|
for i in range(len(self.c) - 1):
|
||||||
self.c[i] = (self.c[i] + self.c[i+1]) % 1.0
|
self.c[i] = (self.c[i] + self.c[i + 1]) % 1.0
|
||||||
return r
|
return r
|
||||||
|
|
||||||
|
|
||||||
|
@ -48,9 +48,14 @@ class Wave:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.bias = Spline()
|
self.bias = Spline()
|
||||||
self.dds = DDS()
|
self.dds = DDS()
|
||||||
|
self.last = 0.
|
||||||
|
self.silence = False
|
||||||
|
|
||||||
def next(self):
|
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):
|
class TriggerError(Exception):
|
||||||
|
@ -78,33 +83,41 @@ class Synthesizer:
|
||||||
while True:
|
while True:
|
||||||
line = next(self.line_iter)
|
line = next(self.line_iter)
|
||||||
|
|
||||||
if line["dac_divider"] != 1:
|
if line.get("dac_divider", 1) != 1:
|
||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
|
|
||||||
for channel, channel_data in zip(self.channels,
|
for channel, channel_data in zip(self.channels,
|
||||||
line["channel_data"]):
|
line["channel_data"]):
|
||||||
if "bias" in 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:
|
if "dds" in channel_data:
|
||||||
channel.dds.amplitude.set_coefficients(
|
channel.dds.amplitude.set_coefficients(
|
||||||
channel_data["dds"]["amplitude"])
|
channel_data["dds"]["amplitude"])
|
||||||
channel.dds.phase.set_coefficients(
|
if "phase" in channel_data["dds"]:
|
||||||
channel_data["dds"]["phase"])
|
channel.dds.phase.set_coefficients(
|
||||||
if channel_data["dds"]["clear"]:
|
channel_data["dds"]["phase"])
|
||||||
|
if channel_data["dds"].get("clear", False):
|
||||||
channel.dds.phase.clear()
|
channel.dds.phase.clear()
|
||||||
|
channel.silence = channel_data.get("silence", False)
|
||||||
|
|
||||||
for channel, rc in zip(self.channels, r):
|
for channel, rc in zip(self.channels, r):
|
||||||
for i in range(line["duration"]):
|
for i in range(line["duration"]):
|
||||||
rc.append(channel.next())
|
rc.append(channel.next())
|
||||||
|
|
||||||
if line["wait_trigger"] and line["jump"]:
|
if line.get("wait_trigger", False):
|
||||||
raise ValueError("Line cannot both jump and wait for trigger")
|
|
||||||
if line["wait_trigger"]:
|
|
||||||
return r
|
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
|
self.line_iter = None
|
||||||
return r
|
return r
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
from artiq.test.wavesynth import TestSynthesizer
|
from artiq.test.wavesynth import TestSynthesizer
|
||||||
import cairoplot
|
import cairoplot
|
||||||
|
@ -114,5 +127,6 @@ def main():
|
||||||
x, y = t.drive()
|
x, y = t.drive()
|
||||||
cairoplot.scatter_plot("plot.png", [x, y])
|
cairoplot.scatter_plot("plot.png", [x, y])
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
main()
|
main()
|
||||||
|
|
Loading…
Reference in New Issue