Actually just found that solution in another post here!
It works wonders if i exclude the file from compiling;D
Now i just need to try to understand this DirectSound buffer thingy, my math sucks so have a hard time with it,
i get the principle though.
I had XAudio2 Working alongside before as i wanted to see if i could get that working,
but i can't get it to work in this case where he makes the "Game" provide a certain amount of samples or something.
Cause XAudio2 from my understanding has no such thing as a circular buffer, it just has a Queue,
And adding things to the Queue doesn't work in that way (basically cause i guess it just adds the same object and rewrites it over and over as it's a pointer to memory).
But even if tht wasn't the case it would add Much more to the queue then what time has actually passed.
Would like to solve that if possible (to learn about this stuff).
Here is some Code. (I work in Float for Audio, cause, why not).
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46 | real32 Samples[(48000 * 2)];
game_sound_output_buffer SoundBuffer = {};
if (GlobalDirectSoundBuffer)
{
SoundBuffer.SamplesPerSecond = SoundOutput.SamplesPerSecond;
SoundBuffer.SampleCount = BytesToWrite / SoundOutput.BytesPerSample;
SoundBuffer.Samples = Samples;
}
else
{
SoundBuffer.SamplesPerSecond = SoundOutput.SamplesPerSecond;
SoundBuffer.SampleCount = 48000;
SoundBuffer.Samples = Samples;
}
game_offscreen_buffer Buffer = {};
Buffer.BitmapMemory = GlobalBackBuffer.BitmapMemory;
Buffer.BitmapWidth = GlobalBackBuffer.BitmapWidth;
Buffer.BitmapHeight = GlobalBackBuffer.BitmapHeight;
Buffer.Pitch = GlobalBackBuffer.Pitch;
GameUpdateAndRender(&Buffer, 0, 0, &SoundBuffer);
if (SoundIsValid)
{
Win32FillSoundBuffer(&SoundOutput, BytesToLock, BytesToWrite, &SoundBuffer);
}
if (XAudio2System.SourceVoice)
{
XAUDIO2_VOICE_STATE VoiceStat;
XAudio2System.SourceVoice->GetState(&VoiceStat);
if (VoiceStat.BuffersQueued < 2)
{
// continue;
{
XAUDIO2_BUFFER Buffer = {};
Buffer.AudioBytes = (sizeof(Samples));
Buffer.pAudioData = (byte*)Samples;
XAudio2System.SourceVoice->SubmitSourceBuffer(&Buffer);
}
}
}
|
:D