[ create a new paste ] login | about

Link: http://codepad.org/bqINREKG    [ raw code | fork ]

D, pasted on Apr 27:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
// some generated float data
float[] data = new float[](256);
data[] = 1.0f;

// output data isn't explicitly typed because you only get this 
// information at runtime, it can be one of numerous types
// (int16, int32, float, double..)
void[] output;  // the soundcard initializes this buffer (assume size 256 in this code)

// soundcard tells us it wants sample data typed as ints, so we use that
int[] writeTo = cast(int[])output;

// actual conversion from float data to int data
foreach (inputSample, ref outputSample; lockstep(data, writeTo))
{
    outputSample = to!int((inputSample * 0x7FFF_0000) - 0.5f);
}


Create a new paste based on this one


Comments: