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

Class DrumBD01. More...

#include <Nsound/DrumBD01.h>

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

Public Member Functions

 DrumBD01 (const float64 &sample_rate)
 Creates a Drum. More...
 
 ~DrumBD01 ()
 Destructor. More...
 
AudioStream play ()
 Plays a demo for this instrument. More...
 
AudioStream play (const float64 &duration, const float64 &frequency)
 Plays a static note for this instrument. More...
 
AudioStream play (const float64 &duration, const float64 &frequency, const float64 &velocity)
 Static play method. More...
 
std::string getInfo ()
 Nsound::DrumBD01 information. More...
 

Protected Attributes

float64 sample_rate_
 

Detailed Description

Class DrumBD01.

Definition at line 50 of file DrumBD01.h.

Constructor & Destructor Documentation

DrumBD01::DrumBD01 ( const float64 sample_rate)

Creates a Drum.

Definition at line 40 of file DrumBD01.cc.

41  :
42  Instrument(sample_rate){}
Instrument(const float64 &sample_rate)
Definition: Instrument.h:54
DrumBD01::~DrumBD01 ( )

Destructor.

Definition at line 46 of file DrumBD01.cc.

46 {}

Member Function Documentation

AudioStream DrumBD01::play ( )
virtual

Plays a demo for this instrument.

Implements Nsound::Instrument.

Definition at line 50 of file DrumBD01.cc.

References Nsound::Instrument::sample_rate_.

Referenced by my_main(), and play().

51 {
53 
54  y << play(0.5, 50.0, 0.25)
55  << play(0.5, 50.0, 0.50)
56  << play(0.5, 50.0, 0.75)
57  << play(0.5, 50.0, 1.0);
58 
59  return y;
60 }
AudioStream play()
Plays a demo for this instrument.
Definition: DrumBD01.cc:50
float64 sample_rate_
Definition: Instrument.h:76
AudioStream DrumBD01::play ( const float64 duration,
const float64 frequency 
)
virtual

Plays a static note for this instrument.

Implements Nsound::Instrument.

Definition at line 64 of file DrumBD01.cc.

References play().

67 {
68  return play(duration, frequency, 1.0);
69 }
AudioStream play()
Plays a demo for this instrument.
Definition: DrumBD01.cc:50
AudioStream DrumBD01::play ( const float64 duration,
const float64 frequency,
const float64 velocity 
)

Static play method.

Definition at line 74 of file DrumBD01.cc.

References Nsound::Generator::drawDecay(), Nsound::Generator::drawLine(), Nsound::FilterLowPassIIR::filter(), Nsound::Generator::generate(), Nsound::Buffer::getSqrt(), Nsound::Buffer::limit(), Nsound::Buffer::normalize(), Nsound::Instrument::sample_rate_, and Nsound::Generator::whiteNoise().

78 {
79  float64 v = velocity;
80 
81  if(v > 1.0) v = 1.0;
82  if(v < 0.0) v = 0.0;
83 
84  float64 fdec = 0.025 * (v * v + 0.1072);
85 
86  // Create a sine generator
87  Sine sin(sample_rate_);
88 
89  Buffer kcps1 = sin.drawDecay(10.0*fdec, 7.0)
90  << sin.drawLine(duration - fdec, 0.0, 0.0);
91 
92  Buffer kcps2 = sin.drawDecay(10.0*0.32, 7.0)
93  << sin.drawLine(duration - 0.32, 0.0, 0.0);
94 
95  Buffer kcps = (4.3333 * kcps1 + kcps2) * frequency;
96 
97  Buffer klpf = sin.drawDecay(10.0*0.04, 7.0)
98  << sin.drawLine(duration - 0.04, 0.0, 0.0);
99 
100  Buffer klpf2 = 8.0 * sin.drawDecay(10.0*0.0005, 7.0)
101  << sin.drawLine(duration - 0.0005, 0.0, 0.0);
102 
103  Buffer kamp = 1.0
104  - 0.5*sin.drawDecay(0.15, 7.0)
105  << sin.drawLine(duration - 0.15, 1.0, 1.0);
106 
107  Buffer a1 = sin.generate(duration, kcps);
108 
109  a1.limit(-0.25, 0.25);
110 
111  Buffer freq = kcps * (0.5 + klpf2);
112 
113  FilterTone tone(sample_rate_, freq[0]);
114 
115  a1 = tone.filter(a1, freq);
116 
117  Buffer a2 = sin.whiteNoise(duration) * sin.whiteNoise(duration);
118 
119  tone.makeKernel(500.0);
120 
121  a2 -= tone.filter(a2);
122 
123  freq = 4.0 * (klpf + klpf2) * kcps;
124 
125  FilterLowPassIIR lpf(sample_rate_, 2, freq[0], 0.01);
126 
127  a1 = lpf.filter(kamp * a1, freq);
128 
129  a2 = lpf.filter(kamp * a2, kcps);
130  a2 *= 5.0 * klpf.getSqrt();
131 
132  a1 += a2 * 1.0;
133 
134  a1.normalize();
135 
136  Buffer env = sin.drawLine(duration - 0.01, 1.0, 1.0)
137  << sin.drawLine(0.005, 1.0, 0.0)
138  << sin.drawLine(0.005, 0.0, 0.0);
139 
140  AudioStream as(sample_rate_, 1);
141 
142  as << env * a1;
143 
144  return as;
145 }
void limit(float64 min, float64 max)
Limits the Buffer to min and max.
Definition: Buffer.cc:876
double float64
Definition: Nsound.h:146
A class for filtering audio in the frequecy domain.
void normalize()
Multiplies the Buffer by a constant gain so the peak sample has magnitude 1.0.
Definition: Buffer.cc:1064
float64 sample_rate_
Definition: Instrument.h:76
A Buffer for storing audio samples.
Definition: Buffer.h:60
Buffer getSqrt() const
Taks the square root of each sample in a copy of this Buffer.
Definition: Buffer.h:1779
DOXME.
Definition: Sine.h:43
std::string Nsound::DrumBD01::getInfo ( )
inlinevirtual

Nsound::DrumBD01 information.

Implements Nsound::Instrument.

Definition at line 73 of file DrumBD01.h.

74  {
75  return
76  "Nsound::DrumBD01 by Nick Hilton on 2009-05-02\n"
77  "Simulates a bass drum. Based on a Csound drum.\n"
78  "source: http://www.csounds.com/istvan/html/drums.html\n";
79  };

Member Data Documentation

float64 Nsound::Instrument::sample_rate_
protectedinherited

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