History

Remove shift of signed int in src_float_to_short_array

Scale by -SHORT_MIN Clip if float is outside range of short Otherwise round and truncate (guaranteed to fit to short) Uses float instead of double as float can fit all 16 bit values

Alexander Grund committed 7 years ago

Commit a2e60101 parent ab8b4821 file · +11 −17Browse files

Showing the changes to src (1 of 1 file). Show all

Unified · Split

src/samplerate.c+11−17
@@ -495,24 +495,18 @@ src_short_to_float_array (const short *in, float *out, int len) · 494 unmodified lines
495495
496496 void
497497 src_float_to_short_array (const float *in, short *out, int len)
498−{ double scaled_value ;
499−
498+{
500499 while (len)
501− { len -- ;
502−
503− scaled_value = in [len] * (8.0 * 0x10000000) ;
504− if (CPU_CLIPS_POSITIVE == 0 && scaled_value >= (1.0 * 0x7FFFFFFF))
505− { out [len] = 32767 ;
506− continue ;
507− } ;
508− if (CPU_CLIPS_NEGATIVE == 0 && scaled_value <= (-8.0 * 0x10000000))
509− { out [len] = -32768 ;
510− continue ;
511− } ;
512−
513− out [len] = (short) (lrint (scaled_value) >> 16) ;
514− } ;
515−
500+ { float scaled_value ;
501+ len -- ;
502+ scaled_value = in [len] * 32768.f ;
503+ if (scaled_value >= 32767.f)
504+ out [len] = 32767 ;
505+ else if (scaled_value <= -32768.f)
506+ out [len] = -32768 ;
507+ else
508+ out [len] = (short) (lrintf (scaled_value)) ;
509+ }
516510 } /* src_float_to_short_array */
517511
518512 void

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t