dumb icon indicating copy to clipboard operation
dumb copied to clipboard

Code optimization

Open ghost opened this issue 7 years ago • 3 comments

Hello ! I'm a C programmer using Dumb for .it playback, i'm happy with its accuracy, but i have to admit, it's one of the dumbest (ahah) piece of code i've seen. Such a bizarre architecture with unoptimized algorithms and duplicated code everywhere. I still wonder why the voices are mixed in that way:

  • multiply the input float by some huge value
  • cast to int64
  • multiply the sample with its volume level
  • do some bitshift to avoid overflowing the whole thing
  • cast again to float

Why don't use floats everywhere ? The conversion takes probably more time than the small speedup of int's

Also in the linear resampling algorithm, to keep the phase into 0...1 range you can simply do (phase-(int)phase) instead of fmod(phase,1) which is quite cpu demanding.

There is a bug in the channels and NNA channels numbers, if you set the #define channel_count (don't remember its exact name) to another value than 64 the program crashes, it's because the IT format uses a 64-element fixed size array for channel volumes/pans, disregarding the module's real channel count. You have to use 64 as fixed value when parsing the IT, then you can use the #define channel_count for mixing if you need for e :)

No offense, I really appreciate the overall work, having a pure C impulse tracker playback library that doesn't rely on 5000 dependencies is awesome. I'd be happy to contribute to the project if you feel like me that some optimization isn't bad :)

ghost avatar Oct 19 '16 15:10 ghost

Pull requests are welcome. Please verify that all optimizations have the intended performance enhancing effects on various platforms before filing, though.

For instance, the conversion to integer fixed point is currently used only for the per-sample volume ramping, and may actually be slower on some systems. It was actually faster on the system I developed it on originally, an Athlon64 3200+. Perhaps all float is faster now?

kode54 avatar Oct 20 '16 03:10 kode54

Thanks. I'll do some profiling to check if my modifications are worth. Floats are nearly as fast as ints, but with CPU pipelines you can sometimes perform some operations for free while you are doing other things, so actually it's possible that mixing types makes the algorithm faster

ghost avatar Oct 20 '16 07:10 ghost

Incidentally, samples are only float because of the newer resampler. I could probably turn that mess into integer as well, since pure integer math is actually faster. Well, unless you or someone else wants to craft fully SIMD optimized mixing code. What happened with this, anyway?

kode54 avatar Sep 14 '17 06:09 kode54