载入中...
搜索中...
未找到
AudioFade.cpp
浏览该文件的文档.
1#include "audio/AudioFade.h"
2
3#include "audio/Source.h"
4
5#include <cmath>
6
7namespace eve::audio {
8
9Result<void> crossfadeSources(Source* from, Source* to, float toVolume, float durationSeconds, float now) {
10 if (!from || !to)
12 "crossfade requires from and to sources", "audio.crossfade"));
13 if (!std::isfinite(toVolume) || toVolume < 0.f || !std::isfinite(durationSeconds) || durationSeconds < 0.f ||
14 !std::isfinite(now))
17 "crossfade requires finite now, non-negative duration and toVolume", "audio.crossfade"));
18
19 to->setVolume(0.f);
20 if (!to->isPlaying()) to->play();
21 auto fadeIn = to->fadeTo(toVolume, durationSeconds, now);
22 if (!fadeIn.ok()) return fadeIn;
23 return from->fadeOutAndStop(durationSeconds, now);
24}
25
26} // namespace eve::audio
std::string to
std::string from
static Diagnostic error(DiagnosticCode code, std::string message, std::string path={})
Construct an error diagnostic with the standard error severity.
Move-only operation result carrying either a value or Status.
Definition Result.h:176
static Result failure(Status status)
Construct a failed result from a structured status.
Definition Result.h:196
A playable audio source (static buffer or streaming decoder). Not thread-safe for playback control ex...
Definition Source.h:30
Result< void > crossfadeSources(Source *from, Source *to, float toVolume, float durationSeconds, float now)
Cross-fade two caller-owned sources over an injected simulation interval.
Definition AudioFade.cpp:9