Programming Real-Time Sound in Python
Source abstract
Abstract
For its versatility, Python has become one of the most popular programming languages. In spite of its possibility to straightforwardly link native code with powerful libraries for scientific computing, the use of Python for real-time sound applications development is often neglected in favor of alternative programming languages, which are tailored to the digital music domain. This article introduces Python as a real-time software programming tool to interested readers, including Python developers who are new to the real time or, conversely, sound programmers who have not yet taken this language into consideration. Cython and Numba are proposed as libraries supporting agile development of efficient software running at machine level. Moreover, it is shown that refactoring few critical parts of the program under these libraries can dramatically improve the performances of a sound algorithm. Such improvements can be directly benchmarked within Python, thanks to the existence of appropriate code parsing resources. After introducing a simple sound processing example, two algorithms that are known from the literature are coded to show how Python can be effectively employed to program sound software. Finally, issues of efficiency are mainly discussed in terms of latency of the resulting applications. Overall, such issues suggest that the use of real-time Python should be limited to the prototyping phase, where the benefits of language flexibility prevail on low latency requirements, for instance, needed during computer music live performances.
Source: crossref · Quality: baseline
Research context
OpenAlex topics: Computational Physics and Python Applications · Music Technology and Sound Studies · Model Reduction and Neural Networks
SciVX discovery tags are terminology-based. OpenAlex topics are source-provided classifications.
Affiliations
HCI Lab, Department of Mathematics, Computer Science and Physics, University of Udine, 33100 Udine, Italy
References (38)
Show source-provided references
1. Rethinking the Computer Music Language: SuperCollider10.1162/014892602320991383 ↗
2. Adams, A.T., and Latulipe, C. (2013). Survey of Audio Programming Tools. CHI ‘13 Extended Abstracts on Human Factors in Computing Systems, ACM. CHI EA ’13.10.1145/2468356.2468495 ↗
3. Morreale, F., and McPherson, A.P. (2017, January 15–19). Design for longevity: Ongoing use of instruments from NIME 2010–14. Proceedings of the International Conference on New Interfaces for Musical Expression (NIME’17), Copenhagen, Denmark.
4. Programming Languages: A Survey
5. Guo, P. (2020, June 18). Python is Now the Most Popular Introductory Teaching Language at Top U.S. Universities. Available online: https://cacm.acm.org/blogs/blog-cacm/176450.
6. Raadt, M., and Carbone, A. (February, January 31). Trends in Introductory Programming Courses in Australian Universities Languages, Environments and Pedagogy. Proceedings of the Australasian Computing Education Conference (ACE2012), Melbourne, Australia. CRPIT.
7. Downey, A.B. (2016). Think DSP: Digital Signal Processing in Python, O’Reilly Media, Inc.. [1st ed.].
8. Sepúlveda, S., Reyes, P., and Weinstein, A. (2015, January 6–12). Visualizing physiological signals in real-time. Proceedings of the 14th Python in Science Conference (SciPy 2015), Austin, TX, USA.10.25080/Majora-7b98e3ed-01c ↗
9. Cython: The Best of Both Worlds10.1109/MCSE.2010.118 ↗
10. Wright, A., Damskägg, E.P., Juvela, L., and Välimäki, V. (2020). Real-Time Guitar Amplifier Emulation with Deep Learning. Appl. Sci., 10.10.3390/app10030766 ↗
11. Martínez Ramírez, M.A., Benetos, E., and Reiss, J.D. (2020). Deep Learning for Black-Box Modeling of Audio Effects. Appl. Sci., 10.10.3390/app10020638 ↗
12. De Pra, Y., Fontana, F., and Simonato, M. (2018, January 22–23). Development of real-time audio applications using Python. Proceedings of the XXII Colloquium of Musical Informatics, Udine, Italy.
13. Mathews, M.V., Miller, J.E., Moore, F.R., Pierce, J.R., and Risset, J.C. (1969). The Technology of Computer Music, MIT Press.
14. Vercoe, B., and Ellis, D. (1990, January 10–15). Real-time CSound: Software Synthesis with Sensing and Control. Proceedings of the International Computer Music Conference, Glasgow, Scotland.
15. Puckette, M. (1996, January 19–24). Pure Data: Another integrated computer music environment. Proceedings of the International Computer Music Conference, Hong Kong, China.
16. Cycling ’74 (2020, June 18). Max/MSP Website. Available online: https://cycling74.com/products/max/.
17. Wang, G., and Cook, P.R. (October, January 29). ChucK: A Concurrent, On-the-Fly, Audio Programming Language. Proceedings of the International Computer Music Conference, Singapore.
18. Fober, D., Orlarey, Y., and Letz, S. (2011, January 19–23). Faust Architectures Design and Osc Support. Proceedings of the International Conference on Digital Audio Effects (DAFx-11), Paris, France.
19. Glover, J.C., Lazzarini, V., and Timoney, J. (2011, January 6–8). Python for Audio Signal Processing. Proceedings of the Linux Audio Conference 2011, Maynooth, Ireland.10.1186/1687-6180-2011-68 ↗
20. McFee, B., Raffel, C., Liang, D., Ellis, D., McVicar, M., Battenberg, E., and Nieto, O. (2015, January 6–12). librosa: Audio and Music Signal Analysis in Python. Proceedings of the 14th Python in Science Conference, Austin, TX, USA.10.25080/Majora-7b98e3ed-003 ↗
21. Bellini, D. (2020, June 18). Expressive Digital Signal Processing (DSP) Package for Python. Available online: https://github.com/danilobellini/audiolazy.
22. Wickert, M. (2018, January 9–15). Real-Time Digital Signal Processing using pyaudio_helper and the ipywidgets. Proceedings of the 17th Python in Science Conference, Austin, TX, USA.10.25080/Majora-4af1f417-00e ↗
23. Belanger, O. (2016, January 15–19). Pyo, the Python DSP Toolbox. Proceedings of the 24th ACM International Conference on Multimedia, Amsterdam, The Netherlands.10.1145/2964284.2973804 ↗
24. ELK Audio (2020, June 18). Audio Latency Demystified. Available online: https://elk.audio/audio-latency-demystified-part-ii/.
25. Bencina, R. (2020, June 18). Real-Time Audio Programming. Available online: http://www.rossbencina.com/code/real-time-audio-programming-101-time-waits-for-nothing.
26. Pham, H. (2020, June 18). PyAudio Website. Available online: https://people.csail.mit.edu/hubert/pyaudio.
27. Stöter, F. (2020, June 18). Repository of Python Scientific Audio Packages. Available online: https://github.com/faroit/awesome-python-scientific-audio.
28. Mitra, S.K. (1998). Digital Signal Processing. A Computer-Based Approach, McGraw-Hill.
29. Explicit Fixed-Point Computation of Nonlinear Delay-Free Loop Filter Networks10.1109/TASLP.2018.2847442 ↗
30. Kern, R. (2020, June 18). Line Profiler Code Repository. Available online: https://github.com/rkern/line_profiler.
31. Lam, S.K., Pitrou, A., and Seibert, S. (2015, January 11). Numba: A LLVM-based python jit compiler. Proceedings of the Second Workshop on the LLVM Compiler Infrastructure in HPC, Austin, TX, USA.10.1145/2833157.2833162 ↗
32. The Computer Language Benchmarks Game (2020, June 18). Benchmark Python vs. C++. Available online: https://benchmarksgame-team.pages.debian.net/benchmarksgame/fastest/gpp-python3.html.
33. Milde, D. (2020, June 18). Benchmark Numba vs. Cython. Available online: https://pybenchmarks.org/u64q/numba.php.
34. Gorelick, M., and Ozsvald, I. (2014). High Performance Python: Practical Performant Programming for Humans, O’Reilly Media, Inc.
35. Ringle, E. (2020, June 18). Portaudio. Available online: https://github.com/EddieRingle/portaudio/blob/master/examples/.
36. Zölzer, U. (2011). DAFX: Digital Audio Effects, John Wiley & Sons.10.1002/9781119991298 ↗
37. Pedregosa, F. (2020, June 18). Memory Profiler Code Repository. Available online: https://github.com/pythonprofilers/memory_profiler.
38. Modeling of the EMS VCS3 Voltage-Controlled Filter as a Nonlinear Filter Network10.1109/TASL.2010.2046287 ↗