Reputation: 21
there is a snippet of decompiled C code. In this part of the program, data from the wav file is processed. I can assume that this is signal normalization, but what is the purpose of the division into 4 different arrays? and then the code only works with the v69 array. Why multiply each byte by 0.0078125? Please help me understand what this code does!
CStdioFile::Read((CStdioFile *)&v54, v14, v13);
v15 = 0;
if ( v13 >= 4 )
{
do
{
v16 = (char)(*((_BYTE *)v14 + v15 + 1) ^ 0x80);
v17 = *((_BYTE *)v14 + v15 + 2);
*(&v69 + v15) = (double)(char)(*((_BYTE *)v14 + v15) ^ 0x80) * 0.0078125;
v18 = (double)v16 * 0.0078125;
v19 = (char)(v17 ^ 0x80);
v20 = *((_BYTE *)v14 + v15 + 3);
*(&v70 + v15) = v18;
v71[v15] = (double)v19 * 0.0078125;
v15 += 4;
*(&v68 + v15) = (double)(char)(v20 ^ 0x80) * 0.0078125;
}
while ( v15 < v13 - 3 );
}
for ( ; v15 < v13; *(&v68 + v15) = (double)v21 * 0.0078125 )
v21 = (char)(*((_BYTE *)v14 + v15++) ^ 0x80);
j__free(v14);
Upvotes: 0
Views: 160
Reputation: 12600
Apparently the values are of type signed char
, and the method maps them to the range from -1 inclusively to +1 exclusively.
0.0078125 is the reciprocal value of 128.
A signed char
has a range from -128 to +127. Multiplying a value of this range by 0.0078125 results in a value in the range -1 to +1. Of course it could not become +1 exactly, the maximum is +127 * 0.0078125 ≈ 0.9922.
Without having digged deeper, the XOR with 0x80 might handle the sign bit, presumed that two's complement is used with the signed char
.
Upvotes: 1
Reputation: 3897
Please always indicate what operating system you use when you decompile some strands of code like this one, because it contains no contextual informations.
What's decompiled here is rather C++ than plain C. The different arrays can hold many informations that are not directly related to your data (for example, addresses of virtual member functions).
0.0078125
as a double, however, resolves into 3F80000000000000
which is very likely a base address in some memory mapping system. Once compiled, the type information is lost and everything eventually ends up into one of the CPU registers. Using a double here was decompiler's best guess, and also the most concise way of writing down this particular value.
Upvotes: 0