I'm writing a proof-of-concept demo that, without getting into too many specifics, is supposed to determine whether or not it's feasible to use an onboard sound-chip for some or all of the audio processing in a clinical audiometer. Strange but true.
I've started off with DirectSound because, with some little prior Dx knowledge, it was the fastest way to get up and running. I wouldn't be opposed to other suggestions, however, if they would solve the issue(s) I encounter.
The main problem right now, is with volume changes. The requirements for the demo include finer control over the output volume than DirectSound (which I assume maps to the sound chip's attenuator) can give, so the propsed solution is to change the waveform's max amplitude to get the extra steps we need.
That works, but there are a couple problems. The main one is that the attenuator change doesn't occur at zero crossing, so there is an audible click when it occurs. I tried a few different fixes, and the most promising one is setting up 2 buffers. The first would play the dynamically generated waveform at the old attenuator/amplitude settings, and the other plays silence. When a volume change is requested, the 2nd buffer's attenuator is set to the new value, and the 2 buffers cross-fade with the first ending up silent, the 2nd ending up at an amplitude which, when combined with the new attenutator, results in zero net volume change. Then the 2nd buffer's amplitude can be moved to the new target value. If the two buffers are synchronized the resulting volume change is click-less.
The problem is synchronizing the buffers. When playing the two buffers a latency is introduced between the buffers. This seemed simple enough to fix, just read the two play cursors and adjust the write position of the 2nd buffer to compensate, but reading the play cursors is not reliable (at least not to the resolution I need).
So the questions are: Is there a way of synchronizing 2 DirectSound buffers to line up the play cursors exactly? Is there an easier/better way of getting rid of the attenuator change click? Or for the pessimists in the crowd (a group I am thinking of joining shortly), are there any other brick walls I'm going to run into trying to do this kind of detailed low-level audio with DirectSound/XAudio?