Farmer Bob
1 posts
Making sure that TargetCursor is after WriteCursor
The documentation for DirectSoundBuffer.GetCurrentPostion says
"Data should not be written to the part of the buffer after the play cursor and before the write cursor." However, even though we get the WriteCursor, we don't do anything with it:
 1 if(SUCCEEDED(GlobalSecondaryBuffer->GetCurrentPosition(&PlayCursor, &WriteCursor))) 

Our target cursor does not take WriteCursor into account at all:
 1 2 3 4 TargetCursor = ((PlayCursor + (SoundOutput.LatencySampleCount*SoundOutput.BytesPerSample)) % SoundOutput.SecondaryBufferSize); 

On my machine the TargetCursor is always after the WriteCursor, but I think it's an accident, and not something we can be certain of. I put in an Assert like this:
 1 Assert(TargetCursor < PlayCursor || TargetCursor > WriteCursor); 

And I can trigger it by changing the LatencySampleCount:

 1 SoundOutput.LatencySampleCount = SoundOutput.SamplesPerSecond / 15; 

to:
 1 SoundOutput.LatencySampleCount = SoundOutput.SamplesPerSecond / 32; 

Is this an oversight, or something that will be tightened up later?

Also, I'm not really familiar with game audio concepts in general, like what LatencySampleCount really means or what the number "15" means (15 seconds of audio?). Can someone clarify?
Johan Öfverstedt
45 posts
Making sure that TargetCursor is after WriteCursor
FarmerBob

 1 SoundOutput.LatencySampleCount = SoundOutput.SamplesPerSecond / 15; 

to:
 1 SoundOutput.LatencySampleCount = SoundOutput.SamplesPerSecond / 32; 

Is this an oversight, or something that will be tightened up later?

Also, I'm not really familiar with game audio concepts in general, like what LatencySampleCount really means or what the number "15" means (15 seconds of audio?). Can someone clarify?

15 or 32 in this code snippet means a 15th of a second's worth of samples. If for example you run at a sample rate of 48000 samples/second, and take a 15th of a second you get 3200 samples. This corresponds to about 66.67ms of sound which can be calculated by 1000ms/15.