Roc Toolkit internal modules
Roc Toolkit: real-time audio streaming
ticker.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2017 Roc Streaming authors
3  *
4  * This Source Code Form is subject to the terms of the Mozilla Public
5  * License, v. 2.0. If a copy of the MPL was not distributed with this
6  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
7  */
8 
9 //! @file roc_core/ticker.h
10 //! @brief Ticker.
11 
12 #ifndef ROC_CORE_TICKER_H_
13 #define ROC_CORE_TICKER_H_
14 
15 #include "roc_core/noncopyable.h"
16 #include "roc_core/panic.h"
17 #include "roc_core/time.h"
18 
19 namespace roc {
20 namespace core {
21 
22 //! Ticker.
23 class Ticker : public NonCopyable<> {
24 public:
25  //! Number of ticks.
26  typedef uint64_t ticks_t;
27 
28  //! Initialize.
29  //! @remarks
30  //! @p freq defines the number of ticks per second.
31  explicit Ticker(ticks_t freq);
32 
33  //! Start ticker.
34  void start();
35 
36  //! Returns number of ticks elapsed since start.
37  //! If ticker is not started yet, it is started automatically.
39 
40  //! Wait until the given number of ticks elapses since start.
41  //! If ticker is not started yet, it is started automatically.
42  void wait(ticks_t ticks);
43 
44 private:
45  const double ratio_;
46  nanoseconds_t start_;
47  bool started_;
48 };
49 
50 } // namespace core
51 } // namespace roc
52 
53 #endif // ROC_CORE_TICKER_H_
Base class for non-copyable objects.
Definition: noncopyable.h:23
Ticker.
Definition: ticker.h:23
void wait(ticks_t ticks)
Wait until the given number of ticks elapses since start. If ticker is not started yet,...
ticks_t elapsed()
Returns number of ticks elapsed since start. If ticker is not started yet, it is started automaticall...
void start()
Start ticker.
uint64_t ticks_t
Number of ticks.
Definition: ticker.h:26
Ticker(ticks_t freq)
Initialize.
int64_t nanoseconds_t
Nanoseconds.
Definition: time.h:58
Root namespace.
Non-copyable object.
Panic.
Time definitions.