# Programming Real-Time Sound in Python
## 6 Conclusions  
In this paper, we have made a short tour to show the potential and limits of Python for real-time sound programming, starting with a simple digital filter until more complex virtual analog models.  
\begin{table}
\begin{tabular}{c c c c c c c c c c} \hline \hline \multirow{2}{*}{**Load**} & \multicolumn{4}{c}{**Audio Only**} & \multicolumn{4}{c}{**GUI Operations**} & \multicolumn{4}{c}{**File Copy**} \\ \cline{2-10}  & **Idle** & **Process** & **Total** & **Idle** & **Process** & **Total** & **Idle** & **Process** & **Total** \\ \hline Min (ms) & 0.005 & 0.039 & 0.044 & 0.005 & 0.037 & 0.042 & 0.005 & 0.038 & 0.044 \\ \hline Max (ms) & 36.5 & 8.7 & 36.8 & 33.9 & 31.6 & 40.9 & 27.9 & 29.9 & 29.9 \\ \hline Average (ms) & 1.31 & 0.14 & 1.44 & 1.32 & 0.13 & 1.44 & 1.35 & 0.09 & 1.45 \\ \hline Violations (\%) & 11\% & 0.17\% & 11.2\% & 11\% & 0.8\% & 11.8\% & 11\% & 0.15\% & 11.2\% \\ \hline \hline \end{tabular}
\end{table}
Table 3: Statistics for the voltage-controlled filter running at different OS loads, with audio chunks of 64 samples: audio application only, audio application with I/O operations in the Python GUI, and audio application with copy of a directory tree in background.  
Figure 2: Timing of audio callbacks and audio processing in the voltage-controlled filter algorithm.  
If the interpreter alone has limited application, conversely refactoring critical parts of the code for libraries, like Numba or Cython, allows for also processing complex algorithms in real time. In particular:  
* those parts of the code which deal with environment setup, type conversions, user interaction, signal analysis and interface development can be left to the interpreter;
* procedures that do not need to intensively interact with the program workspace can be compiled with Numba;
* procedures, which, conversely, must often interact with the program workspace in terms of e.g., memory allocation or signal resampling and filtering, can be compiled with Cython; and,
* finally, already existing procedures written in C or other languages can also be efficiently cytthonized.  
Tests of two computationally-intensive sound algorithms were made under different OS loads, leading to accurate audio outputs with a latency of about 50 ms. Lower latency values were out of reach, due to the Python threading mechanism and its interaction with the OS scheduler. While this limit prevents from using the resulting applications in critical interactive music contexts, on the other hand Python certainly has potential for integrating sets of computationally-intensive algorithms in effective real-time simulation frameworks.  
Conceptualization, Y.D.P.; methodology, Y.D.P.; software, Y.D.P.; validation, Y.D.P.; formal analysis, Y.D.P.; investigation, Y.D.P.; resources, Y.D.P. and F.F.; data curation, Y.D.P.; writing-original draft preparation, Y.D.P.; writing-review and editing, Y.D.P. and F.F.; visualization, Y.D.P. and F.F.; supervision, F.F.; project administration, Y.D.P. and F.F.; funding acquisition, Y.D.P. and F.F. All authors have read and agreed to the published version of the manuscript.  
The APC was funded by Electrolux Professional SpA.  
We especially thank Anonymous Reviewer #1 for carefully reading this manuscript during every review round and contributing to its final form. [PERSON]'s was funded with a scholarship from the Research Hub by Electrolux Professional SpA.  
The authors declare no conflict of interest. The funders had no role in the design of the study; in the collection, analyses, or interpretation of data; in the writing of the manuscript, or in the decision to publish the results.