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

Function PlaySoundTrack

TombEngine/Sound/sound.cpp:496–606  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

494}
495
496void PlaySoundTrack(const std::string& track, SoundTrackType type, std::optional<QWORD> pos, int forceFadeInTime)
497{
498 if (!g_Configuration.EnableSound)
499 return;
500
501 if (track.empty())
502 return;
503
504 bool crossfade = false;
505 DWORD crossfadeTime = 0;
506 DWORD flags = BASS_STREAM_AUTOFREE | BASS_SAMPLE_FLOAT | BASS_ASYNCFILE;
507
508 bool channelActive = BASS_ChannelIsActive(SoundtrackSlot[(int)type].Channel);
509 if (channelActive && SoundtrackSlot[(int)type].Track.compare(track) == 0)
510 {
511 // Same track is incoming with different playhead; set it to new position.
512 auto stream = SoundtrackSlot[(int)type].Channel;
513 if (pos.has_value() && BASS_ChannelGetLength(stream, BASS_POS_BYTE) > pos.value())
514 BASS_ChannelSetPosition(stream, pos.value(), BASS_POS_BYTE);
515
516 return;
517 }
518
519 switch (type)
520 {
521 case SoundTrackType::OneShot:
522 case SoundTrackType::Voice:
523 crossfadeTime = SOUND_XFADETIME_ONESHOT;
524 break;
525
526 case SoundTrackType::BGM:
527 crossfade = true;
528 crossfadeTime = channelActive ? SOUND_XFADETIME_BGM : SOUND_XFADETIME_BGM_START;
529 flags |= BASS_SAMPLE_LOOP;
530 break;
531 }
532
533 auto fullTrackName = std::filesystem::path(FullAudioDirectory + track);
534 if (!fullTrackName.has_extension() || !std::filesystem::is_regular_file(fullTrackName))
535 {
536 for (auto& extension : TRACKS_EXTENSIONS)
537 {
538 fullTrackName.replace_extension(extension);
539 if (std::filesystem::is_regular_file(fullTrackName))
540 break;
541 }
542 }
543
544 if (!std::filesystem::is_regular_file(fullTrackName))
545 {
546 TENLog("No soundtrack files with name '" + fullTrackName.stem().string() + "' were found", LogLevel::Warning);
547 return;
548 }
549
550 if (channelActive)
551 BASS_ChannelSlideAttribute(SoundtrackSlot[(int)type].Channel, BASS_ATTRIB_VOL, -1.0f, crossfadeTime);
552
553 auto stream = BASS_StreamCreateFile(false, fullTrackName.c_str(), 0, 0, flags);

Callers 6

PlaySecretTrackFunction · 0.85
ParseEffectsFunction · 0.85
InitializeScriptingFunction · 0.85
TestTriggersFunction · 0.85
PlayAudioTrackFunction · 0.85
SetAmbientTrackFunction · 0.85

Calls 15

TENLogFunction · 0.85
BASS_StreamCreateFileFunction · 0.85
Sound_CheckBASSErrorFunction · 0.85
GetRandomControlFunction · 0.85
LoadSubtitlesFunction · 0.85
to_stringFunction · 0.85
compareMethod · 0.80
emptyMethod · 0.45
has_valueMethod · 0.45
valueMethod · 0.45
c_strMethod · 0.45
filenameMethod · 0.45

Tested by 1

TestTriggersFunction · 0.68