Introduction
The c++ (cpp) time_seconds example is extracted from the most popular open source projects, you can refer to the following example for usage.
Programming language: C++ (Cpp)
Class/type: time_seconds
Example#1File:
ClipMetric.cppProject:
flair2005/OpenAvataring
void CyclicStreamClipinfo::InitializeStreamView(ShrinkedArmature& parts, time_seconds minT, time_seconds maxT, double sampleRateHz, size_t interval_frames)
{
m_pParts = &parts;
m_pFeature = make_shared<PartsFeatureType>();
m_sampleRate = sampleRateHz;
// find closest 2^k window size, ceil work more robust, but usually it result in 512 frames, which is too long
m_windowSize = 1 << static_cast<int>(floor(log2(maxT.count() * sampleRateHz * 4)));
m_minFr = m_windowSize / (maxT.count() * sampleRateHz);
m_maxFr = m_windowSize / (minT.count() * sampleRateHz);
m_FrWidth = m_maxFr - m_minFr + 1;
m_analyzeInterval = interval_frames;
// if automatic, we set 1/16 of period as analyze interval
if (m_analyzeInterval == 0)
m_analyzeInterval = std::max(m_windowSize / 16, 1);
m_frameWidth = 0;
for (int i = 0; i < parts.size(); i++)
m_frameWidth += m_pFeature->GetDimension(*parts[i]);
// make sure each row/column in buffer is aligned as __mm128 for SIMD
const int alignBoundry = alignof(__m128) / sizeof(float);
m_bufferWidth = ((m_frameWidth-1) / alignBoundry + 1) * alignBoundry;
assert(m_bufferWidth >= m_frameWidth);
// this 4 is just some majical constant that large enough to avaiod frequent data moving
m_bufferCapacity = m_windowSize * 4;
m_buffer.setZero(m_bufferWidth, m_bufferCapacity);
m_Spectrum.setZero(m_bufferWidth, m_windowSize);
m_SmoothedBuffer.setZero(m_windowSize, m_frameWidth);
m_cropMargin = m_sampleRate * 0.5; // 0.1s of frames as margin
m_cyclicDtcThr = g_RevampActiveSupportThreshold;
int n = m_windowSize;
#ifdef FFTW
fftwf_plan plan = fftwf_plan_many_dft_r2c(1, &n, m_frameWidth,
m_buffer.data(), nullptr, m_bufferWidth, 1,
(fftwf_complex*)m_Spectrum.data(), nullptr, m_bufferWidth, 1,
0);
m_fftplan = plan;
#endif
}
Example#2File:
FirstPersonControl.cppProject:
ArcEarth/TangibleHolographicSketch
void KeyboardMouseFirstPersonControl::Update(time_seconds const& time_delta)
{
using namespace DirectX;
XMVECTOR vel = XMVectorZero();
if (m_keyboard->IsKeyDown(m_directionalKeys[0])) // 'W'
vel += XMVectorSet( .0f,.0f,-1.0f,.0f);
if (m_keyboard->IsKeyDown(m_directionalKeys[2])) // 'S'
vel += XMVectorSet(.0f, .0f, 1.0f, .0f);
if (m_keyboard->IsKeyDown(m_directionalKeys[1])) // 'A'
vel += XMVectorSet(-1.0f, .0f, .0f, .0f);
if (m_keyboard->IsKeyDown(m_directionalKeys[3])) // 'D'
vel += XMVectorSet(1.0f, .0f, .0f, .0f);
vel = XMVector3Normalize(vel);
CameraVeclocity = vel;
if (m_pTarget && CameraVeclocity.LengthSquared() > 0.01f)
{
XMVECTOR disp = (Speed * (float)time_delta.count()) * vel;
disp = XMVector3Rotate(disp, m_pTarget->GetOrientation());
m_pTarget->Move(disp);
}
}