How can I convert SInt16 to double or Float32 to double? I know I can convert SInt16 to Float32 like this:
double *buffer;
SInt16* frames;
for (i = 0; i < number_of_frames; i++) {
Float32 currentFrame = frames[i] / 32768.0f;
}
but I’m using many C functions and I want to pass data to them in double.
Now I use this code:
for (i = 0; i < number_of_frames; i++) {
Float32 currentFrame = frames[i] / 32768.0f;
buffer[i] = currentFrame;
}
but I’m not sure the result is correct.
Primitive C types (integers, chars, floating point types) can be inter-converted with casts. So given a signed integer value
my_signed_integer, you can convert it to adoublewith a simple cast:I’m guessing your
Sint16andFloat32are typedefs, so you can still do the same thing:Eventually, this means:
Actually, you don’t need this cast.
frames[i]will be automatically converted todoublebecause of an implicit conversion.