WvStreams
include
wvrateadjust.h
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.
14
*
15
* You can also use this as a slightly (not terribly) inefficient rate
16
* *estimator* for the input stream.
17
*
18
* NOTE: Time is of the essence of this encoder.
19
*/
20
#ifndef __WVRATEADJUST_H
21
#define __WVRATEADJUST_H
22
23
#include "wvencoder.h"
24
#include "wvtimeutils.h"
25
26
class
WvRateAdjust
:
public
WvEncoder
27
{
28
public
:
29
WvRateAdjust
*match_rate;
30
31
int
sampsize, irate_n, irate_d, orate_n, orate_d;
32
WvTime
epoch;
// the time when sampling started
33
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;
43
44
WvRateAdjust
(
int
_sampsize,
int
_irate_base,
int
_orate);
45
WvRateAdjust
(
int
_sampsize,
int
_irate_base,
WvRateAdjust
*_match_rate);
46
47
int
getirate()
48
{
return
irate_n / irate_d; }
49
int
getorate()
50
{
return
orate_n / orate_d; }
51
52
protected
:
53
void
init(
int
_sampsize,
int
_irate_base);
54
55
virtual
bool
_encode
(
WvBuf
&inbuf,
WvBuf
&outbuf,
bool
flush
);
56
};
57
58
#endif // __WVRATEADJUST_H
WvEncoder
The base encoder class.
Definition:
wvencoder.h:67
WvTime
Based on (and interchangeable with) struct timeval.
Definition:
wvtimeutils.h:17
WvRateAdjust::_encode
virtual bool _encode(WvBuf &inbuf, WvBuf &outbuf, bool flush)
Template method implementation of encode().
Definition:
wvrateadjust.cc:54
WvBufBase< unsigned char >
Specialization of WvBufBase for unsigned char type buffers intended for use with raw memory buffers.
Definition:
wvbuf.h:22
WvRateAdjust
Definition:
wvrateadjust.h:26
WvEncoder::flush
bool flush(WvBuf &inbuf, WvBuf &outbuf, bool finish=false)
Flushes the encoder and optionally finishes it.
Definition:
wvencoder.h:163
Generated by
1.8.17