XNA Creators Club Online
Page 1 of 1 (3 items)
Sort Posts: Previous Next

Sync'ing buffers

Last post 05-04-2008 12:43 AM by Dugan. 2 replies.
  • 04-22-2008 12:39 PM

    Sync'ing buffers

    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?
  • 04-22-2008 2:22 PM In reply to

    Re: Sync'ing buffers

    Is there a way of synchronizing 2 DirectSound buffers to line up the play cursors exactly?


    No. You should do your own mixing if that's what you want. Or use some lower-level technology, like KS or ASIO (although different devices have different capabilities).

    For the volume changes, you could ramp the volume across the duration of a buffer, using floating-point volume. That will avoid glitching. Again, you'll have to do your own processing/mixing for this.

    Jon Watte, Direct3D MVP kW X-port 3ds Max .X exporter kW Animation source code
  • 05-04-2008 12:43 AM In reply to

    Re: Sync'ing buffers

    The new XAudio2 API addresses this to some extent.  Synchronized playback and precise volume control were two of the DirectSound shortcoming we wanted to address.  When you set a volume on an XAudio2 voice it will ramp to the new volume over a very short period (5ms on Xbox, 10ms on Windows), but long enough to avoid a click.  However, if you do your own ramping it seems that you'll get everything you need, regardless of the underlying audio API, unless I'm missing something...

    Dugan Porter [MS]
    Game Audio Team

    Dugan Porter [MS]
    Game Audio Team
Page 1 of 1 (3 items) Previous Next
var gDomain='m.webtrends.com'; var gDcsId='dcschd84w10000w4lw9hcqmsz_8n3x'; var gTrackEvents=1; var gFpc='WT_FPC'; /*<\/scr"+"ipt>");} /*]]>*/
DCSIMG