How to: Group Audio Methods as an Operation Set

This topic shows you how you can group together XAudio2 methods so they take effect at the same time.

To group audio methods as an operation set

  1. Declare a global operation set counter.

    The operation set counter ensures that each operation set is unique.

    UINT32 OperationSetCounter = 0;
    
  2. Increment the global counter.

    Each time you submit a new operation set, the global counter should increment to ensure each set is unique.

    UINT32 OperationID = UINT32(InterlockedIncrement(LPLONG(&OperationSetCounter)));
    
  3. Group the method calls by setting their operation set parameters.

  4. Set the operation set parameters to the current value of the global counter.

    In this case, four calls to IXAudio2SourceVoice::Start are grouped as one operation set. Grouping the calls causes all four of the sounds to start at exactly the same time.

    hr = pSFXSourceVoice1->Start( 0, OperationID );
    hr = pSFXSourceVoice2->Start( 0, OperationID );
    hr = pSFXSourceVoice3->Start( 0, OperationID );
    hr = pSFXSourceVoice4->Start( 0, OperationID );
    
  5. Start the operation set.

    After you call all the methods in the set, start the set by calling IXAudio2::CommitChanges with the current value of the global counter.

    pXAudio2->CommitChanges(OperationID);
    

Operation Sets

XAudio2 Programming Guide

XAudio2 Operation Sets