Commit 4cbeff8f authored by David Reid's avatar David Reid

Small optimizations to some format conversion routines.

parent d68ed4f8
...@@ -2443,7 +2443,6 @@ static void mal_channel_mask_to_channel_map__win32(DWORD dwChannelMask, mal_uint ...@@ -2443,7 +2443,6 @@ static void mal_channel_mask_to_channel_map__win32(DWORD dwChannelMask, mal_uint
#include <audioclient.h> #include <audioclient.h>
#include <audiopolicy.h> #include <audiopolicy.h>
#include <mmdeviceapi.h> #include <mmdeviceapi.h>
//#include <functiondiscoverykeys_devpkey.h>
#if defined(_MSC_VER) #if defined(_MSC_VER)
#pragma warning(pop) #pragma warning(pop)
#endif #endif
...@@ -8727,8 +8726,7 @@ void mal_pcm_u8_to_f32(float* pOut, const unsigned char* pIn, unsigned int count ...@@ -8727,8 +8726,7 @@ void mal_pcm_u8_to_f32(float* pOut, const unsigned char* pIn, unsigned int count
float r; float r;
for (unsigned int i = 0; i < count; ++i) { for (unsigned int i = 0; i < count; ++i) {
int x = pIn[i]; int x = pIn[i];
r = x / 255.0f; r = x * 0.00784313725490196078f;
r = r * 2;
r = r - 1; r = r - 1;
pOut[i] = (float)r; pOut[i] = (float)r;
} }
...@@ -8770,9 +8768,8 @@ void mal_pcm_s16_to_f32(float* pOut, const short* pIn, unsigned int count) ...@@ -8770,9 +8768,8 @@ void mal_pcm_s16_to_f32(float* pOut, const short* pIn, unsigned int count)
float r; float r;
for (unsigned int i = 0; i < count; ++i) { for (unsigned int i = 0; i < count; ++i) {
int x = pIn[i]; int x = pIn[i];
r = x + 32768.0f; r = (float)(x + 32768);
r = r / 65536.0f; r = r * 0.00003051804379339284f;
r = r * 2;
r = r - 1; r = r - 1;
pOut[i] = (float)r; pOut[i] = (float)r;
} }
...@@ -8814,9 +8811,8 @@ void mal_pcm_s24_to_f32(float* pOut, const void* pIn, unsigned int count) ...@@ -8814,9 +8811,8 @@ void mal_pcm_s24_to_f32(float* pOut, const void* pIn, unsigned int count)
float r; float r;
for (unsigned int i = 0; i < count; ++i) { for (unsigned int i = 0; i < count; ++i) {
int x = ((int)(((unsigned int)(((unsigned char*)pIn)[i*3+0]) << 8) | ((unsigned int)(((unsigned char*)pIn)[i*3+1]) << 16) | ((unsigned int)(((unsigned char*)pIn)[i*3+2])) << 24)) >> 8; int x = ((int)(((unsigned int)(((unsigned char*)pIn)[i*3+0]) << 8) | ((unsigned int)(((unsigned char*)pIn)[i*3+1]) << 16) | ((unsigned int)(((unsigned char*)pIn)[i*3+2])) << 24)) >> 8;
r = x + 8388608.0f; r = (float)(x + 8388608);
r = r / 16777215.0f; r = r * 0.00000011920929665621f;
r = r * 2;
r = r - 1; r = r - 1;
pOut[i] = (float)r; pOut[i] = (float)r;
} }
......
...@@ -36,9 +36,10 @@ u8->s32 { ...@@ -36,9 +36,10 @@ u8->s32 {
} }
# r = (x / 255) * 2 - 1 # r = (x / 255) * 2 - 1
# = (x / 127.5) - 1
# = (x * 0.00784313725490196078) - 1
u8->f32 { u8->f32 {
div r x 255.0f; mul r x 0.00784313725490196078f;
mul r r 2;
sub r r 1; sub r r 1;
} }
...@@ -60,11 +61,12 @@ s16->s32 { ...@@ -60,11 +61,12 @@ s16->s32 {
shl r x 16; 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 { s16->f32 {
add r x 32768.0f; add (flt)r x 32768;
div r r 65536.0f; mul r r 0.00003051804379339284f;
mul r r 2;
sub r r 1; sub r r 1;
} }
...@@ -87,10 +89,11 @@ s24->s32 { ...@@ -87,10 +89,11 @@ s24->s32 {
} }
# r = ((x + 8388608) / 16777215) * 2 - 1 # r = ((x + 8388608) / 16777215) * 2 - 1
# = (x + 8388608) / 8388607.5) - 1
# = (x + 8388608) * 0.00000011920929665621) - 1
s24->f32 { s24->f32 {
add r x 8388608.0f; add (flt)r x 8388608;
div r r 16777215.0f; mul r r 0.00000011920929665621f;
mul r r 2;
sub r r 1; sub r r 1;
} }
......
...@@ -441,7 +441,7 @@ std::string malgen_generate_code__conversion_func_inst_binary_op(const char* res ...@@ -441,7 +441,7 @@ std::string malgen_generate_code__conversion_func_inst_binary_op(const char* res
char typeStr[64]; char typeStr[64];
strncpy_s(typeStr, result, resultVar - result); strncpy_s(typeStr, result, resultVar - result);
code += typeStr; code += "("; code += assignmentStr; code += ")"; code += malgen_format_op_param(typeStr); code += "("; code += assignmentStr; code += ")";
return code; return code;
} else { } else {
code += assignmentStr; code += assignmentStr;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment