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

Audio effects (changing number of channels)

Last post 05-06-2008 7:47 PM by Dugan. 1 replies.
  • 04-19-2008 5:31 PM

    Audio effects (changing number of channels)

    Hi,

    I was trying to implement an audio effect which takes as input a mono sound and outputs a stereo. The way I implemented it was to create a IXAudio2SubmixVoice voice and add an effect to it. Below is a snippet of my audio effect.

    1
    2
    3
    4
    5
      MYX3DAudioFilter *pX3DFilter = new MYX3DAudioFilter((const XAPO_REGISTRATION_PROPERTIES*) rep);
      XAUDIO2_EFFECT_DESCRIPTOR descriptor;
      descriptor.InitialState = true;
      descriptor.OutputChannels  = 2;
      descriptor.pEffect = pX3DFilter;

    Now, if I attach this effect when I create the IXAudio2SubmixVoice voice everything works fine. Below is the working snippet.

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
      XAUDIO2_EFFECT_CHAIN eChain;
      eChain.EffectCount = 1;
      eChain.pEffectDescriptors = &descriptor;

      IXAudio2SubmixVoice* pSFXSubmixVoice;
      AudioManager* aManager = AudioManager::getManager();
      if(FAILED(err = aManager->getEngine()->CreateSubmixVoice(&pSFXSubmixVoice, 1, 44100, 0, 0, 0, &eChain))) {
        char dumpString[100];
        log->logMessage(LOG_ERROR, "Pipline Init Failure: XAUDIO3D_T");
        log->logMessageArgs(LOG_ERROR, "%s", convertStr(dumpString, DXGetErrorString9(err)));
        return err;
      }

    However, if I initialize the IXAudio2SubmixVoice voice without the effect and then add the effect later using SetEffectChain() the code fails and gives the following error message:

    "XAUDIO2: ERROR: Cannot use an effect chain that produces 2-channel audio, as it would change the number of channels produced by this voice (currently 1)"

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
      IXAudio2SubmixVoice* pSFXSubmixVoice;
      AudioManager* aManager = AudioManager::getManager();
      if(FAILED(err = aManager->getEngine()->CreateSubmixVoice(&pSFXSubmixVoice, 1, 44100, 0, 0, 0, &eChain))) {
        char dumpString[100];
        log->logMessage(LOG_ERROR, "Pipline Init Failure: XAUDIO3D_T");
        log->logMessageArgs(LOG_ERROR, "%s", convertStr(dumpString, DXGetErrorString9(err)));
        return err;
      }

    pSFXSubmixVoice->SetEffectChain(&eChain);

    I am not very sure why that happens. Though I have a working code it would still be helpful to know what I am doing wrong there.

    Thanks,
    Anish
  • 05-06-2008 7:47 PM In reply to

    Re: Audio effects (changing number of channels)

    I believe the problem is in the way voices are handled internally by XAudio2.  When a voice is created, its number of output channels is determined by its input channel count and the channel count produced by its effect chain.  Internal connections from this voice to other ones are set up based on this channel count.  So if you try to replace the effect chain later, and your new chain produces a different number of channels, we would have to reconfigure all our connections to other voices, which is actually a hard problem when you think about preserving the send level matrices etc.  Essentially, once a submix voice is created you're "stuck" with whatever number of channels it produces, and the only workaround is to destroy and recreate your submix voice with the new effect chain.  Fortunately this switch can be done atomically in XAudio2, so it may not be a bad solution.

    Dugan Porter [MS]
    Game Audio Team

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