Calling the SteamAudio C API in version 4.8.0 for Direct emulation does not work properly
Hello,
I've encountered another issue on my journey with the C API, this time regarding Direct simulation. I'm trying to apply distance attenuation, occlusion, and transmission effects, but only attenuation and occlusion are working correctly—transmission does not.
I'm using version 4.8.0 of Steam Audio with the C# bindings. The key creation code is as follows:
// Scene
IPL.SceneSettings sS = new IPL.SceneSettings();
sS.Type = IPL.SceneType.Embree;
sS.EmbreeDevice = EmbD;
MessageBox.Show("Scene creation result: " + IPL.SceneCreate(iplContext, sS, out Scene).ToString());
// Add geometry
AddMesh();
// Create simulator
IPL.SimulationSettings simS = new IPL.SimulationSettings();
simS.Flags = IPL.SimulationFlags.Direct;
simS.SceneType = sS.Type;
simS.NumDiffuseSamples = 32;
simS.MaxDuration = DSecond;
simS.MaxNumSources = 8;
simS.NumThreads = 2;
simS.SamplingRate = iplAudioSettings.SamplingRate;
simS.FrameSize = iplAudioSettings.FrameSize;
simS.MaxNumOcclusionSamples = 16;
MessageBox.Show("Simulator creation result: " + IPL.SimulatorCreate(iplContext, simS, out simulator).ToString());
IPL.SimulatorSetScene(simulator, Scene);
IPL.SimulatorCommit(simulator);
// Create source
IPL.SourceSettings sourceS = new IPL.SourceSettings();
sourceS.Flags = IPL.SimulationFlags.Direct;
MessageBox.Show("Source creation result: " + IPL.SourceCreate(simulator, sourceS, out Source).ToString());
IPL.SourceAdd(Source, simulator);
IPL.SimulatorCommit(simulator);
// Set initial input parameters
// Source
SourceInput.Flags = IPL.SimulationFlags.Direct;
SourceInput.DirectFlags = IPL.DirectSimulationFlags.DistanceAttenuation | IPL.DirectSimulationFlags.Occlusion | IPL.DirectSimulationFlags.Transmission;
IPL.DistanceAttenuationModel dM = new();
dM.Type = IPL.DistanceAttenuationModelType.Default;
SourceInput.DistanceAttenuationModel = dM;
SourceInput.OcclusionType = IPL.OcclusionType.Volumetric;
SourceInput.OcclusionRadius = 0.5f;
SourceInput.NumOcclusionSamples = 16;
SourceInput.NumTransmissionRays = 16;
SourceInput.Source.Right = Vector3.UnitX;
SourceInput.Source.Up = Vector3.UnitY;
SourceInput.Source.Ahead = GetRight(Vector3.UnitZ);
// Listener input parameters
var t = LForward;
t.Z = -1;
Listener.Listener.Ahead = t;
Listener.Listener.Right = Vector3.UnitX;
Listener.Listener.Up = Vector3.UnitY;
Listener.Listener.Origin = LPosition;
Listener.NumRays = RayCount;
Listener.NumBounces = 16;
Listener.Duration = DSecond;
Listener.Order = 1;
Listener.IrradianceMinDistance = 1;
Adding geometry and setting materials should be fine—they are created and added correctly because when I use reflection effects, they work well. Moreover, when I change the materials, the reflected sound changes accordingly, so I believe the materials are correctly set and added to Steam Audio. If there is another way to verify this, please let me know.
Next, I set the source input parameters for the Direct effect, set the shared input parameters for Direct, and run the simulation.
When I retrieve the Direct simulation results, I find that only attenuation and occlusion are working correctly: the occlusion value changes from 1 to 0 when the listener moves behind an obstacle. However, the three-band transmission EQ values are always 1. I don't know why this is happening. I have correctly set the transmission values for the materials—they are definitely not 1. I'm not sure where the problem lies or how to troubleshoot it.
Any help would be greatly appreciated. Thank you!
The occlusion effect is working correctly, including changes in the occlusion coefficient based on different angular positions relative to obstacles.
However, the transmission values are always all 1. I don't understand why they haven't been replaced with the corresponding properties of the material being passed through. I clearly used the transmission flag in the simulation, and the material should have been set up correctly because the reflection material is working fine—it reflects sound according to the material I set. Could it be that setting the material can sometimes succeed only partially?
In addition to setting the transmission flag, I have also configured:
SourceInput.NumTransmissionRays = 16;
As shown in my code above, aside from these two settings, are there any other transmission-related settings that I might have missed? Could you provide some assistance? Thank you!
Okay, after further investigation, it was found that the issue was with me manually updating the binding library to 4.8, and it worked normally in 4.7.
Okay, after further investigation, it was found that the issue was with me manually updating the binding library to 4.8, 和 it worked normally in 4.7.
Okay, I've noticed that there's still a tiny probability that transmission won't work again. I don't know why this happens. Whether the transmission works or not, reflection always works properly. I don't think it's a Material issue. I don't know where the problem lies. Occlusion, attenuation, and reflection all work fine, only transmission occasionally fails, in the 4.7 version of the API.
The problem has been resolved, it was caused by an incorrect C # encapsulation. Sorry!