Is there somewhere a fast version of the Arduino map function hidden in FastLED?

Is there somewhere a fast version of the Arduino map function hidden in FastLED?

Yeah, there’s map8 in lib8tion.h: https://github.com/FastLED/FastLED/blob/FastLED2.1/lib8tion.h

Cool, thanks!

What are the ranges you’re mapping from and to?

I need to expand values from a part of the byte range to the full range 0-255.
Wait… this is a simple rule of three problem?!
What I need for values is called compressor in audio editing…

What’s the specific input range? Is it known ahead of time? (e.g… 0…200, or 100-150, etc.)

More like e.g. 23-42. What means “ahead of time”? Before the next frame: yes. At compile time: no. During runtime: yes.
My specific problem is to increase the contrast in a frame without just clipping which causes flickering edges. Like sharpening AND softening the edges at once.

Are you increasing from a set range to another set range?

Yes from an real time calculated set to the maximum range set.

Yeah, map8 is more for compressing a range than expanding it. I’ll see if I can think of the fastest way to do this (or at least A fast way), but there might have to be a divide in the middle (which is not so fast)…

A basic map function:

float linear(float i, float imin, float imax, float omin, float omax)
{
if (i < imin) {i = imin;}
if (i > imax) {i = imax;}
float o = ((omax-omin)*((i-imin)/(imax-imin))+omin);
return o;
}

I presume you’re using a Teensy 3.1?

In which case I would worry about an odd floating point calculation — it doesn’t really affect stuff much

Right now I work with an AVR (all the videos show patterns caclulated on a 16MHz 4k RAM ATMEGA2560) which means I have to think about saving time.
I avoided using floats in general since I care about speed. If precision is needed 16 bit integer math is the better way to go in my opinion.

Give a floating point a go and time it — that way you can benchmark it.

(That function can be split apart so there’s only one float operation)

(and: exercise for the reader: convert it to fixed-point and benchmark it :wink: