Does anyone have a good SIMD log approximation?

A lot of use use the fast SIMD exponential approximation that’s in the rack sdk: approxExp2_taylor5.

Does anyone happen to have a good equivalent fast approximation for log? Enquiring minds want to know!

update: oh, gee, I haven’t even tried rack::simd::log yet. that might be good enough… But still interested in a super fast approx.

1 Like

Rack contains a port of some of Julien Pommier’s mathfun library. The sse_mathfun_log_ps function is included.

This is what rack::simd::log uses.

It looks like it’s a parallelisation of the corresponding code from the cephes library by Stephen L. Moshier, so it’s likely to be pretty good.

What I would really like, and I haven’t researched it yet, is a fast approximation to pow(x,y), in the case where \{x,y\}\in[0;1].

I know Bruce would do this with a 2D lookup table with interpolation, and I will probably do this, but if ever someone has any ideas or pointers, I’m all ears!

I haven’t studied it in enough detail to understand it yet. But the cephes library powf does it by exponentation and log.

xy = ey log(x)

It’s not clear to me without studying it harder if some parts can be discarded if you have those constraints. Nor how easy it would be to parallelise it.

1 Like

out of curiosity (related to your statement): how would you convert rack::simd::float_4 pitch = rack::simd::exp(semitones * kLN2Per12f); using approxExp2_taylor5?

note: kLN2Per12f is std::log(2.0f) / 12.0f;

thanks

Oh, right you are. It’s so well abstracted in the lib that I missed that. tx!

true, but with newer stuff I try to use SSE approximations instead of lookup tables since that tends to be better behaved and fast. But only when I can figure it out.

1 Like

Well, let me wave my hands a little! The formula for pitch is pitch = k * exp2(CV). So so base 2 exponentiation is already closer to what you want. The value of k depends on the definition of pitch(0) and how you handle sample rate, etc… I would say look in VCV Fundamental VCO1 for how to do this. I copied that for my recent VCOs.

I do have an entire repo, separate from my “commercial” modules whose entire purpose is to show how to write a decent VCO. Here’s a place where I do that calculation: Demo/VCO3.cpp at main · squinkylabs/Demo · GitHub

1 Like

Thanks for the reply.

Not sure about this: Demo/VCO3.cpp at main · squinkylabs/Demo · GitHub

Isn’t pitch expressed in semitones? What 0-10 range means for pitch param? V/oct? Shouldn’t be -5/5 so? (else you won’t pitch down).

I’d like to do somethings like -+60 semitones, so param 0.5 = +0st and CV (-5/5v) will modulate it -+60 so.

Pitch in vcv is expressed in volts. Refer to the vcv manual for more on that. Since a volt is an octave, yes 1/12 of a volt is a semitone. What do you mean “not so sure about this”? you mean you aren’t sure the VCOs in that repo play in tune? Try them out. The code have been reviewed by many people, including Andrew himself. But by all means the first thing you should look at for reference is the source code for VCV Fundamental VCO. Well, first thing look at the spec in the manual.

sorry man, i’ve expressed bad myself :slight_smile: i meant: now sure about what 0/10 param values means related to pitch (due to configParam(PITCH_PARAM, 0, 10, 4, “Initial Pitch”):wink:

is it just a draft? or set “4” means +4v? what about “decrease pitch” so? that’s all :slight_smile:

Oh, that. It’s totally arbitrary. It is, after all a demo. Most of my real vcos have an octave, semitone, and fine control. But, in this case I think I meant that a setting of 4 means that zero volts outputs C4, which is of course the standard pitch. So that knob lets you transpose from the normal pitch down 4 octave to transposed up 6 octaves. The pitch cv input CV adds to this. It is bipolar, so covers a huge range.

I should note that even though this is a simple example plugin, this sort of pitch control is fairly normal. Most VCO do something similar.

Please experiment with any VCO. Measure the output pitch with one of the tuner plugins. Put in various voltages, move the knobs, and see what happens. Build one of the open source VCOs and debug it or log the internal numbers.

1 Like