Skip to content

Commit e0f0886

Browse files
committed
remove slow and inaccurate math from time critical code
as it turns out, the "_t" functions (from wled_math.cpp) are about 3 times (!!!) slower than the standard functions. * mapping modes : Arc and Circle * effects: 2D Drift, 2D Drift Rose
1 parent ff56cf0 commit e0f0886

File tree

2 files changed

+16
-16
lines changed

2 files changed

+16
-16
lines changed

wled00/FX.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5062,8 +5062,8 @@ uint16_t mode_2DDrift() { // By: Stepko https://editor.soulmateli
50625062
unsigned long t_20 = t/20; // softhack007: pre-calculating this gives about 10% speedup
50635063
for (float i = 1; i < maxDim; i += 0.25) {
50645064
float angle = radians(t * (maxDim - i));
5065-
uint16_t myX = (cols>>1) + (uint16_t)(sin_t(angle) * i) + (cols%2);
5066-
uint16_t myY = (rows>>1) + (uint16_t)(cos_t(angle) * i) + (rows%2);
5065+
uint16_t myX = (cols>>1) + (uint16_t)(sinf(angle) * i) + (cols%2);
5066+
uint16_t myY = (rows>>1) + (uint16_t)(cosf(angle) * i) + (rows%2);
50675067
SEGMENT.setPixelColorXY(myX, myY, ColorFromPalette(SEGPALETTE, (i * 20) + t_20, 255, LINEARBLEND));
50685068
}
50695069
SEGMENT.blur(SEGMENT.intensity>>3);
@@ -5338,8 +5338,8 @@ uint16_t mode_2DJulia(void) { // An animated Julia set
53385338
reAl = -0.94299f; // PixelBlaze example
53395339
imAg = 0.3162f;
53405340

5341-
reAl += sin_t((float)strip.now/305.f)/20.f;
5342-
imAg += sin_t((float)strip.now/405.f)/20.f;
5341+
reAl += sinf((float)strip.now/305.f)/20.f;
5342+
imAg += sinf((float)strip.now/405.f)/20.f;
53435343

53445344
dx = (xmax - xmin) / (cols); // Scale the delta x and y values to our matrix size.
53455345
dy = (ymax - ymin) / (rows);
@@ -6067,8 +6067,8 @@ uint16_t mode_2Dghostrider(void) {
60676067
CRGB color = CRGB::White;
60686068
SEGMENT.wu_pixel(lighter->gPosX * 256 / 10, lighter->gPosY * 256 / 10, color);
60696069

6070-
lighter->gPosX += lighter->Vspeed * sin_t(radians(lighter->gAngle));
6071-
lighter->gPosY += lighter->Vspeed * cos_t(radians(lighter->gAngle));
6070+
lighter->gPosX += lighter->Vspeed * sinf(radians(lighter->gAngle));
6071+
lighter->gPosY += lighter->Vspeed * cosf(radians(lighter->gAngle));
60726072
lighter->gAngle += lighter->angleSpeed;
60736073
if (lighter->gPosX < 0) lighter->gPosX = (cols - 1) * 10;
60746074
if (lighter->gPosX > (cols - 1) * 10) lighter->gPosX = 0;
@@ -6090,8 +6090,8 @@ uint16_t mode_2Dghostrider(void) {
60906090
lighter->time[i] = 0;
60916091
lighter->reg[i] = false;
60926092
} else {
6093-
lighter->lightersPosX[i] += -7 * sin_t(radians(lighter->Angle[i]));
6094-
lighter->lightersPosY[i] += -7 * cos_t(radians(lighter->Angle[i]));
6093+
lighter->lightersPosX[i] += -7 * sinf(radians(lighter->Angle[i]));
6094+
lighter->lightersPosY[i] += -7 * cosf(radians(lighter->Angle[i]));
60956095
}
60966096
SEGMENT.wu_pixel(lighter->lightersPosX[i] * 256 / 10, lighter->lightersPosY[i] * 256 / 10, ColorFromPalette(SEGPALETTE, (256 - lighter->time[i])));
60976097
}
@@ -6303,8 +6303,8 @@ uint16_t mode_2Ddriftrose(void) {
63036303

63046304
SEGMENT.fadeToBlackBy(32+(SEGMENT.speed>>3));
63056305
for (size_t i = 1; i < 37; i++) {
6306-
uint32_t x = (CX + (sin_t(radians(i * 10)) * (beatsin8(i, 0, L*2)-L))) * 255.f;
6307-
uint32_t y = (CY + (cos_t(radians(i * 10)) * (beatsin8(i, 0, L*2)-L))) * 255.f;
6306+
uint32_t x = (CX + (sinf(radians(i * 10)) * (beatsin8(i, 0, L*2)-L))) * 255.f;
6307+
uint32_t y = (CY + (cosf(radians(i * 10)) * (beatsin8(i, 0, L*2)-L))) * 255.f;
63086308
SEGMENT.wu_pixel(x, y, CHSV(i * 10, 255, 255));
63096309
}
63106310
SEGMENT.blur((SEGMENT.intensity>>4)+1);

wled00/FX_fcn.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -892,8 +892,8 @@ void IRAM_ATTR_YN Segment::setPixelColor(int i, uint32_t col) //WLEDMM: IRAM_ATT
892892
float step = HALF_PI / (2.85f*i);
893893
for (float rad = 0.0f; rad <= HALF_PI+step/2; rad += step) {
894894
// may want to try float version as well (with or without antialiasing)
895-
int x = roundf(sin_t(rad) * i);
896-
int y = roundf(cos_t(rad) * i);
895+
int x = roundf(sinf(rad) * i);
896+
int y = roundf(cosf(rad) * i);
897897
setPixelColorXY(x, y, col);
898898
}
899899
// Bresenham’s Algorithm (may not fill every pixel)
@@ -923,8 +923,8 @@ void IRAM_ATTR_YN Segment::setPixelColor(int i, uint32_t col) //WLEDMM: IRAM_ATT
923923
case M12_sCircle: //WLEDMM
924924
if (vStrip > 0)
925925
{
926-
int x = roundf(sin_t(360*i/SEGLEN*DEG_TO_RAD) * vW * (vStrip+1)/nrOfVStrips());
927-
int y = roundf(cos_t(360*i/SEGLEN*DEG_TO_RAD) * vW * (vStrip+1)/nrOfVStrips());
926+
int x = roundf(sinf(360*i/SEGLEN*DEG_TO_RAD) * vW * (vStrip+1)/nrOfVStrips());
927+
int y = roundf(cosf(360*i/SEGLEN*DEG_TO_RAD) * vW * (vStrip+1)/nrOfVStrips());
928928
setPixelColorXY(x + vW/2, y + vH/2, col);
929929
}
930930
else // pArc -> circle
@@ -1101,8 +1101,8 @@ uint32_t Segment::getPixelColor(int i)
11011101
case M12_sCircle: //WLEDMM
11021102
if (vStrip > 0)
11031103
{
1104-
int x = roundf(sin_t(360*i/SEGLEN*DEG_TO_RAD) * vW * (vStrip+1)/nrOfVStrips());
1105-
int y = roundf(cos_t(360*i/SEGLEN*DEG_TO_RAD) * vW * (vStrip+1)/nrOfVStrips());
1104+
int x = roundf(sinf(360*i/SEGLEN*DEG_TO_RAD) * vW * (vStrip+1)/nrOfVStrips());
1105+
int y = roundf(cosf(360*i/SEGLEN*DEG_TO_RAD) * vW * (vStrip+1)/nrOfVStrips());
11061106
return getPixelColorXY(x + vW/2, y + vH/2);
11071107
}
11081108
else

0 commit comments

Comments
 (0)