Skip to content

Commit

Permalink
fix sine operations
Browse files Browse the repository at this point in the history
  • Loading branch information
Kethen committed Aug 25, 2024
1 parent c6862ec commit 1bcb54f
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
8 changes: 4 additions & 4 deletions force_feedback.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
#define __set_bit(bit, field) {*(field) = *(field) | (1 << bit);}
#define __clear_bit(bit, field) {*(field) = *(field) & ~(1 << bit);}

#define sin16(in) (int16_t)(sin((double)(in) * (double)M_PI / 180.0))
#define sin_deg(in) (double)(sin((double)(in) * (double)M_PI / 180.0))

#define time_after_eq(a, b) (a >= b)
#define time_before(a, b) (a < b)
Expand Down Expand Up @@ -117,7 +117,7 @@ static void lg4ff_update_state(struct lg4ff_effect_state *state, const uint64_t
if (!test_bit(FF_EFFECT_UPDATING, &state->flags)) {
state->updated_at = state->play_at;
}
state->direction_gain = sin16(effect->direction * 360 / 0x10000);
state->direction_gain = sin_deg(effect->direction * 360 / 0x10000);
if (effect->type == FF_PERIODIC) {
state->phase_adj = effect->u.periodic.phase * 360 / effect->u.periodic.period;
}
Expand All @@ -130,7 +130,7 @@ static void lg4ff_update_state(struct lg4ff_effect_state *state, const uint64_t
if (test_bit(FF_EFFECT_UPDATING, &state->flags)) {
__clear_bit(FF_EFFECT_PLAYING, &state->flags);
state->play_at = state->updated_at + effect->replay.delay;
state->direction_gain = sin16(effect->direction * 360 / 0x10000);
state->direction_gain = sin_deg(effect->direction * 360 / 0x10000);
if (effect->replay.length) {
state->stop_at = state->updated_at + effect->replay.length;
}
Expand Down Expand Up @@ -233,7 +233,7 @@ static int32_t lg4ff_calculate_periodic(struct lg4ff_effect_state *state)

switch (periodic->waveform) {
case FF_SINE:
level += sin16(state->phase) * magnitude;
level += sin_deg(state->phase) * magnitude;
break;
case FF_SQUARE:
level += (state->phase < 180 ? 1 : -1) * magnitude;
Expand Down
2 changes: 1 addition & 1 deletion force_feedback.h
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ struct lg4ff_effect_state{
uint32_t cmd_start_count;
#endif

int32_t direction_gain;
double direction_gain;
int32_t slope;
};

Expand Down

0 comments on commit 1bcb54f

Please sign in to comment.