Skip to content

Conversation

philburk
Copy link
Collaborator

Use floatf() to fix non-linearity at 0.0.
Always clip when doing dithering to prevent numeric wrap-around.
Add extra half bit to compensate for bias when truncating.

Use floatf() to fix non-linearity at 0.0.
Always clip when doing dithering to prevent numeric wrap-around.
Add extra half bit to compensate for bias when truncating.
@philburk philburk requested a review from RossBencina July 24, 2025 22:57
@@ -574,7 +581,7 @@ static void Float32_To_Int16(

while( count-- )
{
short samp = (short) (*src * (32767.0f));
short samp = (short) floorf(*src * (32767.0f));
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe use PA_FLOAT_TO_INT32 here.

@philburk
Copy link
Collaborator Author

philburk commented Jul 31, 2025

TODO:

  • Check the CPU performance difference for these changes.
  • Check whether using floorf() can cause numeric wraparound for values just under -1.0.
  • Write mathematical definition of the required behavior. Then test the behavior. Document Sample Format Conversion Policies #1042

@RossBencina RossBencina added this to the V19.9 milestone Jul 31, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants