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

Class Hat. More...

#include <Nsound/Hat.h>

Inheritance diagram for Nsound::Hat:
Inheritance graph
[legend]

Public Member Functions

 Hat (const float64 &sample_rate)
 Creates a Hat. More...
 
 Hat (const Hat &copy)
 Copy constructor. More...
 
 ~Hat ()
 Destructor. More...
 
Hatoperator= (const Hat &rhs)
 Assignment. More...
 
AudioStream play ()
 Plays a demo for this instrument. More...
 
AudioStream play (const float64 &duration, const float64 &tune)
 Static play method with option of Hat open or closed. More...
 
AudioStream play (const float64 &duration, const float64 &tune, boolean is_closed)
 Static play method with option of Hat open or closed. More...
 
std::string getInfo ()
 Nsound::Hat information. More...
 

Protected Attributes

Squaresquare_
 
FilterHighPassIIRhpf_
 
float64 sample_rate_
 

Detailed Description

Class Hat.

Simulates a Hat Hit. Based on a Csound Hat by Steven Cook.

source: http://www.csounds.com/cook/

Sound Generators: 808HiHat.orc 808HiHat.sco

Definition at line 61 of file Hat.h.

Constructor & Destructor Documentation

Hat::Hat ( const float64 sample_rate)

Creates a Hat.

Definition at line 46 of file Hat.cc.

References hpf_, Nsound::Instrument::sample_rate_, and square_.

47  :
48  Instrument(sample_rate),
49  square_(NULL),
50  hpf_(NULL)
51 {
53  hpf_ = new FilterHighPassIIR(sample_rate_, 2, 4872.0, 0.05);
54 }
FilterHighPassIIR * hpf_
Definition: Hat.h:108
Square generator.
Definition: Square.h:50
A class for filtering audio in the frequecy domain.
Square * square_
Definition: Hat.h:103
float64 sample_rate_
Definition: Instrument.h:76
Instrument(const float64 &sample_rate)
Definition: Instrument.h:54
Hat::Hat ( const Hat copy)

Copy constructor.

Definition at line 58 of file Hat.cc.

References hpf_, and square_.

59  :
60  Instrument(rhs.sample_rate_),
61  square_(NULL),
62  hpf_(NULL)
63 {
64  square_ = new Square(*rhs.square_);
65  hpf_ = new FilterHighPassIIR(*rhs.hpf_);
66 }
FilterHighPassIIR * hpf_
Definition: Hat.h:108
Square generator.
Definition: Square.h:50
A class for filtering audio in the frequecy domain.
Square * square_
Definition: Hat.h:103
Instrument(const float64 &sample_rate)
Definition: Instrument.h:54
Hat::~Hat ( )

Destructor.

Definition at line 70 of file Hat.cc.

References hpf_, and square_.

71 {
72  delete square_;
73  delete hpf_;
74 }
FilterHighPassIIR * hpf_
Definition: Hat.h:108
Square * square_
Definition: Hat.h:103

Member Function Documentation

Hat & Hat::operator= ( const Hat rhs)

Assignment.

Definition at line 79 of file Hat.cc.

References hpf_, Nsound::Instrument::sample_rate_, and square_.

80 {
81  delete square_;
82  delete hpf_;
83 
85  square_ = new Square(*rhs.square_);
86  hpf_ = new FilterHighPassIIR(*rhs.hpf_);
87 
88  return *this;
89 }
FilterHighPassIIR * hpf_
Definition: Hat.h:108
Square generator.
Definition: Square.h:50
A class for filtering audio in the frequecy domain.
Square * square_
Definition: Hat.h:103
float64 sample_rate_
Definition: Instrument.h:76
AudioStream Hat::play ( )
virtual

Plays a demo for this instrument.

Implements Nsound::Instrument.

Definition at line 93 of file Hat.cc.

References Nsound::AudioStream::add(), and Nsound::Instrument::sample_rate_.

Referenced by my_main(), and play().

94 {
96 
97  float64 offset = 0.124;
98 
99  y << play(1.0, 1.0, true);
100 
101  // duration, tune, is_open
102 //~ y.add(play(1.0, 1.0, true), 0 * offset);
103  y.add(play(1.0, 1.0, true), 1 * offset);
104  y.add(play(1.0, 1.0, false), 2 * offset);
105  y.add(play(1.0, 1.0, true) , 3 * offset);
106 
107  y.add(play(1.0, 1.0, true) , 4 * offset);
108  y.add(play(1.0, 1.0, true) , 5 * offset);
109  y.add(play(1.0, 1.0, true) , 6 * offset);
110  y.add(play(1.0, 1.0, false), 7 * offset);
111 
112  y.add(play(1.0, 1.0, true) , 8 * offset);
113  y.add(play(1.0, 1.0, true) , 9 * offset);
114  y.add(play(1.0, 1.0, false), 10 * offset);
115  y.add(play(1.0, 1.0, true) , 11 * offset);
116 
117  y.add(play(1.0, 1.0, true) , 12 * offset);
118  y.add(play(1.0, 1.0, true) , 13 * offset);
119  y.add(play(1.0, 1.0, true) , 14 * offset);
120  y.add(play(1.0, 1.0, false), 15 * offset);
121 
122  y.add(play(1.0, 1.0, true) , 16 * offset);
123  y.add(play(1.0, 1.0, true) , 17 * offset);
124  y.add(play(1.0, 1.0, false), 18 * offset);
125  y.add(play(1.0, 1.0, true) , 19 * offset);
126 
127  y.add(play(1.0, 1.0, true) , 20 * offset);
128  y.add(play(1.0, 1.0, true) , 21 * offset);
129  y.add(play(1.0, 1.0, true) , 22 * offset);
130  y.add(play(1.0, 1.0, false), 23 * offset);
131 
132  y.add(play(1.0, 0.9, true) , 24 * offset);
133  y.add(play(1.0, 0.8, true) , 25 * offset);
134  y.add(play(1.0, 0.7, true) , 26 * offset);
135  y.add(play(1.0, 0.6, true) , 27 * offset);
136 
137  y.add(play(1.0, 0.5, true) , 28 * offset);
138  y.add(play(1.0, 0.4, true) , 29 * offset);
139  y.add(play(1.0, 0.3, true) , 30 * offset);
140  y.add(play(1.0, 0.2, true) , 31 * offset);
141 
142  return y;
143 }
AudioStream play()
Plays a demo for this instrument.
Definition: Hat.cc:93
double float64
Definition: Nsound.h:146
float64 sample_rate_
Definition: Instrument.h:76
AudioStream Nsound::Hat::play ( const float64 duration,
const float64 tune 
)
inlinevirtual

Static play method with option of Hat open or closed.

Implements Nsound::Instrument.

Definition at line 84 of file Hat.h.

References play().

87  { return play(duration, tune, true); };
AudioStream play()
Plays a demo for this instrument.
Definition: Hat.cc:93
AudioStream Hat::play ( const float64 duration,
const float64 tune,
boolean  is_closed 
)

Static play method with option of Hat open or closed.

Definition at line 149 of file Hat.cc.

References Nsound::Generator::drawDecay(), Nsound::Generator::drawLine(), Nsound::FilterHighPassIIR::filter(), Nsound::Generator::generate(), hpf_, Nsound::Instrument::sample_rate_, Nsound::Generator::silence(), and square_.

153 {
154  float64 play_duration = duration;
155  float64 silence_duration = 0.0;
156 
157  float64 env_offset = 0.55 * play_duration;
158 
159  if(is_closed)
160  {
161  play_duration *= 0.06;
162  silence_duration = duration - play_duration;
163  env_offset = 0.0;
164  }
165 
166  float64 frequency = tune * 530.0;
167 
168  Buffer env = square_->drawLine(0.0005, 0.1, 1.0)
169  << square_->drawDecay(play_duration-0.0005 - env_offset, 7.0)
170  << square_->silence(silence_duration + env_offset);
171 
172  AudioStream out(sample_rate_, 1);
173 
174  out << square_->generate(play_duration, frequency);
175 
176  out += square_->generate(play_duration, frequency * 1.5038);
177  out += square_->generate(play_duration, frequency * 1.6132);
178  out += square_->generate(play_duration, frequency * 1.9642);
179  out += square_->generate(play_duration, frequency * 2.5321);
180  out += square_->generate(play_duration, frequency * 2.7547);
181 
182  out /= 2.0;
183 
184  out = hpf_->filter(out);
185  out = hpf_->filter(out);
186 
187  return out * env;
188 }
FilterHighPassIIR * hpf_
Definition: Hat.h:108
double float64
Definition: Nsound.h:146
Buffer silence(const float64 &duration) const
This method generates silence.
Definition: Generator.cc:1310
virtual float64 generate(const float64 &frequency)
This is a real-time method for the wavetable oscillator.
Definition: Generator.cc:972
Buffer drawDecay(const float64 &duration, const float64 &alpha=2.0 *M_PI) const
This method draws an exponential curve that decays from 1.0 to 0.0 over the duration.
Definition: Generator.cc:388
Square * square_
Definition: Hat.h:103
float64 sample_rate_
Definition: Instrument.h:76
A Buffer for storing audio samples.
Definition: Buffer.h:60
AudioStream filter(const AudioStream &x)
Buffer drawLine(const float64 &duration, const float64 &amplitude_start, const float64 &amplitude_finish) const
This method draws a linear line beteween 2 points.
Definition: Generator.cc:464
std::string Nsound::Hat::getInfo ( )
inlinevirtual

Nsound::Hat information.

Implements Nsound::Instrument.

Definition at line 97 of file Hat.h.

98  {
99  return
100  "Nsound::Hat by Nick Hilton on 2009-11-13\n"
101  "Simulates a Hat Hit. Based on a Csound Hat by Steven Cook.\n"
102  "source: http://www.csounds.com/cook/\n";
103  };

Member Data Documentation

Square* Nsound::Hat::square_
protected

Definition at line 103 of file Hat.h.

Referenced by Hat(), operator=(), play(), and ~Hat().

FilterHighPassIIR* Nsound::Hat::hpf_
protected

Definition at line 108 of file Hat.h.

Referenced by Hat(), operator=(), play(), and ~Hat().

float64 Nsound::Instrument::sample_rate_
protectedinherited

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