wvdbusserver: implement NameHasOwner request.
[wvstreams.git] / include / wvrateadjust.h
blob92a2983e54b62a99ab77e680e26c7c39690bef64
1 /* -*- Mode: C++ -*-
2 * Worldvisions Weaver Software:
3 * Copyright (C) 1997-2002 Net Integration Technologies, Inc.
4 *
5 * WvRateAdjust is a WvEncoder that makes sure data comes out of it at a
6 * given average rate. It adds duplicate samples or removes extra samples
7 * from the input in order to achieve this.
8 *
9 * The current version doesn't do anything fancy like linear or spline
10 * interpolation, since it's being built mainly for minor rate adjustments
11 * like 8000 Hz to 8020 Hz, and interpolation probably doesn't help too
12 * much there. It's also nicer to not have to worry explicitly about the
13 * number format, which you would have to do if you were doing actual math.
15 * You can also use this as a slightly (not terribly) inefficient rate
16 * *estimator* for the input stream.
18 * NOTE: Time is of the essence of this encoder.
19 */
20 #ifndef __WVRATEADJUST_H
21 #define __WVRATEADJUST_H
23 #include "wvencoder.h"
24 #include "wvtimeutils.h"
26 class WvRateAdjust : public WvEncoder
28 public:
29 WvRateAdjust *match_rate;
31 int sampsize, irate_n, irate_d, orate_n, orate_d;
32 WvTime epoch; // the time when sampling started
34 // the token bucket holds the "remainder" of our fake integer division
35 // operation. With this, we can make sure we always average out to
36 // exactly the right rate.
37 //
38 // Basically:
39 // bucket = ((orate*insamps) - (irate*outsamps)) * irate_d * orate_d
40 //
41 // ...but with some care thrown in to prevent overflows.
42 int bucket;
44 WvRateAdjust(int _sampsize, int _irate_base, int _orate);
45 WvRateAdjust(int _sampsize, int _irate_base, WvRateAdjust *_match_rate);
47 int getirate()
48 { return irate_n / irate_d; }
49 int getorate()
50 { return orate_n / orate_d; }
52 protected:
53 void init(int _sampsize, int _irate_base);
55 virtual bool _encode(WvBuf &inbuf, WvBuf &outbuf, bool flush);
58 #endif // __WVRATEADJUST_H