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

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
495 495
496void496void
497src_float_to_short_array (const float *in, short *out, int len)497src_float_to_short_array (const float *in, short *out, int len)
498{ double scaled_value ;498{
499
500 while (len)499 while (len)
501 { len -- ;500 { float scaled_value ;
502 501 len -- ;
503 scaled_value = in [len] * (8.0 * 0x10000000) ;502 scaled_value = in [len] * 32768.f ;
504 if (CPU_CLIPS_POSITIVE == 0 && scaled_value >= (1.0 * 0x7FFFFFFF))503 if (scaled_value >= 32767.f)
505 { out [len] = 32767 ;504 out [len] = 32767 ;
506 continue ;505 else if (scaled_value <= -32768.f)
507 } ;506 out [len] = -32768 ;
508 if (CPU_CLIPS_NEGATIVE == 0 && scaled_value <= (-8.0 * 0x10000000))507 else
509 { out [len] = -32768 ;508 out [len] = (short) (lrintf (scaled_value)) ;
510 continue ;509 }
511 } ;
512
513 out [len] = (short) (lrint (scaled_value) >> 16) ;
514 } ;
515
516} /* src_float_to_short_array */510} /* src_float_to_short_array */
517 511
518void512void

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