Monday, August 8, 2022
HomeGame DevelopmentXAudio2 mono supply performed as a 3D sound is heard solely in...

XAudio2 mono supply performed as a 3D sound is heard solely in proper speaker, no matter distance and place


I’m having drawback organising a 3D house sound impact in XAudio2. The sound impact that I’m utilizing is mono however the result’s enjoying always, irrelevant from the gap and positioning of the listener and emitter, at all times on proper channel. Right here is the code of the play sound impact operate:

void SoundSystem::Channel::PlaySoundEffect(Sound& s, float pitch, float quantity)
{
    assert(pSource && !pSound);

    s.AddChannel(*this);

    XAUDIO2_VOICE_DETAILS particulars;
    SoundSystem::Get().pMaster->GetVoiceDetails(&particulars);

    X3DAUDIO_DSP_SETTINGS DSPSettings = { 0 };
    FLOAT32* matrix = new FLOAT32[details.InputChannels];
    DSPSettings.SrcChannelCount = s.mFormat.nChannels;
    DSPSettings.DstChannelCount = particulars.InputChannels;
    DSPSettings.pMatrixCoefficients = matrix;

    X3DAudioCalculate(SoundSystem::Get().X3DInstance, &SoundSystem::Get().Listener, &s.Emitter, 
        X3DAUDIO_CALCULATE_MATRIX | X3DAUDIO_CALCULATE_DOPPLER
        | X3DAUDIO_CALCULATE_LPF_DIRECT | X3DAUDIO_CALCULATE_LPF_REVERB
        | X3DAUDIO_CALCULATE_REVERB,
        &DSPSettings);

    pSound = &s;
    xaBuffer.pAudioData = s.pData.get();
    xaBuffer.AudioBytes = s.nBytes;
    pSource->SubmitSourceBuffer(&xaBuffer, nullptr);

    // Apply X3DAudio generated DSP settings to XAudio2
    pSource->SetFrequencyRatio(DSPSettings.DopplerFactor);
    pSource->SetOutputMatrix(SoundSystem::Get().pMaster, s.mFormat.nChannels, particulars.InputChannels, DSPSettings.pMatrixCoefficients);
    pSource->SetOutputMatrix(SoundSystem::Get().pMaster, 1, 1, &DSPSettings.ReverbLevel);
    XAUDIO2_FILTER_PARAMETERS FilterParametersDirect = { LowPassFilter, 2.0f * sinf(X3DAUDIO_PI / 6.0f * DSPSettings.LPFDirectCoefficient), 1.0f }; // see XAudio2CutoffFrequencyToRadians() in XAudio2.h for extra info on the method used right here
    pSource->SetOutputFilterParameters(SoundSystem::Get().pMaster, &FilterParametersDirect);
    XAUDIO2_FILTER_PARAMETERS FilterParametersReverb = { LowPassFilter, 2.0f * sinf(X3DAUDIO_PI / 6.0f * DSPSettings.LPFReverbCoefficient), 1.0f }; // see XAudio2CutoffFrequencyToRadians() in XAudio2.h for extra info on the method used right here
    pSource->SetOutputFilterParameters(SoundSystem::Get().pMaster, &FilterParametersReverb);

    pSource->Begin();
}

Right here is the Listener:

void SetListener(const glm::vec3& entrance, const glm::vec3& up, const glm::vec3& place, const glm::vec3& velocity) {
    Listener.OrientFront = { entrance.x, entrance.y, -front.z };
    Listener.OrientTop = { up.x, up.y, -up.z };
    Listener.Place = { place.x, place.y, -position.z };
    Listener.Velocity = { velocity.x, velocity.y, -velocity.z };
}

And right here is the emitter:

void SetEmitter(const glm::vec3& entrance, const glm::vec3& up, const glm::vec3& place, const glm::vec3& velocity) {
    Emitter.OrientFront = { entrance.x, entrance.y, -front.z };
    Emitter.OrientTop = { up.x, up.y, -up.z };
    Emitter.Place = { place.x, place.y, -position.z };
    Emitter.Velocity = { velocity.x, velocity.y, -velocity.z };

    Emitter.pCone->InnerAngle = 0.0f;
    // Setting the inside cone angles to X3DAUDIO_2PI and
    // outer cone apart from 0 causes
    // the emitter to behave like some extent emitter utilizing the
    // INNER cone settings solely.
    Emitter.pCone->OuterAngle = 0.0f;
    // Setting the outer cone angles to zero causes
    // the emitter to behave like some extent emitter utilizing the
    // OUTER cone settings solely.
    Emitter.pCone->InnerVolume = 0.0f;
    Emitter.pCone->OuterVolume = 1.0f;
    Emitter.pCone->InnerLPF = 0.0f;
    Emitter.pCone->OuterLPF = 1.0f;
    Emitter.pCone->InnerReverb = 0.0f;
    Emitter.pCone->OuterReverb = 1.0f;

    Emitter.CurveDistanceScaler = 1.f;
}

Word that I’m utilizing OpenGL because the graphics API and have a proper handed coordinate system so I negate the z element. Something that I’m doing unsuitable and have the sound solely on one speaker and in full quantity? Thanks upfront

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments