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

Class Drum. More...

#include <Nsound/FluteSlide.h>

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

Public Member Functions

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

Protected Attributes

float64 sample_rate_
 

Detailed Description

Class Drum.

Definition at line 50 of file FluteSlide.h.

Constructor & Destructor Documentation

FluteSlide::FluteSlide ( const float64 sample_rate)

Creates a Bass Kick Drum.

Definition at line 40 of file FluteSlide.cc.

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

Destructor.

Definition at line 48 of file FluteSlide.cc.

49 {
50 }

Member Function Documentation

AudioStream FluteSlide::play ( )
virtual

Plays a demo for this instrument.

Implements Nsound::Instrument.

Definition at line 54 of file FluteSlide.cc.

References play(), and Nsound::Instrument::sample_rate_.

Referenced by main(), and play().

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

Plays a static note for this instrument.

Implements Nsound::Instrument.

Definition at line 71 of file FluteSlide.cc.

References play().

72 {
73  return play(duration, frequency, 1.0, 0.05);
74 }
AudioStream play()
Plays a demo for this instrument.
Definition: FluteSlide.cc:54
AudioStream FluteSlide::play ( const float64 duration,
const float64 frequency,
const float64 presure,
const float64 breath 
)

Plays a static note for this instrument.

Definition at line 78 of file FluteSlide.cc.

References Nsound::Generator::drawLine(), Nsound::FilterTone::filter(), Nsound::Buffer::getLength(), Nsound::AudioStream::normalize(), Nsound::DelayLine::read(), Nsound::Instrument::sample_rate_, Nsound::Generator::whiteNoise(), and Nsound::DelayLine::write().

83 {
84  Sine sine(sample_rate_);
85 
86  float64 n_delay_seconds = 1.0 / frequency;
87 
88  DelayLine delay1(sample_rate_, n_delay_seconds / 2.0);
89  DelayLine delay2(sample_rate_, n_delay_seconds);
90 
91  FilterTone tone(sample_rate_, 2000.0);
92 
93 
94  Buffer env1 = sine.drawLine(0.1, 0.0, pressure)
95  << sine.drawLine(duration - 0.2, pressure, pressure)
96  << sine.drawLine(0.1, pressure, 0.0);
97 
98  Buffer env2 = sine.drawLine(0.01, 0.0, 1.0)
99  << sine.drawLine(duration - 0.02, 1.0, 1.0)
100  << sine.drawLine(0.01, 1.0, 0.0) << 0.0;
101 
102  Buffer flow = env1 * sine.whiteNoise(duration);
103 
104  Buffer input = breath * flow + env1;
105 
106  float64 flute = 0.0;
107 
108  uint32 n_samples = input.getLength();
109 
111 
112  for(uint32 n = 0; n < n_samples; ++n)
113  {
114  float64 x = input[n] + flute * 0.35;
115 
116  delay1.write(x);
117 
118  x = delay1.read();
119 
120  x -= x * x * x;
121 
122  x += flute * 0.4;
123 
124  x = tone.filter(x);
125 
126  y << x;
127 
128  delay2.write(x);
129 
130  flute = delay2.read();
131  }
132 
133  y *= env2 * duration;
134 
135  y.normalize();
136 
137  return y;
138 }
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
uint32 getLength() const
Returns the number of samples in the Buffer.
Definition: Buffer.h:587
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
DOXME.
Definition: Sine.h:43
std::string Nsound::FluteSlide::getInfo ( )
inlinevirtual

Nsound::FluteSlide information.

Implements Nsound::Instrument.

Definition at line 74 of file FluteSlide.h.

75  {
76  return
77  "Nsound::FluteSlide by Nick Hilton\n\n"
78 
79  "Based on physical models written in Csound by Hans Mikelson.\n"
80  "Originally based on Perry Cook's physical model.\n\n"
81 
82  ";PERRY COOK'S SLIDE FLUTE\n"
83  "\n"
84  " instr 3\n"
85  "\n"
86  "aflute1 init 0\n"
87  "ifqc = cpspch(p5)\n"
88  "ipress = p6\n"
89  "ibreath = p7\n"
90  "\n"
91  "; FLOW SETUP\n"
92  "kenv1 linseg 0, .1, ipress, p3-.2, ipress, .1, 0\n"
93  "kenv2 linseg 0, .01, 1, p3-.02, 1, .01, 0\n"
94  "\n"
95  "; THE VALUES MUST BE AROUND -1 AND 1 OR THE CUBIC WILL BLOW UP.\n"
96  "aflow1 rand 1\n"
97  "aflow1 = aflow1 * kenv1\n"
98  "\n"
99  "; .0356 CAN BE USED TO ADJUST THE BREATH LEVEL.\n"
100  "asum1 = ibreath*aflow1 + kenv1\n"
101  "asum2 = asum1 + aflute1*.4\n"
102  "\n"
103  "; EMBOUCHURE DELAY SHOULD BE 1/2 THE BORE DELAY\n"
104  "\n"
105  "ax delay asum2, 1/ifqc/2 - 15/sr\n"
106  "\n"
107  "apoly = ax - ax*ax*ax\n"
108  "asum3 = apoly + aflute1*.4\n"
109  "\n"
110  "avalue tone asum3, 2000\n"
111  "\n"
112  "; BORE THE BORE LENGTH DETERMINES PITCH. SHORTER IS HIGHER.\n"
113  "aflute1 delay avalue, 1/ifqc - 15/sr\n"
114  "\n"
115  " out avalue*p4*kenv2\n"
116  "\n"
117  " endin;\n";
118  };

Member Data Documentation

float64 Nsound::Instrument::sample_rate_
protectedinherited

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