Casting a vector operation
Andrej Mitrovic
none at none.none
Wed Apr 27 15:43:03 PDT 2011
So, I need to convert a float[] to an int[] for some use with audio. The conversion operation is to multiply each sample (the value) with 0x7FFF_0000, and decrement with .5f, round this operation to an int and store it as the new sample.
So here's how a float>int conversion looks like:
http://codepad.org/bqINREKG
Now, I wanted to replace the foreach loop with a vector op. So first I've tried this:
writeTo[] = to!int((data[] * 0x7FFF_0000) - 0.5f)
This won't work. I've tried to do a simple cast:
writeTo[] = cast(int[])((data[] * 0x7FFF_0000) - 0.5f);
floatToInt.d(26): Error: Array operation data[] * 0x1.fffcp+30F - 0.5F not implemented
Same thing if I use to!int[]. I'm not sure what this error means.
Unfortunately I have little understanding of vector ops. Is there any way to use a vector op that operates on floats but stores each result as an int?
Btw, the *actual* definition of a single channel is:
void*[2] buffers;
These are two "half-buffers", meaning that the soundcard reads from one half-buffer while the client fills the other half.
Should I be worried that these are typed as void*? I mean I've read something about a GC problem where the GC could interpret the value stored in a void* as a pointer to random data in the heap, which could lead to memory leaks, or something of that sort.
More information about the Digitalmars-d-learn
mailing list