Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change output value calculation to 'round away from 0' instead 'floor'. #358

Merged
merged 2 commits into from
Jun 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions radio/src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -379,8 +379,6 @@ foreach(FILE ${PULSES_SRC})
set(SRC ${SRC} pulses/${FILE})
endforeach()

add_definitions(-DCORRECT_NEGATIVE_SHIFTS)

if(NOT MSVC)
set(WARNING_FLAGS "${WARNING_FLAGS} -Wall -Wno-address-of-packed-member -Wno-strict-aliasing -Wformat -Wreturn-type -Wunused -Wuninitialized -Wunknown-pragmas -Wno-switch -Wtype-limits")
if(WARNINGS_AS_ERRORS)
Expand Down
12 changes: 2 additions & 10 deletions radio/src/mixer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -261,16 +261,8 @@ int16_t applyLimits(uint8_t channel, int32_t value)
value = (int32_t) value * tmp; // div by 1024*256 -> output = -1024..1024
#endif

#ifdef CORRECT_NEGATIVE_SHIFTS
int8_t sign = (value<0?1:0);
value -= sign;
tmp = value>>16; // that's quite tricky: the shiftright 16 operation is assmbled just with addressmove; just forget the two least significant bytes;
tmp >>= 2; // now one simple shift right for two bytes does the rest
tmp += sign;
#else
tmp = value>>16; // that's quite tricky: the shiftright 16 operation is assmbled just with addressmove; just forget the two least significant bytes;
tmp >>= 2; // now one simple shift right for two bytes does the rest
#endif
// Round away from 0
tmp = (value + (value < 0 ? (1<<17)-1 : (1<<17))) >> 18;

ofs += tmp; // ofs can to added directly because already recalculated,
}
Expand Down