Compare commits
3 Commits
aaa42db2ae
...
0b36e31135
Author | SHA1 | Date | |
---|---|---|---|
0b36e31135 | |||
b7d92259a9 | |||
8378add874 |
@ -11,10 +11,10 @@ class CircBuffer:
|
||||
self.__buffer = np.zeros(
|
||||
(channels, size), dtype=np.double
|
||||
) # or dtype of your choice
|
||||
self.__time = np.zeros(size, dtype=np.double)
|
||||
self.__index = [0 for i in range(channels)]
|
||||
self.__is_full = [False for i in range(channels)]
|
||||
self.__totalcount = [0 for i in range(channels)]
|
||||
self.__time = [0.0 for i in range(channels)]
|
||||
self.__overflows = [0 for i in range(channels)]
|
||||
|
||||
@property
|
||||
@ -42,7 +42,9 @@ class CircBuffer:
|
||||
self.__buffer[channel, self.write_index(channel)] = item
|
||||
self.__index[channel] = (self.write_index(channel) + 1) % self.__size
|
||||
self.__totalcount[channel] += 1
|
||||
self.__time[channel] += 1 / self.__samplereate
|
||||
self.__time[self.write_index(channel=0)] = (
|
||||
self.__time[self.write_index(channel=0) - 1] + 1 / self.__samplereate
|
||||
)
|
||||
if self.__index[channel] == 0:
|
||||
self.__is_full[channel] = True
|
||||
self.__overflows[channel] += 1
|
||||
@ -107,11 +109,11 @@ class CircBuffer:
|
||||
extend = self.size
|
||||
return start, extend
|
||||
|
||||
def get(self, index: int = -1, channel: int = 0):
|
||||
def get(self, index: int = -1, channel: int = 0) -> Tuple[np.double, float]:
|
||||
# easy case first, we can spare the effort of further checking
|
||||
if index >= 0 and index <= self.write_index(channel):
|
||||
if self.has_value(index, channel):
|
||||
return self.__buffer[channel, index]
|
||||
return (self.__buffer[channel, index], self.__time[index])
|
||||
else:
|
||||
raise IndexError(
|
||||
f"Invalid index {index} on ring buffer for channel{channel}"
|
||||
@ -120,7 +122,7 @@ class CircBuffer:
|
||||
if index < 0:
|
||||
index = self.write_index() - 1
|
||||
if self.has_value(index, channel):
|
||||
return self.__buffer[channel, index]
|
||||
return (self.__buffer[channel, index], self.__time[index])
|
||||
else:
|
||||
raise IndexError(
|
||||
f"Invalid index {index} on ring buffer for channel{channel}"
|
||||
|
@ -32,10 +32,8 @@ class SinProducer:
|
||||
log.debug("producing Sin")
|
||||
start_time = time.time()
|
||||
t = 0
|
||||
while time.time() - start_time < 2:
|
||||
|
||||
while time.time() - start_time < 20:
|
||||
s = AMPLITUDE * np.sin(2 * np.pi * FREQUENCY * t)
|
||||
|
||||
self.buffer.append(s)
|
||||
t += 1 / self.buffer.samplerate
|
||||
time.sleep(1 / self.buffer.samplerate)
|
||||
|
@ -78,8 +78,9 @@ class PyRelacs(QMainWindow):
|
||||
widget.setLayout(layout)
|
||||
self.setCentralWidget(widget)
|
||||
|
||||
SAMPLERATE = 10000
|
||||
self.buffer = CircBuffer(size=1_000_000, samplerate=SAMPLERATE)
|
||||
SAMPLERATE = 1000
|
||||
BUFFERSIZE = 1_000
|
||||
self.buffer = CircBuffer(size=BUFFERSIZE, samplerate=SAMPLERATE)
|
||||
# self.connect_dac()
|
||||
|
||||
# self.daq_producer = DaqProducer(self.buffer, self.daq_device, [1, 1])
|
||||
@ -210,7 +211,7 @@ class PyRelacs(QMainWindow):
|
||||
sinus_pro.signals.progress.connect(self.progress_fn)
|
||||
self.threadpool.start(sinus_pro)
|
||||
|
||||
time.sleep(0.05)
|
||||
# time.sleep(0.05)
|
||||
self.continously_plot.plot_daq()
|
||||
|
||||
def stop_recording(self):
|
||||
|
Loading…
Reference in New Issue
Block a user