diff --git a/mini_al.h b/mini_al.h index 9be3a2bf..4cf214a9 100644 --- a/mini_al.h +++ b/mini_al.h @@ -2443,7 +2443,6 @@ static void mal_channel_mask_to_channel_map__win32(DWORD dwChannelMask, mal_uint #include #include #include -//#include #if defined(_MSC_VER) #pragma warning(pop) #endif @@ -8727,8 +8726,7 @@ void mal_pcm_u8_to_f32(float* pOut, const unsigned char* pIn, unsigned int count float r; for (unsigned int i = 0; i < count; ++i) { int x = pIn[i]; - r = x / 255.0f; - r = r * 2; + r = x * 0.00784313725490196078f; r = r - 1; pOut[i] = (float)r; } @@ -8770,9 +8768,8 @@ void mal_pcm_s16_to_f32(float* pOut, const short* pIn, unsigned int count) float r; for (unsigned int i = 0; i < count; ++i) { int x = pIn[i]; - r = x + 32768.0f; - r = r / 65536.0f; - r = r * 2; + r = (float)(x + 32768); + r = r * 0.00003051804379339284f; r = r - 1; pOut[i] = (float)r; } @@ -8814,9 +8811,8 @@ void mal_pcm_s24_to_f32(float* pOut, const void* pIn, unsigned int count) float r; 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; - r = x + 8388608.0f; - r = r / 16777215.0f; - r = r * 2; + r = (float)(x + 8388608); + r = r * 0.00000011920929665621f; r = r - 1; pOut[i] = (float)r; } diff --git a/resources/format_conversions.txt b/resources/format_conversions.txt index f2360c15..a1d7e3c5 100644 --- a/resources/format_conversions.txt +++ b/resources/format_conversions.txt @@ -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; } diff --git a/tools/malgen/source/malgen.cpp b/tools/malgen/source/malgen.cpp index 5c939951..99ba2884 100644 --- a/tools/malgen/source/malgen.cpp +++ b/tools/malgen/source/malgen.cpp @@ -441,7 +441,7 @@ std::string malgen_generate_code__conversion_func_inst_binary_op(const char* res char typeStr[64]; strncpy_s(typeStr, result, resultVar - result); - code += typeStr; code += "("; code += assignmentStr; code += ")"; + code += malgen_format_op_param(typeStr); code += "("; code += assignmentStr; code += ")"; return code; } else { code += assignmentStr;