Nsound  0.9.4
Public Member Functions | Protected Attributes | Friends | List of all members
Nsound::Kernel Class Reference

#include <Nsound/Kernel.h>

Public Member Functions

 Kernel (uint32 b_length, uint32 a_length, int32 f1=0, int32 f2=0, int32 f3=0, int32 f4=0)
 
 Kernel (const Kernel &copy)
 
virtual ~Kernel ()
 
boolean operator< (const Kernel &rhs) const
 
float64 getA (uint32 i)
 Returns kernel 'a[i]' coef. More...
 
float64getA ()
 Returns Kernel 'a' array, the length is returned by getALegnth() More...
 
const float64getA () const
 Returns Kernel 'a' array, the length is returned by getALegnth() More...
 
float64 getB (uint32 i)
 Returns kernel 'b[i]' coef. More...
 
float64getB ()
 Returns kernel 'b' array, the length is returned by getBLegnth() More...
 
const float64getB () const
 Returns kernel 'b' array, the length is returned by getBLegnth() More...
 
uint32 getALength () const
 
uint32 getBLength () const
 
float64 getSum () const
 
Kerneloperator= (const Kernel &rhs)
 
void randomize (const float64 &min=-1.0, const float64 &max=1.0)
 Sets all coefs to random float64 values between min & max. More...
 
void setA (const float64 *a)
 Copy getALength() values from the array a into the Kernel. Use setLength() to set the number of values to copy. More...
 
void setA (const float64 &d, uint32 i)
 Set a_[i] = d. More...
 
void setA (const Buffer &a)
 Copy getALength() values from the array a into the Kernel. Use setLength() to set the number of values to copy. More...
 
void setB (const float64 *b)
 Copy getBLength() values from the array a into the Kernel. Use setLength() to set the number of values to copy. More...
 
void setB (const float64 &d, uint32 i)
 Set b_[i] = d. More...
 
void setB (const Buffer &b)
 Copy getALength() values from the array a into the Kernel. Use setLength() to set the number of values to copy. More...
 
void setLength (uint32 b_length, uint32 a_length)
 
void ga_swap_ab (Kernel &rhs)
 Genitic Algorithm Helper Function: swaps the A & B coefs. More...
 
void ga_interleave (Kernel &rhs)
 Genitic Algorithm Helper Function: interleave B coefs with B, A with A. More...
 
void ga_interleave ()
 Genitic Algorithm Helper Function: interleave B coefs with A. More...
 

Protected Attributes

uint32 b_length_
 
uint32 a_length_
 
int32 f1_
 
int32 f2_
 
int32 f3_
 
int32 f4_
 
float64b_
 
float64a_
 

Friends

std::ostream & operator<< (std::ostream &out, const Kernel &rhs)
 Prints the coeffents. More...
 

Detailed Description

WARNING: This is Experimental, you should not use this class as it may not be working or will change in future releases of Nsound.

Definition at line 50 of file Kernel.h.

Constructor & Destructor Documentation

Kernel::Kernel ( uint32  b_length,
uint32  a_length,
int32  f1 = 0,
int32  f2 = 0,
int32  f3 = 0,
int32  f4 = 0 
)

Definition at line 48 of file Kernel.cc.

References a_, and b_.

53  :
54  b_length_(b_length),
55  a_length_(a_length),
56  f1_(f1),
57  f2_(f2),
58  f3_(f3),
59  f4_(f4),
60  b_(NULL),
61  a_(NULL)
62 {
63  b_ = new float64 [b_length];
64  a_ = new float64 [a_length];
65 }
uint32 b_length_
Definition: Kernel.h:164
int32 f1_
Definition: Kernel.h:167
double float64
Definition: Nsound.h:146
int32 f2_
Definition: Kernel.h:168
int32 f3_
Definition: Kernel.h:169
float64 * a_
Definition: Kernel.h:173
uint32 a_length_
Definition: Kernel.h:165
int32 f4_
Definition: Kernel.h:170
float64 * b_
Definition: Kernel.h:172
Kernel::Kernel ( const Kernel copy)

Definition at line 69 of file Kernel.cc.

References a_, a_length_, b_, and b_length_.

70  :
71  b_length_(copy.b_length_),
72  a_length_(copy.a_length_),
73  f1_(copy.f1_),
74  f2_(copy.f2_),
75  f3_(copy.f3_),
76  f4_(copy.f4_),
77  b_(NULL),
78  a_(NULL)
79 {
80  b_ = new float64 [b_length_];
81  a_ = new float64 [a_length_];
82 
83  *this = copy;
84 }
uint32 b_length_
Definition: Kernel.h:164
int32 f1_
Definition: Kernel.h:167
double float64
Definition: Nsound.h:146
int32 f2_
Definition: Kernel.h:168
int32 f3_
Definition: Kernel.h:169
float64 * a_
Definition: Kernel.h:173
uint32 a_length_
Definition: Kernel.h:165
int32 f4_
Definition: Kernel.h:170
float64 * b_
Definition: Kernel.h:172
Kernel::~Kernel ( )
virtual

Definition at line 88 of file Kernel.cc.

References a_, and b_.

89 {
90  delete [] b_;
91  delete [] a_;
92 }
float64 * a_
Definition: Kernel.h:173
float64 * b_
Definition: Kernel.h:172

Member Function Documentation

boolean Kernel::operator< ( const Kernel rhs) const

Definition at line 119 of file Kernel.cc.

References a_length_, b_length_, f1_, f2_, f3_, and f4_.

120 {
121  return (b_length_ < rhs.b_length_) ||
122 
123  (b_length_ == rhs.b_length_ &&
124  a_length_ < rhs.a_length_) ||
125 
126  (b_length_ == rhs.b_length_ &&
127  a_length_ == rhs.a_length_ &&
128  f1_ < rhs.f1_) ||
129 
130  (b_length_ == rhs.b_length_ &&
131  a_length_ == rhs.a_length_ &&
132  f1_ == rhs.f1_ &&
133  f2_ < rhs.f2_) ||
134 
135  (b_length_ == rhs.b_length_ &&
136  a_length_ == rhs.a_length_ &&
137  f1_ == rhs.f1_ &&
138  f2_ == rhs.f2_ &&
139  f3_ < rhs.f3_) ||
140 
141  (b_length_ == rhs.b_length_ &&
142  a_length_ == rhs.a_length_ &&
143  f1_ == rhs.f1_ &&
144  f2_ == rhs.f2_ &&
145  f3_ == rhs.f3_ &&
146  f4_ < rhs.f4_) ||
147 
148  false;
149 
150 }
uint32 b_length_
Definition: Kernel.h:164
int32 f1_
Definition: Kernel.h:167
int32 f2_
Definition: Kernel.h:168
int32 f3_
Definition: Kernel.h:169
uint32 a_length_
Definition: Kernel.h:165
int32 f4_
Definition: Kernel.h:170
float64 Nsound::Kernel::getA ( uint32  i)
inline

Returns kernel 'a[i]' coef.

Definition at line 70 of file Kernel.h.

References a_, and a_length_.

Referenced by Nsound::FilterIIR::designKernel(), Nsound::FilterIIR::filter(), and ga_swap_ab().

71  { if(i < a_length_) return a_[i]; return 0.0; };
float64 * a_
Definition: Kernel.h:173
uint32 a_length_
Definition: Kernel.h:165
float64* Nsound::Kernel::getA ( )
inline

Returns Kernel 'a' array, the length is returned by getALegnth()

Definition at line 75 of file Kernel.h.

References a_.

Referenced by ga_swap_ab().

76  { return a_; };
float64 * a_
Definition: Kernel.h:173
const float64* Nsound::Kernel::getA ( ) const
inline

Returns Kernel 'a' array, the length is returned by getALegnth()

Definition at line 81 of file Kernel.h.

References a_.

82  { return a_; };
float64 * a_
Definition: Kernel.h:173
float64 Nsound::Kernel::getB ( uint32  i)
inline

Returns kernel 'b[i]' coef.

Definition at line 86 of file Kernel.h.

References b_, and b_length_.

Referenced by Nsound::FilterIIR::designKernel(), Nsound::FilterIIR::filter(), and ga_swap_ab().

87  { if(i < b_length_) return b_[i]; return 0.0; };
uint32 b_length_
Definition: Kernel.h:164
float64 * b_
Definition: Kernel.h:172
float64* Nsound::Kernel::getB ( )
inline

Returns kernel 'b' array, the length is returned by getBLegnth()

Definition at line 91 of file Kernel.h.

References b_.

Referenced by ga_swap_ab().

92  { return b_; };
float64 * b_
Definition: Kernel.h:172
const float64* Nsound::Kernel::getB ( ) const
inline

Returns kernel 'b' array, the length is returned by getBLegnth()

Definition at line 97 of file Kernel.h.

References b_.

98  { return b_; };
float64 * b_
Definition: Kernel.h:172
uint32 Nsound::Kernel::getALength ( ) const
inline

Definition at line 101 of file Kernel.h.

References a_length_.

Referenced by Nsound::operator<<().

101 { return a_length_; };
uint32 a_length_
Definition: Kernel.h:165
uint32 Nsound::Kernel::getBLength ( ) const
inline

Definition at line 104 of file Kernel.h.

References b_length_.

Referenced by Nsound::operator<<().

104 { return b_length_; };
uint32 b_length_
Definition: Kernel.h:164
float64 Kernel::getSum ( ) const

Definition at line 154 of file Kernel.cc.

References a_, a_length_, b_, and b_length_.

Referenced by Nsound::FilterIIR::designKernel().

155 {
156  float64 sum = 0.0;
157 
158  for(uint32 i = 0; i < b_length_; ++i)
159  {
160  sum += std::fabs(b_[i]);
161  }
162 
163  for(uint32 i = 0; i < a_length_; ++i)
164  {
165  sum += std::fabs(a_[i]);
166  }
167 
168  return sum;
169 }
uint32 b_length_
Definition: Kernel.h:164
unsigned int uint32
Definition: Nsound.h:153
double float64
Definition: Nsound.h:146
float64 * a_
Definition: Kernel.h:173
uint32 a_length_
Definition: Kernel.h:165
float64 * b_
Definition: Kernel.h:172
Kernel & Kernel::operator= ( const Kernel rhs)

Definition at line 97 of file Kernel.cc.

References a_, a_length_, b_, b_length_, f1_, f2_, f3_, f4_, and setLength().

98 {
99  if(this == & rhs)
100  {
101  return *this;
102  }
103 
104  setLength(rhs.b_length_, rhs.a_length_);
105 
106  memcpy(b_, rhs.b_, sizeof(float64) * b_length_);
107  memcpy(a_, rhs.a_, sizeof(float64) * a_length_);
108 
109  f1_ = rhs.f1_;
110  f2_ = rhs.f2_;
111  f3_ = rhs.f3_;
112  f4_ = rhs.f4_;
113 
114  return *this;
115 }
uint32 b_length_
Definition: Kernel.h:164
int32 f1_
Definition: Kernel.h:167
double float64
Definition: Nsound.h:146
void setLength(uint32 b_length, uint32 a_length)
Definition: Kernel.cc:255
int32 f2_
Definition: Kernel.h:168
int32 f3_
Definition: Kernel.h:169
float64 * a_
Definition: Kernel.h:173
uint32 a_length_
Definition: Kernel.h:165
int32 f4_
Definition: Kernel.h:170
float64 * b_
Definition: Kernel.h:172
void Kernel::randomize ( const float64 min = -1.0,
const float64 max = 1.0 
)

Sets all coefs to random float64 values between min & max.

Definition at line 194 of file Kernel.cc.

References a_, a_length_, b_, b_length_, and Nsound::RngTausworthe::get().

Referenced by Nsound::FilterIIR::designKernel().

195 {
196  RngTausworthe rng;
197 
198  for(uint32 i = 0; i < b_length_; ++i)
199  {
200  b_[i] = rng.get(min, max);
201  }
202 
203  for(uint32 i = 0; i < a_length_; ++i)
204  {
205  a_[i] = rng.get(min, max);
206  }
207 }
uint32 b_length_
Definition: Kernel.h:164
unsigned int uint32
Definition: Nsound.h:153
float64 * a_
Definition: Kernel.h:173
uint32 get()
Get a random number.
uint32 a_length_
Definition: Kernel.h:165
float64 * b_
Definition: Kernel.h:172
void Kernel::setA ( const float64 a)

Copy getALength() values from the array a into the Kernel. Use setLength() to set the number of values to copy.

Definition at line 211 of file Kernel.cc.

References a_, and a_length_.

Referenced by Nsound::FilterIIR::designKernel(), ga_swap_ab(), and Nsound::FilterParametricEqualizer::makeKernel().

212 {
213  memcpy(a_, a, sizeof(float64) * a_length_);
214 }
double float64
Definition: Nsound.h:146
float64 * a_
Definition: Kernel.h:173
uint32 a_length_
Definition: Kernel.h:165
void Nsound::Kernel::setA ( const float64 d,
uint32  i 
)
inline

Set a_[i] = d.

Definition at line 127 of file Kernel.h.

References a_, and a_length_.

128  { if(i < a_length_) a_[i] = d; };
float64 * a_
Definition: Kernel.h:173
uint32 a_length_
Definition: Kernel.h:165
void Kernel::setA ( const Buffer a)

Copy getALength() values from the array a into the Kernel. Use setLength() to set the number of values to copy.

Definition at line 218 of file Kernel.cc.

References a_, a_length_, and Nsound::Buffer::getLength().

219 {
220  uint32 a_len = a.getLength();
221 
222  for(uint32 i = 0; i < a_length_; ++i)
223  {
224  if(i < a_len)
225  {
226  a_[i] = a[i];
227  }
228  }
229 }
unsigned int uint32
Definition: Nsound.h:153
uint32 getLength() const
Returns the number of samples in the Buffer.
Definition: Buffer.h:587
float64 * a_
Definition: Kernel.h:173
uint32 a_length_
Definition: Kernel.h:165
void Kernel::setB ( const float64 b)

Copy getBLength() values from the array a into the Kernel. Use setLength() to set the number of values to copy.

Definition at line 233 of file Kernel.cc.

References b_, and b_length_.

Referenced by Nsound::FilterIIR::designKernel(), ga_swap_ab(), and Nsound::FilterParametricEqualizer::makeKernel().

234 {
235  memcpy(b_, b, sizeof(float64) * b_length_);
236 }
uint32 b_length_
Definition: Kernel.h:164
double float64
Definition: Nsound.h:146
float64 * b_
Definition: Kernel.h:172
void Nsound::Kernel::setB ( const float64 d,
uint32  i 
)
inline

Set b_[i] = d.

Definition at line 140 of file Kernel.h.

References b_, and b_length_.

141  { if(i < b_length_) b_[i] = d; };
uint32 b_length_
Definition: Kernel.h:164
float64 * b_
Definition: Kernel.h:172
void Kernel::setB ( const Buffer b)

Copy getALength() values from the array a into the Kernel. Use setLength() to set the number of values to copy.

Definition at line 240 of file Kernel.cc.

References b_, b_length_, and Nsound::Buffer::getLength().

241 {
242  uint32 b_len = b.getLength();
243 
244  for(uint32 i = 0; i < b_length_; ++i)
245  {
246  if(i < b_len)
247  {
248  b_[i] = b[i];
249  }
250  }
251 }
uint32 b_length_
Definition: Kernel.h:164
unsigned int uint32
Definition: Nsound.h:153
uint32 getLength() const
Returns the number of samples in the Buffer.
Definition: Buffer.h:587
float64 * b_
Definition: Kernel.h:172
void Kernel::setLength ( uint32  b_length,
uint32  a_length 
)

Definition at line 255 of file Kernel.cc.

References a_, a_length_, b_, and b_length_.

Referenced by operator=().

256 {
257  if(b_length_ != b_length)
258  {
259  b_length_ = b_length;
260  delete [] b_;
261  b_ = new float64 [b_length_];
262  }
263 
264  if(a_length_ != a_length)
265  {
266  a_length_ = a_length;
267  delete [] a_;
268  a_ = new float64 [a_length_];
269  }
270 
271 }
uint32 b_length_
Definition: Kernel.h:164
double float64
Definition: Nsound.h:146
float64 * a_
Definition: Kernel.h:173
uint32 a_length_
Definition: Kernel.h:165
float64 * b_
Definition: Kernel.h:172
void Kernel::ga_swap_ab ( Kernel rhs)

Genitic Algorithm Helper Function: swaps the A & B coefs.

Definition at line 275 of file Kernel.cc.

References getA(), getB(), setA(), and setB().

Referenced by Nsound::FilterIIR::designKernel().

276 {
277  Kernel temp(rhs);
278 
279  rhs.setA(getB());
280  rhs.setB(getA());
281 
282  setA(temp.getB());
283  setB(temp.getA());
284 }
void setB(const float64 *b)
Copy getBLength() values from the array a into the Kernel. Use setLength() to set the number of value...
Definition: Kernel.cc:233
float64 * getB()
Returns kernel 'b' array, the length is returned by getBLegnth()
Definition: Kernel.h:91
float64 * getA()
Returns Kernel 'a' array, the length is returned by getALegnth()
Definition: Kernel.h:75
void setA(const float64 *a)
Copy getALength() values from the array a into the Kernel. Use setLength() to set the number of value...
Definition: Kernel.cc:211
void Kernel::ga_interleave ( Kernel rhs)

Genitic Algorithm Helper Function: interleave B coefs with B, A with A.

Definition at line 296 of file Kernel.cc.

References a_, a_length_, b_, b_length_, and swap_().

Referenced by Nsound::FilterIIR::designKernel().

297 {
298  Kernel temp(rhs);
299 
300  for(uint32 i = 0; i < b_length_; ++i)
301  {
302  if(i % 2)
303  {
304  swap_(b_[i], rhs.b_[i]);
305  }
306  }
307 
308  for(uint32 i = 0; i < a_length_; ++i)
309  {
310  if(i % 2)
311  {
312  swap_(a_[i], rhs.a_[i]);
313  }
314  }
315 
316 }
uint32 b_length_
Definition: Kernel.h:164
unsigned int uint32
Definition: Nsound.h:153
void swap_(float64 &a, float64 &b)
Definition: Kernel.cc:287
float64 * a_
Definition: Kernel.h:173
uint32 a_length_
Definition: Kernel.h:165
float64 * b_
Definition: Kernel.h:172
void Kernel::ga_interleave ( )

Genitic Algorithm Helper Function: interleave B coefs with A.

Definition at line 320 of file Kernel.cc.

References a_, a_length_, b_, b_length_, and swap_().

321 {
322  for(uint32 i = 0; i < b_length_; ++i)
323  {
324  if(i % 2 && i < a_length_)
325  {
326  swap_(b_[i], a_[i]);
327  }
328  }
329 
330 }
uint32 b_length_
Definition: Kernel.h:164
unsigned int uint32
Definition: Nsound.h:153
void swap_(float64 &a, float64 &b)
Definition: Kernel.cc:287
float64 * a_
Definition: Kernel.h:173
uint32 a_length_
Definition: Kernel.h:165
float64 * b_
Definition: Kernel.h:172

Friends And Related Function Documentation

std::ostream& operator<< ( std::ostream &  out,
const Kernel rhs 
)
friend

Prints the coeffents.

Member Data Documentation

uint32 Nsound::Kernel::b_length_
protected
uint32 Nsound::Kernel::a_length_
protected
int32 Nsound::Kernel::f1_
protected

Definition at line 167 of file Kernel.h.

Referenced by operator<(), and operator=().

int32 Nsound::Kernel::f2_
protected

Definition at line 168 of file Kernel.h.

Referenced by operator<(), and operator=().

int32 Nsound::Kernel::f3_
protected

Definition at line 169 of file Kernel.h.

Referenced by operator<(), and operator=().

int32 Nsound::Kernel::f4_
protected

Definition at line 170 of file Kernel.h.

Referenced by operator<(), and operator=().

float64* Nsound::Kernel::b_
protected
float64* Nsound::Kernel::a_
protected

The documentation for this class was generated from the following files: