3 ms·
Yup, making it fast is no problem; I was just concerned about achieving low latency without dropping samples. The typical cookbook examples usually output to ma
by n3k5 6y ago
Yup, making it fast is no problem; I was just concerned about achieving low latency without dropping samples. The typical cookbook examples usually output to matplotlib or maybe an audio file, rather than straight to DAC, and I had amplified such search results by specifically looking for Jupyter examples (and also missed a lot of work that was done when it was still called IPython).
Upon digging a bit deeper it turns out using vanilla SciPy for real-time DSP is totally a thing.
Live-coding adds some additional demands regarding a different kind of latency — pre-computations need to happen as quickly as possible — but it seems feasible.
- amelius 6y agoInteresting! Could you share some of the links that you came across in your exploration?
- n3k5 6y agoBasically I just skimmed through https://www.google.com/search?q=scipy+dsp+real-time https://www.google.com/search?q=scipy+dsp+real-time and weeded out false positives that do use SciPy in some capacity, but also more specialised stuff such as the aforementioned Pyo. This mostly got rid of the music-related stuff (à la ‘what if guitar effect but Python instead of sclang’) and left me with e.g. Stack Overflow posts that simply confirm ‘yes, it's feasible’. But I have two noteworthy links: https://warrenweckesser.github.io/papers/weckesser-scipy-linear-filters.pdf https://warrenweckesser.github.io/papers/weckesser-scipy-lin... Particularly “Filtering a long signal in batches” on page 6, where it shows how to apply the Butterworth filter from the previous section to individual windows while preserving its state across invocations. As I'm familiar with NumPy, but very ignorant about scipy.signal, this was the ‘Bingo!’ moment for me :) https://scikit-dsp-comm.readthedocs.io/en/latest/ https://scikit-dsp-comm.readthedocs.io/en/latest/ > This allows in particular demodulation of radio signals and downsampling to baseband analog signals for streaming playback of say an FM broadcast station. I didn't dig into where it does the heavy lifting for that (sample rates in the MHz range) — there may be some C/C++ involved. But the docs show some nice examples of how to do streaming audio DSP with NumPy, SciPy and PyAudio inside Jupyter: https://scikit-dsp-comm.readthedocs.io/en/latest/nb_examples/Real-Time-DSP_Using_pyaudio_helper_and_ipywidgets.html https://scikit-dsp-comm.readthedocs.io/en/latest/nb_examples...