Skip to content

Realtime: input numpy view allocated inside the audio callback #87

Description

@matteospanio

Bug

SoundDeviceBackend pre-allocates the output numpy view once (sounddevice_backend.py:267, _out_np), but the input path calls self._input_tensor.numpy() inside the PortAudio callback on every invocation (line ~295). .numpy() on a CPU tensor creates a view, but it still constructs a new ndarray object per callback (Python allocation + refcount churn on the RT thread), which is exactly what the pre-allocated output view exists to avoid.

Fix

Pre-allocate _in_np = self._input_tensor.numpy() next to _out_np and reuse it in the callback. Keeps the callback allocation-free, consistent with the latency-tail claims in the realtime instrumentation.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingperformanceShould be done faster or could be optimizedrealtimeReal-time / streaming

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions