Nsound  0.9.4
Mesh2D.h
Go to the documentation of this file.
1 //-----------------------------------------------------------------------------
2 //
3 // $Id: Mesh2D.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) 2008-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_MESH_2D_H_
34 #define _NSOUND_MESH_2D_H_
35 
36 #include <Nsound/Nsound.h>
37 
38 #include <iostream>
39 #include <vector>
40 
41 namespace Nsound
42 {
43 
44 // forwards
45 class Buffer;
46 class MeshJunction;
47 
48 //-----------------------------------------------------------------------------
51 class Mesh2D
52 {
53  public:
54 
56  Mesh2D(
57  const float64 & sample_rate,
58  uint32 width,
59  uint32 height,
60  const float64 & leak_gain,
61  const float64 & tau,
62  const float64 & delta = 6.0,
63  const float64 & gamma = 8.0);
64 
66  Mesh2D(const Mesh2D & copy);
67 
69  ~Mesh2D();
70 
72  void
73  clear();
74 
76  float64
77  getEnergy() const;
78 
80  Mesh2D &
81  operator=(const Mesh2D & rhs);
82 
84  Buffer
85  strike(
86  const Buffer & x_pos,
87  const Buffer & y_pos,
88  const Buffer & velocity);
89 
91  Buffer
92  strike(
93  const float64 & x_pos,
94  const float64 & y_pos,
95  const float64 & velocity);
96 
98  void
100  boolean flag,
101  const std::string & dirname = ".",
102  const std::string & prefix = "mesh");
103 
104  private:
105 
107  void
108  allocMemory();
109 
111  void
112  freeMemory();
113 
115  void
116  writeMeshMap();
117 
118  void
119  writeMeshFile(const std::string & mode);
120 
121  MeshJunction *
122  mesh(uint32 x, uint32 y);
123 
125  float64
126  tick(
127  const float64 & x_pos,
128  const float64 & y_pos,
129  const float64 & velocity);
130 
132 
135 
140 
142 
144 
145  boolean dump_mesh_;
146 
147  std::string dirname_;
148  std::string prefix_;
149 
150 }; // class Mesh2D
151 
152 } // namespace Nsound
153 
154 // :mode=c++: jEdit modeline
155 #endif
unsigned int uint32
Definition: Nsound.h:153
float64 sample_rate_
Definition: Mesh2D.h:131
uint32 X_
Definition: Mesh2D.h:133
Mesh2D(const float64 &sample_rate, uint32 width, uint32 height, const float64 &leak_gain, const float64 &tau, const float64 &delta=6.0, const float64 &gamma=8.0)
Constructor.
Definition: Mesh2D.cc:48
float64 getEnergy() const
Calculate total energy in the mesh.
Definition: Mesh2D.cc:182
Buffer strike(const Buffer &x_pos, const Buffer &y_pos, const Buffer &velocity)
Hit the mesh many times at different locations.
Definition: Mesh2D.cc:249
~Mesh2D()
Destructor.
Definition: Mesh2D.cc:105
float64 gamma_
MeshJunction delta.
Definition: Mesh2D.h:139
void clear()
Clears all MeshJunctions to zero.
Definition: Mesh2D.cc:159
void setMeshDumping(boolean flag, const std::string &dirname=".", const std::string &prefix="mesh")
Enables the dumping of mesh values to disk for use with mesh2blender.py.
Definition: Mesh2D.cc:341
void allocMemory()
Allocates memory for the mesh.
Definition: Mesh2D.cc:112
void writeMeshMap()
Write to disk the mesh map, used with mesh2blender.py.
Definition: Mesh2D.cc:269
void freeMemory()
Frees memory from the mesh.
Definition: Mesh2D.cc:169
uint32 Y_
The number of MeshJunctions columns.
Definition: Mesh2D.h:134
Mesh2D & operator=(const Mesh2D &rhs)
Assignment operator.
Definition: Mesh2D.cc:225
double float64
Definition: Nsound.h:146
float64 tau_
MeshJunction leak gain.
Definition: Mesh2D.h:137
boolean dump_mesh_
Center MeshJunction where final sound is collected.
Definition: Mesh2D.h:145
MeshJunction * center_
Array of pointers.
Definition: Mesh2D.h:143
float64 leak_gain_
The number of MeshJunctions rows.
Definition: Mesh2D.h:136
void writeMeshFile(const std::string &mode)
Definition: Mesh2D.cc:309
MeshJunction ** mesh_
MeshJunction gamma.
Definition: Mesh2D.h:141
float64 delta_
MeshJunction tau.
Definition: Mesh2D.h:138
std::string dirname_
Definition: Mesh2D.h:147
std::string prefix_
Definition: Mesh2D.h:148
A Buffer for storing audio samples.
Definition: Buffer.h:60
MeshJunction * mesh(uint32 x, uint32 y)
Definition: Mesh2D.cc:198
float64 tick(const float64 &x_pos, const float64 &y_pos, const float64 &velocity)
Calculate one sample.
Definition: Mesh2D.cc:386