• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2019 The Chromium OS Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 // Generated from files in cras/src/server/rust/src in adhd.
6 
7 #ifndef RATE_ESTIMATOR_H_
8 #define RATE_ESTIMATOR_H_
9 
10 #include <time.h>
11 
12 /**
13  * An estimator holding the required information to determine the actual frame
14  * rate of an audio device.
15  *
16  * # Members
17  *    * `last_level` - Buffer level of the audio device at last check time.
18  *    * `level_diff` - Number of frames written to or read from audio device
19  *                     since the last check time. Rate estimator will use this
20  *                     change plus the difference of buffer level to derive the
21  *                     number of frames audio device has actually processed.
22  *    * `window_start` - The start time of the current window.
23  *    * `window_size` - The size of the window.
24  *    * `window_frames` - The number of frames accumulated in current window.
25  *    * `lsq` - The helper used to estimate sample rate.
26  *    * `smooth_factor` - A scaling factor used to average the previous and new
27  *                        rate estimates to ensure that estimates do not change
28  *                        too quickly.
29  *    * `estimated_rate` - The estimated rate at which samples are consumed.
30  */
31 typedef struct rate_estimator rate_estimator;
32 
33 /**
34  * # Safety
35  *
36  * To use this function safely, `re` must be a pointer returned from
37  * rate_estimator_create, or null.
38  */
39 void rate_estimator_add_frames(rate_estimator *re, int frames);
40 
41 /**
42  * # Safety
43  *
44  * To use this function safely, `re` must be a pointer returned from
45  * rate_estimator_create, or null, and `now` must be a valid pointer to a
46  * timespec.
47  */
48 int32_t rate_estimator_check(rate_estimator *re, int level,
49 			     const struct timespec *now);
50 
51 /**
52  * # Safety
53  *
54  * To use this function safely, `window_size` must be a valid pointer to a
55  * timespec.
56  */
57 rate_estimator *rate_estimator_create(unsigned int rate,
58 				      const struct timespec *window_size,
59 				      double smooth_factor);
60 
61 /**
62  * # Safety
63  *
64  * To use this function safely, `re` must be a pointer returned from
65  * rate_estimator_create, or null.
66  */
67 void rate_estimator_destroy(rate_estimator *re);
68 
69 /**
70  * # Safety
71  *
72  * To use this function safely, `re` must be a pointer returned from
73  * rate_estimator_create, or null.
74  */
75 double rate_estimator_get_rate(const rate_estimator *re);
76 
77 /**
78  * # Safety
79  *
80  * To use this function safely, `re` must be a pointer returned from
81  * rate_estimator_create, or null.
82  */
83 void rate_estimator_reset_rate(rate_estimator *re, unsigned int rate);
84 
85 #endif /* RATE_ESTIMATOR_H_ */
86