Skip to content

Commit

Permalink
Improve transmission
Browse files Browse the repository at this point in the history
  • Loading branch information
LAGonauta committed Dec 16, 2023
1 parent c255862 commit 13bc643
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
7 changes: 4 additions & 3 deletions include/Loaders/SteamAudioMapMeshLoader.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,10 @@ namespace MetaAudio

// Transmission details:
// SteamAudio returns the transmission property of the material that was hit, not how much was transmitted
// We should calculate ourselves how much is actually transmitted. The unit used in MetaAudio is actually
// the attenuation `dB/m`, not how much is transmitted per meter.
std::array<IPLMaterial, 1> materials{ {0.10f, 0.20f, 0.30f, 0.05f, 0.100f, 0.050f, 0.030f} };
// We should calculate ourselves how much is actually transmitted.
// The unit used in MetaAudio was the attenuation `dB/m`, not how much is transmitted per meter.
// However, SteamAudio >4 now clamps to 1.0f so this was changed back to transmitted per meter.
std::array<IPLMaterial, 1> materials{ {0.10f, 0.20f, 0.30f, 0.05f, 0.800f, 0.200f, 0.100f} };
public:
SteamAudioMapMeshLoader(SteamAudio::Context sa_context, IPLSimulationSettings simulSettings);

Expand Down
12 changes: 8 additions & 4 deletions src/Effects/SteamAudioOcclusionCalculator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,8 @@ namespace MetaAudio
simulator.SourceRemove(source);
simulator.Commit();

if (result.direct.occlusion < 0.5f) //more than half occluded, add transmission component based on obstruction length
// More than half occluded, add transmission component based on obstruction length
if (result.direct.occlusion < 0.5f)
{
pmtrace_s tr;

Expand All @@ -108,9 +109,12 @@ namespace MetaAudio
if ((tr.fraction < 1.0f || tr.allsolid || tr.startsolid) && tr.fraction < 0.99f && !tr.startsolid)
{
auto distance = obstruction_first_point.getDistance(tr.endpos) * AL_UnitToMeters;
result.direct.transmission[0] = alure::dBToLinear(-distance * result.direct.transmission[0]);
result.direct.transmission[1] = alure::dBToLinear(-distance * result.direct.transmission[1]);
result.direct.transmission[2] = alure::dBToLinear(-distance * result.direct.transmission[2]);
if (distance > 0)
{
result.direct.transmission[0] = std::clamp(result.direct.transmission[0] / distance, 0.0f, 1.0f);
result.direct.transmission[1] = std::clamp(result.direct.transmission[1] / distance, 0.0f, 1.0f);
result.direct.transmission[2] = std::clamp(result.direct.transmission[2] / distance, 0.0f, 1.0f);
}
}
}
}
Expand Down

0 comments on commit 13bc643

Please sign in to comment.