XNA Creators Club Online
community forums
Page 1 of 1 (6 items)
Sort Posts: Previous Next

XAudio2

Last post 04-01-2008 6:38 PM by The Luminous Aardvark. 5 replies.
  • 03-16-2008 9:26 PM

    XAudio2

    Hi,

        I have been playing around with XAudio2 since it's first incarnation in the August 2007 DirectX SDK. I have an annoyance and seeing as the Beta is now closed I don't know where else to express it so I guess here is the best place to start.

        My goal from the start was to write a .NET Assembly for XAudio2 with all the COM interfaces and C++ structures neatly wrapped up into managed code. Which i've done and works nicely within XNA Game Studio 2.0.

        Okay i'll get to the point...

        While XAudio2 was under Beta most, if not all parameter changing, e.g SetFilterParameters, SetChannelVolumes would return an HRESULT letting you know if XAudio2 was able to apply the settings you have asked it to. Now we have the RTM and these HRESULT return codes no longer exist. Yes, I know you cannot set filter parameters on a master voice, but try it!!!

        At this point XAudio2 goes a little crazy and begins to allocate lots of memory, stealing CPU time also.

        Also try SetChannelVolumes on a master voice.

        SAME AGAIN!!!

        The documentation does tell you that you can't set these but because the IXAudio2MasteringVoice interface inherits its functionality from the IXAudio2Voice then these methods are available.

       The documentation tells you also that the SetFilterParameters can be set on a Submix voice, this also causes XAudio2 to get confused. Hmmm!!!


       Can someone explain to me why these return codes were removed and why XAudio2 goes crazy?

       It's not a problem as far as development goes, like I said it's an annoyance more than anything.

    Thanx in Advance

  • 03-20-2008 8:14 PM In reply to

    Re: XAudio2

    Hi, Luminous.  I'm sorry this change gave you trouble.  What happened here was that when XAudio2 development started we were in the Windows mind-set (handle all errors, never crash).  Later on we migrated to Xbox-style error handling (don't check for bad calls at all), but the work happened late in the dev cycle, blindsiding some our loyal Beta users.

    I'll make sure this issue is well documented, but here is the gist: in the retail build we never validate any function calls, and anything can happen if you call them wrong - ranging from (accidentally) correct behavior to an instant crash (which is preferable, as it guarantees that you notice the problem).  In the debug build we do check all calls exhaustively, and if anything is wrong we break into the debugger with a fairly detailed message explaining the error.  Hence I strongly recommend using the debug build during development; it may save you a lot of time. 

    Note that we distinguish between user errors and system errors.  User errors are bugs in the code calling XAudio2, so they're completely avoidable, and if they are fixed before shipping there's no reason for XAudio2 to waste CPU time checking for them.  System errors are unpredictable conditions that can affect any app, and for these we still return error codes that the customer should check for and handle appropriately.

    This explains the vanished return codes; they were all for user error validation.  The remaining few errors are for system errors, currently just: problems with the hardware XMA decoder, problems using a given XAPO, removal of the audio device we were using, and out-of-memory conditions (these are avoidable on Xbox since you have a fixed budget, but they always have to be handled on Windows).

    The main benefit of this change is that it helps customers find and fix XAudio2 usage errors before shipping.  It also reduces XAudio2's memory and CPU footprint a little.

    Having said all that, you may have found an actual XAudio2 bug regarding filters on submix voices, so I'd ask you to try with the debug XAudio2 library and see what the debugger says.  If it doesn't complain and you still see this behavior, we'd definitely want to know.

    Thanks,
    Dugan Porter
    Game Audio Team

    Dugan Porter [MS]
    Game Audio Team
  • 03-22-2008 3:59 AM In reply to

    Re: XAudio2

    Hi Dugan and thanks for your prompt reply.

    Just one more question (for the moment anyway). Regarding filters and submix voices. In your last paragraph you say about using the debug XAudio2 library, and in the debug build of my library I am using the XAUDIO2_DEBUG_ENGINE with the XAudio2Create method so this should mean I am using the debug version of XAudio2. Is this right?

    I have set the the necessary registry values according to the XAudio2 documentation but during debugging, I recieve no information in the output window of Visual C++ 2008 Express Edition, other than the managed assemblies loaded. It is evident however that some form of activity is occuring as the reported CPU usage goes through the roof and audio data is corrupted (simply removing XAUDIO2_DEBUG_ENGINE flag restores expected behaviour).

    Am I missing something?

    Thanks
  • 04-01-2008 1:29 PM In reply to

    Re: XAudio2

    Hmm.  That's right, XAUDIO2_DEBUG_ENGINE should make you load up the debug DLL.  (Take a look at the XAudio2Create function in xaudio2.h.)  There has been another report of debug output not working in Visual C++ 2008 - see my reply from half an hour ago.  But regardless of whether you see debug output, the incorrect call should definitely break you into the debugger at the point of failure.  If you aren't seeing that, I want to understand why.  Please double-check that you're really loading the xaudioD2_0 DLL; if you are, send us simple instructions for a repro and we'll get to the bottom of it.

    Dugan

    Dugan Porter [MS]
    Game Audio Team
  • 04-01-2008 6:08 PM In reply to

    Re: XAudio2

    I believe the other report is one of mine but thanks anyway. Now after some brief exploration I have discovered something. The project I have been working on is a collection of managed classes for XAudio2 in a class library project and accessed through a windows forms application project.

    I have written a small Win32 console App using XAudio2 and indeed all the Debug spew is coming through.
    I have also written a CLR console app using XAudio2 and the debug info is still coming through.

    But no output still through the original project.

    So I assume this debug output is getting lost somehow. Any suggestions?


    Thanks again.

    :)

  • 04-01-2008 6:38 PM In reply to

    Re: XAudio2

    And regarding Submix voices and filter parameters try the following:

    int main(array<System::String ^> ^args)
    {
      HRESULT hr = 0;
      IXAudio2* pIXAudio = NULL;
      IXAudio2MasteringVoice* pIMasterVoice = NULL;
      IXAudio2SubmixVoice* pISubmix = NULL;

      UINT32 Flags = 0;

    #ifdef _DEBUG
      Flags = XAUDIO2_DEBUG_ENGINE;
    #endif

      // Create XAudio2 object
      hr = XAudio2Create(&pIXAudio, Flags);

      if(FAILED(hr))
        return -1;

      // Create XAudio2 Mastering Voice
      hr = pIXAudio->CreateMasteringVoice(&pIMasterVoice);

      if(FAILED(hr))
      {
        // Give up and exit
        pIXAudio->Release();
        return -1;
      }

      // Create XAudio2 Submix Voice
      hr = pIXAudio->CreateSubmixVoice(&pISubmix, 2, 44100);

      if(FAILED(hr))
      {
        // Destroy Mastering voice
        pIMasterVoice->DestroyVoice();

        // Free XAudio2 object
        pIXAudio->Release();
      }

      XAUDIO2_FILTER_PARAMETERS xfp;
      xfp.Frequency = 0.2f;
      xfp.OneOverQ = 0.1f;
      xfp.Type = BandPassFilter;


      pISubmix->SetFilterParameters(&xfp);

      // clean up
      pISubmix->DestroyVoice();

      pIMasterVoice->DestroyVoice();

      pIXAudio->Release();

    return 0;
    }

    As soon as the SetFilterParameters method is called the following debug info is generated:

    XAUDIO2: Thread 320: 3331.162ms: CX2Voice::SetFilterParameters: Acquiring m_ApiLock at 0x01121FCC created by CX2Engine::InitializeLocks...
    XAUDIO2: Thread 320: 3331.354ms: CX2Voice::SetFilterParameters: Acquired m_ApiLock at 0x01121FCC created by CX2Engine::InitializeLocks
    XAUDIO2: Thread 320: 3336.649ms: x2voicebase.cpp:1082: IXAudio2Voice::SetFilterParameters: API call: Entry (this=0x011304F4)
    XAUDIO2: Thread 320: 3336.853ms: x2voicebase.cpp:1088: CX2Voice::SetFilterParameters: ERROR: Filter control is not available on this voice


    Now the documentation with the DirectX March 2008 SDK and indeed http://msdn2.microsoft.com/en-us/library/bb669181(VS.85).aspx says that submix voices support the SetFilterParameters method but http://msdn2.microsoft.com/en-us/library/bb694519(VS.85).aspx does not list SetFilterParameters as a method.

    Thanks

    :)
Page 1 of 1 (6 items) Previous Next