Rise
The Vieneo Province
Toggle main menu visibility
Loading...
Searching...
No Matches
WiperAudio.h
Go to the documentation of this file.
1
#pragma once
2
#include "bass.h"
3
#include <cmath>
4
5
namespace
WiperAudio
6
{
7
inline
float
PlaybackRate
(
float
duration,
float
cyclesPerSecond)
8
{
9
const
float
rate = duration * cyclesPerSecond;
10
return
std::isfinite(rate) && rate > 0.f ? rate : 0.f;
11
}
12
// Use the animation as the clock. Let normal playback run without repeated
13
// seeks, but correct starts/resumes and >50 ms drift after a stalled frame.
14
inline
bool
Synchronize
(HSTREAM stream,
float
phase,
float
duration,
float
cyclesPerSecond,
bool
force)
15
{
16
if
(!stream || !std::isfinite(phase) || phase < 0.f || phase >= 1.f
17
||
PlaybackRate
(duration, cyclesPerSecond) <= 0.f)
return
false
;
18
const
QWORD position = BASS_ChannelGetPosition(stream, BASS_POS_BYTE);
19
if
(position ==
static_cast<
QWORD
>
(-1))
return
false
;
20
const
double
currentPhase = BASS_ChannelBytes2Seconds(stream, position) / duration;
21
double
error = phase - currentPhase;
22
error -= std::round(error);
// shortest distance across the loop boundary
23
if
(!force && std::fabs(error) / cyclesPerSecond <= .05)
return
true
;
24
return
BASS_ChannelSetPosition(stream,
25
BASS_ChannelSeconds2Bytes(stream, phase * duration), BASS_POS_BYTE) != FALSE;
26
}
27
}
WiperAudio
Definition
WiperAudio.h:6
WiperAudio::PlaybackRate
float PlaybackRate(float duration, float cyclesPerSecond)
Definition
WiperAudio.h:7
WiperAudio::Synchronize
bool Synchronize(HSTREAM stream, float phase, float duration, float cyclesPerSecond, bool force)
Definition
WiperAudio.h:14
WiperAudio.h
Generated on
for Rise by
1.18.0