mirror of
https://github.com/mackron/miniaudio.git
synced 2026-04-22 00:06:59 +02:00
Small optimizations to some format conversion routines.
This commit is contained in:
@@ -36,9 +36,10 @@ u8->s32 {
|
||||
}
|
||||
|
||||
# r = (x / 255) * 2 - 1
|
||||
# = (x / 127.5) - 1
|
||||
# = (x * 0.00784313725490196078) - 1
|
||||
u8->f32 {
|
||||
div r x 255.0f;
|
||||
mul r r 2;
|
||||
mul r x 0.00784313725490196078f;
|
||||
sub r r 1;
|
||||
}
|
||||
|
||||
@@ -60,11 +61,12 @@ s16->s32 {
|
||||
shl r x 16;
|
||||
}
|
||||
|
||||
# r = ((x + 32768) / 65536) * 2 - 1
|
||||
# r = ((x + 32768) / 65535) * 2 - 1
|
||||
# = (x + 32768) / 32767.5) - 1
|
||||
# = (x + 32768) * 0.00003051804379339284) - 1
|
||||
s16->f32 {
|
||||
add r x 32768.0f;
|
||||
div r r 65536.0f;
|
||||
mul r r 2;
|
||||
add (flt)r x 32768;
|
||||
mul r r 0.00003051804379339284f;
|
||||
sub r r 1;
|
||||
}
|
||||
|
||||
@@ -87,10 +89,11 @@ s24->s32 {
|
||||
}
|
||||
|
||||
# r = ((x + 8388608) / 16777215) * 2 - 1
|
||||
# = (x + 8388608) / 8388607.5) - 1
|
||||
# = (x + 8388608) * 0.00000011920929665621) - 1
|
||||
s24->f32 {
|
||||
add r x 8388608.0f;
|
||||
div r r 16777215.0f;
|
||||
mul r r 2;
|
||||
add (flt)r x 8388608;
|
||||
mul r r 0.00000011920929665621f;
|
||||
sub r r 1;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user