1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182
|
// ----------------------------------------------------------------------------
//
// Copyright (C) 2012 Fons Adriaensen <fons@linuxaudio.org>
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
//
// ----------------------------------------------------------------------------
#ifndef __LFQUEUE_H
#define __LFQUEUE_H
#include <stdint.h>
#include <string.h>
class Adata
{
public:
int32_t _state;
int32_t _nsamp;
double _timer;
};
class Lfq_adata
{
public:
Lfq_adata (int size);
~Lfq_adata (void);
void reset (void) { _nwr = _nrd = 0; }
int size (void) const { return _size; }
int wr_avail (void) const { return _size - _nwr + _nrd; }
Adata *wr_datap (void) { return _data + (_nwr & _mask); }
void wr_commit (void) { _nwr++; }
int rd_avail (void) const { return _nwr - _nrd; }
Adata *rd_datap (void) { return _data + (_nrd & _mask); }
void rd_commit (void) { _nrd++; }
private:
Adata *_data;
int _size;
int _mask;
int _nwr;
int _nrd;
};
class Jdata
{
public:
int32_t _state;
double _error;
double _ratio;
int _bstat;
};
class Lfq_jdata
{
public:
Lfq_jdata (int size);
~Lfq_jdata (void);
void reset (void) { _nwr = _nrd = 0; }
int size (void) const { return _size; }
int wr_avail (void) const { return _size - _nwr + _nrd; }
Jdata *wr_datap (void) { return _data + (_nwr & _mask); }
void wr_commit (void) { _nwr++; }
int rd_avail (void) const { return _nwr - _nrd; }
Jdata *rd_datap (void) { return _data + (_nrd & _mask); }
void rd_commit (void) { _nrd++; }
private:
Jdata *_data;
int _size;
int _mask;
int _nwr;
int _nrd;
};
class Lfq_int32
{
public:
Lfq_int32 (int size);
~Lfq_int32 (void);
int size (void) const { return _size; }
void reset (void) { _nwr = _nrd = 0; }
int wr_avail (void) const { return _size - _nwr + _nrd; }
int32_t *wr_datap (void) { return _data + (_nwr & _mask); }
void wr_commit (void) { _nwr++; }
int rd_avail (void) const { return _nwr - _nrd; }
int32_t *rd_datap (void) { return _data + (_nrd & _mask); }
void rd_commit (void) { _nrd++; }
void wr_int32 (int32_t v) { _data [_nwr++ & _mask] = v; }
void wr_uint32 (uint32_t v) { _data [_nwr++ & _mask] = v; }
void wr_float (float v) { *(float *)(_data + (_nwr++ & _mask)) = v; }
int32_t rd_int32 (void) { return _data [_nrd++ & _mask]; }
int32_t rd_uint32 (void) { return _data [_nrd++ & _mask]; }
float rd_float (void) { return *(float *)(_data + (_nrd++ & _mask)); }
private:
int32_t *_data;
int _size;
int _mask;
int _nwr;
int _nrd;
};
class Lfq_audio
{
public:
Lfq_audio (int nsamp, int nchan);
~Lfq_audio (void);
int size (void) const { return _size; }
void reset (void)
{
_nwr = _nrd = 0;
memset (_data, 0, _size * _nch * sizeof (float));
}
int nchan (void) const { return _nch; }
int nwr (void) const { return _nwr; };
int nrd (void) const { return _nrd; };
int wr_avail (void) const { return _size - _nwr + _nrd; }
int wr_linav (void) const { return _size - (_nwr & _mask); }
float *wr_datap (void) { return _data + _nch * (_nwr & _mask); }
void wr_commit (int k) { _nwr += k; }
int rd_avail (void) const { return _nwr - _nrd; }
int rd_linav (void) const { return _size - (_nrd & _mask); }
float *rd_datap (void) { return _data + _nch * (_nrd & _mask); }
void rd_commit (int k) { _nrd += k; }
private:
float *_data;
int _size;
int _mask;
int _nch;
int _nwr;
int _nrd;
};
#endif
|