Is Python sometimes simply not fast enough for a task?

Viewed 97

I noticed a lack of good soundfont-compatible synthesizers written in Python. So, a month or so ago, I started some work on my own (for reference, it's here). Making this was also a challenge that I set for myself.

I keep coming up against the same problem again and again and again, summarized by this:

  1. To play sound, a stream of data with a more-or-less constant rate of flow must be sent to the audio device
  2. To synthesize sound in real time based on user input, little-to-no buffering can be used
  3. Thus, there is a cap on the amount of time one 'buffer generation loop' can take
  4. Python, as a language, simply cannot run fast enough to do synthesize sound within this time limit

The problem is not my code, or at least, I've tried to optimize it to extreme levels - using local variables in time-sensitive parts of the code, avoiding using dots to access variables in loops, using itertools for iteration, using pre-compiled macros like max, changing thread switching parameters, doing as few calculations as possible, making approximations, this list goes on.

Using Pypy helps, but even that starts to struggle after not too long.

It's worth noting that (at best) my synth at the moment can play about 25 notes simultaneously. But this isn't enough. Fluidsynth, a synth written in C, has a cap on the number of notes per instrument at 128 notes. It also supports multiple instruments at a time.

Is my assertion that Python simply cannot be used to write a synthesizer correct? Or am I missing something very important?

0 Answers
Related