Skip to content

Commit d1e84e1

Browse files
authored
Hotfix bdf recording (#445)
* change depricated function * Flush EDF buffer at quarter-second intervals Reduce the threshold for writing EDF samples from _fs to _fs // 4 so buffered data is flushed more frequently. Previously the FileRecorder only wrote when the buffer exceeded one second of samples; this change triggers writes at roughly quarter-second increments to lower memory usage and latency while retaining the existing behavior of writing full _fs-sized chunks and updating annotations/timestamps under the same lock. * Write full-second sample blocks to file Replace the previous arbitrary threshold write logic with computation of whole-second sample blocks: compute num_samples_to_write as (n_samples // fs) * fs and only write when > 0. This ensures written chunks are multiples of the sampling frequency, avoids partial-frame writes and potential timestamp/data misalignment, and then drops the written samples from the buffer.
1 parent 2e086cb commit d1e84e1

1 file changed

Lines changed: 4 additions & 3 deletions

File tree

src/explorepy/tools.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -362,10 +362,11 @@ def _write_edf(self, packet):
362362
self._data = np.concatenate((self._data, data), axis=1)
363363
self._timestamps += list(data[0, :])
364364
with lock:
365-
if self._data.shape[1] > self._fs // 4:
366-
self._file_obj.writeSamples(list(self._data[:, :self._fs]))
365+
num_samples_to_write = (self._data.shape[1] // self._fs) * self._fs
366+
if num_samples_to_write > 0:
367+
self._file_obj.writeSamples(list(self._data[:, :num_samples_to_write]))
367368
self._write_edf_anno()
368-
self._data = self._data[:, self._fs:]
369+
self._data = self._data[:, num_samples_to_write:]
369370

370371
def _process_packet_data(self, packet):
371372
"""Helper function to extract and format data from a packet."""

0 commit comments

Comments
 (0)