Skip to content

Optimization: avoid cast to double in src_short_to_float #230

@jgcodes2020

Description

@jgcodes2020

The current implementation of src_short_to_float looks like this:

void
src_short_to_float_array (const short *in, float *out, int len)
{
for (int i = 0 ; i < len ; i++)
{ out [i] = (float) (in [i] / (1.0 * 0x8000)) ;
} ;
return ;
} /* src_short_to_float_array */

(1.0 * 0x8000) yields a double and so the division is done in doubles, requiring a few extra casts. This can be avoided by doing it in floats like this:

void
src_short_to_float_array (const short *in, float *out, int len)
{
	for (int i = 0 ; i < len ; i++)
	{	out [i] = (float) (in [i] / (1.0f * 0x8000)) ;
		} ;


	return ;
} /* src_short_to_float_array */

This should yield identical results because 1/32768 is an exact power of 2.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions