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

Class Drum. More...

#include <Nsound/Clarinet.h>

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

Public Member Functions

 Clarinet (const float64 &sample_rate)
 Creates a Bass Kick Drum. More...
 
 ~Clarinet ()
 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 &presure, const float64 &filter, const float64 &reed_stiffness)
 Plays a static note for this instrument. More...
 
std::string getInfo ()
 Nsound::Clarinet information. More...
 

Protected Attributes

float64 sample_rate_
 

Detailed Description

Class Drum.

Definition at line 48 of file Clarinet.h.

Constructor & Destructor Documentation

Clarinet::Clarinet ( const float64 sample_rate)

Creates a Bass Kick Drum.

Definition at line 42 of file Clarinet.cc.

43  :
44  Instrument(sample_rate)
45 {
46 }
Instrument(const float64 &sample_rate)
Definition: Instrument.h:54
Clarinet::~Clarinet ( )

Destructor.

Definition at line 50 of file Clarinet.cc.

51 {
52 }

Member Function Documentation

AudioStream Clarinet::play ( )
virtual

Plays a demo for this instrument.

Implements Nsound::Instrument.

Definition at line 56 of file Clarinet.cc.

References Nsound::Instrument::sample_rate_.

Referenced by main(), and play().

57 {
59 
60  // duration, freq
61  y << play(0.600, 261.616)
62  << play(0.600, 293.656)
63  << play(0.600, 329.609)
64  << play(0.600, 349.218)
65  << play(0.600, 391.973)
66  << play(1.800, 445.000);
67 
68  return y;
69 }
AudioStream play()
Plays a demo for this instrument.
Definition: Clarinet.cc:56
float64 sample_rate_
Definition: Instrument.h:76
AudioStream Clarinet::play ( const float64 duration,
const float64 frequency 
)
virtual

Plays a static note for this instrument.

Implements Nsound::Instrument.

Definition at line 73 of file Clarinet.cc.

References play().

74 {
75  return play(duration, frequency, 1.8, 1000.0, 0.2);
76 }
AudioStream play()
Plays a demo for this instrument.
Definition: Clarinet.cc:56
AudioStream Clarinet::play ( const float64 duration,
const float64 frequency,
const float64 presure,
const float64 filter,
const float64 reed_stiffness 
)

Plays a static note for this instrument.

Definition at line 80 of file Clarinet.cc.

References Nsound::Generator::drawLine(), Nsound::FilterHighPassIIR::filter(), Nsound::FilterLowPassIIR::filter(), Nsound::Generator::generate(), Nsound::Buffer::getLength(), Nsound::AudioStream::normalize(), Nsound::DelayLine::read(), Nsound::Instrument::sample_rate_, Nsound::AudioStream::substream(), and Nsound::DelayLine::write().

86 {
87  DelayLine delay1(sample_rate_, (1.0 / frequency));
88  DelayLine delay2(sample_rate_, (1.0 / frequency));
89  Sine sin(sample_rate_);
90  FilterLowPassIIR tone(sample_rate_, 2, filter, 0.0);
91  FilterHighPassIIR atone(sample_rate_, 2, filter, 0.0);
92 
93  Buffer reed_wave = sin.drawLine( 80.0 / 256.0, 1.0, 1.0)
94  << sin.drawLine(156.0 / 256.0, 1.0, -1.0)
95  << sin.drawLine( 20.0 / 256.0, -1.0, -1.0);
96 
97  float64 env_peak = (0.55 + 0.3 * pressure);
98 
99  Buffer env1 = sin.drawLine(0.005, 0.0, env_peak)
100  << sin.drawLine(duration - 0.015, env_peak, env_peak)
101  << sin.drawLine(0.01, env_peak, 0.0);
102 
103  Buffer vibrato_env = sin.drawLine(duration, 0.0, 0.1);
104 
105  Buffer pressurem = vibrato_env * sin.generate(duration, 5.0) + 1.0;
106 
107  pressurem *= (0.3 * env1);
108 
109  float64 reed_bell = 0.0;
110 
111  uint32 n_samples = pressurem.getLength();
112 
114 
115  Buffer xxx;
116 
117  for(uint32 n = 0; n < n_samples; ++n)
118  {
119  float64 filter_out = tone.filter(reed_bell);
120 
121  float64 x = -1.0 * pressurem[n] - 0.95 * filter_out - reed_stiffness;
122 
123  xxx << x;
124 
125  uint32 reed_index = static_cast<uint32>((0.25 * x + 0.5) * sample_rate_);
126 
127  x *= reed_wave[reed_index];
128 
129  x += pressurem[n];
130 
131  delay2.write(x);
132  reed_bell = delay2.read();
133 
134  x = atone.filter(reed_bell);
135 
136  y << x;
137 
138  }
139 
140  y.normalize();
141 
142  float64 dt = 1.0 / frequency;
143 
144  // Declick, at the very beginning and ends, the reed_wave values goes crazy
145 
146  y = y.substream(dt, duration - dt);
147 
148  Buffer out_env = sin.drawLine(0.01, 0.0, 1.0)
149  << sin.drawLine(duration - 0.02, 1.0, 1.0)
150  << sin.drawLine(0.01, 1.0, 0.0);
151 
152  y *= out_env;
153 
154  return y;
155 }
unsigned int uint32
Definition: Nsound.h:153
std::ostream & write(std::ostream &out) const
Serializes the Buffer to output stream, no endian checks.
Definition: Buffer.cc:1922
double float64
Definition: Nsound.h:146
A class for filtering audio in the frequecy domain.
uint32 getLength() const
Returns the number of samples in the Buffer.
Definition: Buffer.h:587
A class for filtering audio in the frequecy domain.
float64 sample_rate_
Definition: Instrument.h:76
A Buffer for storing audio samples.
Definition: Buffer.h:60
DOXME.
Definition: Sine.h:43
std::string Nsound::Clarinet::getInfo ( )
inlinevirtual

Nsound::Clarinet information.

Implements Nsound::Instrument.

Definition at line 73 of file Clarinet.h.

74  {
75  return
76  "Nsound::Clarinet by Nick Hilton\n\n"
77 
78  "Based on physical models written in Csound by Hans Mikelson.\n"
79  "Originally based on Perry Cook's physical model.\n\n"
80 
81  ";PERRY COOK'S CLARINET\n"
82  "\n"
83  " instr 5\n"
84  "asum2 init 0\n"
85  "abellreed init 0\n"
86  "aout init 0\n"
87  "kenv1 linseg 0, .005, .55 + .3*p4, p3 - .015, .55 + .3*p4, .01, 0\n"
88  "\n"
89  "; REED SECTION\n"
90  "apressm = kenv1\n"
91  "arefilt tone abellreed, 1500\n"
92  "asum2 = (-.95)*arefilt - apressm\n"
93  "areedtab tablei asum2/4+.34, 1, 1, .5\n"
94  "\n"
95  "abellreed delayr 1/p5/2\n"
96  " delayw aout\n"
97  "aout delayr 1/p5/2\n"
98  " delayw apressm + areedtab*asum2\n"
99  "\n"
100  " out aout*10000\n"
101  " endin;\n";
102  };

Member Data Documentation

float64 Nsound::Instrument::sample_rate_
protectedinherited

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