bef07961ab
I noticed that the loop over 65535 possible denominators took a long time, causing up to 100ms wait for a sound sample to start playing! This algorithm, adapted from an algorithm shown in Python's fractions.py, is guaranteed to find the best denominator in a small number of steps (I think log2-many steps but I'm not sure). In practice, it means the time between samples playing is just 10ms, and some of that is recreating the sine wave sample in Python each time. It often finds the same solution as the old code, but sometimes it finds one a bit better since it compares the ratios using float point instead of integer arithmetic. |
||
---|---|---|
.. | ||
__init__.c | ||
PWMAudioOut.c | ||
PWMAudioOut.h |