Can anybody suggest me, how to generate different left and right sounds?
When you write a stereo stream, you simply interleave the left and right samples - left1,right1,left2,right2,left3,etc...
Modifying the example above...
function MakeSine(handle: HSTREAM; buffer: Pointer; length: DWORD; user: DWORD): DWORD; stdcall;
i, len: Integer;
buf := buffer;
len := length div 4;
// write the sine function to the output stream
for i := 0 to len - 1 do begin
buf^ := Trunc(Sin(SineCount * PI) * Amplitude); // left
buf^ := Trunc(Sin(SineCount * PI) * Amplitude); // right
SineCount := SineCount + (Frequency / 44100);
Result := length;
Another question is about the length of the buffer:
len := length div 2
Why division by 2?
Because it's using 16-bit sample data, ie. 2 bytes per sample.
It becomes "div 4" in the modification above, because now it's stereo, ie. 2x 2 bytes per sample.