Nsound  0.9.4
Kernel.h
Go to the documentation of this file.
1 //-----------------------------------------------------------------------------
2 //
3 // $Id: Kernel.h 874 2014-09-08 02:21:29Z weegreenblobbie $
4 //
5 // Nsound is a C++ library and Python module for audio synthesis featuring
6 // dynamic digital filters. Nsound lets you easily shape waveforms and write
7 // to disk or plot them. Nsound aims to be as powerful as Csound but easy to
8 // use.
9 //
10 // Copyright (c) 2009 to Present Nick Hilton
11 //
12 // weegreenblobbie_yahoo_com (replace '_' with '@' and '.')
13 //
14 //-----------------------------------------------------------------------------
15 
16 //-----------------------------------------------------------------------------
17 //
18 // This program is free software; you can redistribute it and/or modify
19 // it under the terms of the GNU General Public License as published by
20 // the Free Software Foundation; either version 2 of the License, or
21 // (at your option) any later version.
22 //
23 // This program is distributed in the hope that it will be useful,
24 // but WITHOUT ANY WARRANTY; without even the implied warranty of
25 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26 // GNU Library General Public License for more details.
27 //
28 // You should have received a copy of the GNU General Public License
29 // along with this program; if not, write to the Free Software
30 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
31 //
32 //-----------------------------------------------------------------------------
33 #ifndef _NSOUND_KERNEL_H_
34 #define _NSOUND_KERNEL_H_
35 
36 #include <Nsound/Nsound.h>
37 
38 #include <iostream>
39 #include <set>
40 
41 namespace Nsound
42 {
43 
44 // Forward declarations
45 class Buffer;
46 
47 //-----------------------------------------------------------------------------
50 class Kernel
51 {
52  public:
53 
54  Kernel(uint32 b_length, uint32 a_length,
55  int32 f1 = 0,
56  int32 f2 = 0,
57  int32 f3 = 0,
58  int32 f4 = 0);
59 
60  Kernel(const Kernel & copy);
61 
62  virtual
63  ~Kernel();
64 
65  boolean
66  operator<(const Kernel & rhs) const;
67 
69  float64
71  { if(i < a_length_) return a_[i]; return 0.0; };
72 
74  float64 *
75  getA()
76  { return a_; };
77 
79  const
80  float64 *
81  getA() const
82  { return a_; };
83 
85  float64
87  { if(i < b_length_) return b_[i]; return 0.0; };
88 
90  float64 *
91  getB()
92  { return b_; };
93 
95  const
96  float64 *
97  getB() const
98  { return b_; };
99 
100  uint32
101  getALength() const { return a_length_; };
102 
103  uint32
104  getBLength() const { return b_length_; };
105 
106  float64
107  getSum() const;
108 
109  Kernel &
110  operator=(const Kernel & rhs);
111 
113  friend
114  std::ostream &
115  operator<<(std::ostream & out, const Kernel & rhs);
116 
118  void
119  randomize(const float64 & min = -1.0, const float64 & max = 1.0);
120 
122  void
123  setA(const float64 * a);
124 
126  void
127  setA(const float64 & d, uint32 i)
128  { if(i < a_length_) a_[i] = d; };
129 
131  void
132  setA(const Buffer & a);
133 
135  void
136  setB(const float64 * b);
137 
139  void
140  setB(const float64 & d, uint32 i)
141  { if(i < b_length_) b_[i] = d; };
142 
144  void
145  setB(const Buffer & b);
146 
147  void
148  setLength(uint32 b_length, uint32 a_length);
149 
151  void
152  ga_swap_ab(Kernel & rhs);
153 
155  void
156  ga_interleave(Kernel & rhs);
157 
159  void
160  ga_interleave();
161 
162  protected:
163 
166 
171 
174 
175 };
176 
177 std::ostream &
178 operator<<(std::ostream & out, const Kernel & rhs);
179 
180 typedef std::set<Kernel> KernelCache;
181 
182 };
183 
184 // :mode=c++: jEdit modeline
185 
186 #endif
uint32 b_length_
Definition: Kernel.h:164
unsigned int uint32
Definition: Nsound.h:153
std::ostream & operator<<(std::ostream &out, const Buffer &rhs_buffer)
Definition: Buffer.cc:1338
void ga_interleave()
Genitic Algorithm Helper Function: interleave B coefs with A.
Definition: Kernel.cc:320
std::set< Kernel > KernelCache
Definition: Kernel.h:180
Kernel & operator=(const Kernel &rhs)
Definition: Kernel.cc:97
int32 f1_
Definition: Kernel.h:167
float64 getB(uint32 i)
Returns kernel 'b[i]' coef.
Definition: Kernel.h:86
float64 getSum() const
Definition: Kernel.cc:154
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
void setA(const float64 &d, uint32 i)
Set a_[i] = d.
Definition: Kernel.h:127
float64 * getB()
Returns kernel 'b' array, the length is returned by getBLegnth()
Definition: Kernel.h:91
boolean operator<(const Kernel &rhs) const
Definition: Kernel.cc:119
const float64 * getB() const
Returns kernel 'b' array, the length is returned by getBLegnth()
Definition: Kernel.h:97
friend std::ostream & operator<<(std::ostream &out, const Kernel &rhs)
Prints the coeffents.
double float64
Definition: Nsound.h:146
void ga_swap_ab(Kernel &rhs)
Genitic Algorithm Helper Function: swaps the A & B coefs.
Definition: Kernel.cc:275
void setLength(uint32 b_length, uint32 a_length)
Definition: Kernel.cc:255
uint32 getALength() const
Definition: Kernel.h:101
void randomize(const float64 &min=-1.0, const float64 &max=1.0)
Sets all coefs to random float64 values between min & max.
Definition: Kernel.cc:194
virtual ~Kernel()
Definition: Kernel.cc:88
uint32 getBLength() const
Definition: Kernel.h:104
Kernel(uint32 b_length, uint32 a_length, int32 f1=0, int32 f2=0, int32 f3=0, int32 f4=0)
Definition: Kernel.cc:48
const float64 * getA() const
Returns Kernel 'a' array, the length is returned by getALegnth()
Definition: Kernel.h:81
int32 f2_
Definition: Kernel.h:168
A Buffer for storing audio samples.
Definition: Buffer.h:60
signed int int32
Definition: Nsound.h:142
int32 f3_
Definition: Kernel.h:169
float64 * a_
Definition: Kernel.h:173
float64 * getA()
Returns Kernel 'a' array, the length is returned by getALegnth()
Definition: Kernel.h:75
uint32 a_length_
Definition: Kernel.h:165
float64 getA(uint32 i)
Returns kernel 'a[i]' coef.
Definition: Kernel.h:70
int32 f4_
Definition: Kernel.h:170
void setB(const float64 &d, uint32 i)
Set b_[i] = d.
Definition: Kernel.h:140
float64 * b_
Definition: Kernel.h:172
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