10#include "wvrateadjust.h"
12WvRateAdjust::WvRateAdjust(
int _sampsize,
int _irate_base,
int _orate)
14 : log(
"RateAdj", WvLog::Debug5)
21 init(_sampsize, _irate_base);
25WvRateAdjust::WvRateAdjust(
int _sampsize,
int _irate_base,
28 : log(
"RateAdj", WvLog::Debug5)
31 match_rate = _match_rate;
34 orate_n = match_rate->irate_n;
35 orate_d = match_rate->irate_d;
37 init(_sampsize, _irate_base);
41void WvRateAdjust::init(
int _sampsize,
int _irate_base)
44 irate_n = _irate_base * 10;
56 if (!inbuf.
used())
return true;
57 assert((inbuf.
used() % sampsize) == 0);
60 unsigned isamps = inbuf.
used() / sampsize;
65 orate_n = match_rate->irate_n;
66 orate_d = match_rate->irate_d;
72 irate_n += isamps * 10;
73 irate_d = msecdiff(wvtime(), epoch) / 100;
78 log(
"irate=%s (%s/%s), orate=%s (%s/%s), bucket=%s\n",
79 getirate(), irate_n, irate_d, getorate(), orate_n, orate_d,
92 irate_n = irate_n * (irate_d - 10)/irate_d;
96 log(
" JUMP! new irate=%s (%s/%s)\n", getirate(), irate_n, irate_d);
100 int plus = orate_n * irate_d, minus = irate_n * orate_d;
103 unsigned omax = isamps + isamps/2;
106 const unsigned char *iptr = inbuf.
get(isamps * sampsize);
107 unsigned char *ostart, *optr;
109 ostart = optr = outbuf.
alloc(omax * sampsize);
112 for (
unsigned s = 0; s < isamps; s++, iptr += sampsize)
117 while (bucket >= minus)
120 if ((
unsigned)(optr - ostart) >= omax * sampsize)
121 ostart = optr = outbuf.
alloc(omax * sampsize);
123 for (
int i = 0; i < sampsize; i++)
130 unsigned un = omax*sampsize - (optr - ostart);
const T * get(size_t count)
Reads exactly the specified number of elements and returns a pointer to a storage location owned by t...
void unalloc(size_t count)
Unallocates exactly the specified number of elements by removing them from the buffer and releasing t...
T * alloc(size_t count)
Allocates exactly the specified number of elements and returns a pointer to an UNINITIALIZED storage ...
size_t used() const
Returns the number of elements in the buffer currently available for reading.
Specialization of WvBufBase for unsigned char type buffers intended for use with raw memory buffers.
virtual bool _encode(WvBuf &inbuf, WvBuf &outbuf, bool flush)
Template method implementation of encode().
Based on (and interchangeable with) struct timeval.