MCPcopy Create free account
hub / github.com/TombEngine/TombEngine / Sound_UpdateScene

Function Sound_UpdateScene

TombEngine/Sound/sound.cpp:918–994  ·  view source on GitHub ↗

Update whole sound scene in a level. Must be called every frame to update camera position and 3D parameters.

Source from the content-addressed store, hash-verified

916// Update whole sound scene in a level.
917// Must be called every frame to update camera position and 3D parameters.
918void Sound_UpdateScene()
919{
920 if (!g_Configuration.EnableSound)
921 return;
922
923 // Apply environmental effects
924
925 static int currentReverb = NO_VALUE;
926 auto roomReverb = g_Configuration.EnableReverb ? (int)g_Level.Rooms[Camera.pos.RoomNumber].reverbType : (int)ReverbType::Small;
927
928 if (currentReverb == NO_VALUE || roomReverb != currentReverb)
929 {
930 currentReverb = roomReverb;
931 if (currentReverb < (int)ReverbType::Count)
932 BASS_FXSetParameters(BASS_FXHandler[(int)SoundFilter::Reverb], &BASS_ReverbTypes[(int)currentReverb]);
933 }
934
935 for (int i = 0; i < SOUND_MAX_CHANNELS; i++)
936 {
937 if ((SoundSlot[i].Channel != NULL) && (BASS_ChannelIsActive(SoundSlot[i].Channel) == BASS_ACTIVE_PLAYING))
938 {
939 SampleInfo* sampleInfo = &g_Level.SoundDetails[g_Level.SoundMap[SoundSlot[i].EffectID]];
940
941 // Stop and clean up sounds which were in ending state in previous frame.
942 // In case sound is looping, make it ending unless they are re-fired in next frame.
943
944 if (SoundSlot[i].State == SoundState::Ending)
945 {
946 SoundSlot[i].State = SoundState::Ended;
947 Sound_FreeSlot(i, SOUND_XFADETIME_CUTSOUND);
948 continue;
949 }
950 else if ((SoundPlayMode)(sampleInfo->Flags & 3) == SoundPlayMode::Looped)
951 SoundSlot[i].State = SoundState::Ending;
952
953 // Calculate attenuation and clean up sounds which are out of listener range (only for 3D sounds).
954
955 if (SoundSlot[i].Origin != SOUND_OMNIPRESENT_ORIGIN)
956 {
957 float radius = (float)(sampleInfo->Radius) * 1024.0f;
958 float distance = Sound_DistanceToListener(SoundSlot[i].Origin);
959
960 if (distance > radius)
961 {
962 Sound_FreeSlot(i);
963 continue;
964 }
965 else
966 BASS_ChannelSetAttribute(SoundSlot[i].Channel, BASS_ATTRIB_VOL, Sound_Attenuate(SoundSlot[i].Gain, distance, radius));
967 }
968 }
969 }
970
971 // Apply current listener position.
972
973 auto velocity = (oldMikePos - Camera.mikePos.ToVector3()) * (float)FPS;
974 oldMikePos = Camera.mikePos.ToVector3();
975

Callers 2

GamePhaseFunction · 0.85
FreezePhaseFunction · 0.85

Calls 7

Sound_FreeSlotFunction · 0.85
Sound_DistanceToListenerFunction · 0.85
Sound_AttenuateFunction · 0.85
BASS_3DVECTORClass · 0.85
Vector3Function · 0.50
ToVector3Method · 0.45
NormalizeMethod · 0.45

Tested by

no test coverage detected