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

Class Drum. More...

#include <Nsound/GuitarBass.h>

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

Public Member Functions

 GuitarBass (const float64 &sample_rate)
 Creates a Bass Kick Drum. More...
 
 ~GuitarBass ()
 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...
 
std::string getInfo ()
 Nsound::GuitarBass information. More...
 

Protected Attributes

float64 sample_rate_
 

Detailed Description

Class Drum.

Definition at line 50 of file GuitarBass.h.

Constructor & Destructor Documentation

GuitarBass::GuitarBass ( const float64 sample_rate)

Creates a Bass Kick Drum.

Definition at line 42 of file GuitarBass.cc.

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

Destructor.

Definition at line 50 of file GuitarBass.cc.

51 {
52 }

Member Function Documentation

AudioStream GuitarBass::play ( )
virtual

Plays a demo for this instrument.

Implements Nsound::Instrument.

Definition at line 56 of file GuitarBass.cc.

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

Referenced by main(), play(), and Nsound::AudioPlayback::scanDevices().

57 {
59 
60  // duration, freq
61  y << play(0.450, 61.734)
62  << 0.90 * play(0.300, 123.467)
63  << 0.95 * play(0.150, 92.491)
64  << 0.80 * play(0.450, 61.734)
65  << 0.80 * play(0.450, 46.245)
66  << 0.80 * play(0.450, 55.000)
67  << 0.80 * play(0.450, 61.734)
68  << play(0.450, 73.414)
69  << play(0.650, 61.734);
70 
71  return y;
72 }
AudioStream play()
Plays a demo for this instrument.
Definition: GuitarBass.cc:56
float64 sample_rate_
Definition: Instrument.h:76
AudioStream GuitarBass::play ( const float64 duration,
const float64 frequency 
)
virtual

Plays a static note for this instrument.

Implements Nsound::Instrument.

Definition at line 76 of file GuitarBass.cc.

References Nsound::Buffer::cbegin(), Nsound::Generator::drawLine(), Nsound::FilterTone::filter(), Nsound::FilterBandPassIIR::filter(), Nsound::Generator::generate(), Nsound::DelayLine::read(), Nsound::Instrument::sample_rate_, and Nsound::DelayLine::write().

77 {
79 
80  Buffer outenv = tri.drawLine(0.01, 0.0, 1.0)
81  << tri.drawLine(duration - 0.11, 1.0, 1.0)
82  << tri.drawLine(0.11, 1.0, 0.0);
83 
84  // draw a tirangle envlope
85  float64 triangle_duration = 1.0 / (2.0 * frequency);
86  Buffer triangle = -1.0 * tri.generate(triangle_duration, 2.0 * frequency)
87  << tri.drawLine(duration - triangle_duration, 0.0,0.0);
88 
89  // this envlope is for the body resonance
90  Buffer envres = tri.drawLine(0.1, 0.0, 1.0)
91  << tri.drawLine(duration - 0.1, 1.0, 1.0);
92 
93  FilterTone tone(sample_rate_, frequency * frequency / 10.0);
94 
95  DelayLine delay(sample_rate_, 1.0 / frequency);
96 
97  uint32 n_samples = static_cast<uint32>(duration * sample_rate_);
98 
99  float64 filter_out = 0.0;
100 
102 
103  Buffer::circular_iterator tri_iter = triangle.cbegin();
104 
105  filter_out = tone.filter(0);
106  for(uint32 n = 0; n < n_samples; ++n, ++tri_iter)
107  {
108  delay.write(filter_out + *tri_iter);
109  filter_out = tone.filter(delay.read());
110  y << filter_out;
111  }
112 
113  // Add some resonance from the body
114 
115  FilterBandPassIIR body1(sample_rate_, 2, 120.0, 200.0, 0.01);
116  FilterBandPassIIR body2(sample_rate_, 2, 60.0, 100.0, 0.01);
117 
118  y += 0.0001 * body1.filter(y)
119  + 0.00004 * body2.filter(y);
120 
121  y *= outenv;
122 
123  return y;
124 }
Triangle generator.
Definition: Triangle.h:48
unsigned int uint32
Definition: Nsound.h:153
A circulator iterator for class Buffer.
double float64
Definition: Nsound.h:146
circular_iterator cbegin()
Retruns the itreator at the start of the Buffer.
Definition: Buffer.h:318
float64 sample_rate_
Definition: Instrument.h:76
A Buffer for storing audio samples.
Definition: Buffer.h:60
std::string Nsound::GuitarBass::getInfo ( )
inlinevirtual

Nsound::GuitarBass information.

Implements Nsound::Instrument.

Definition at line 67 of file GuitarBass.h.

68  {
69  return
70  "Nsound::GuitarBass by Nick Hilton\n\n"
71 
72  "Based on physical models written in Csound by Hans Mikelson.\n\n"
73 
74  ";BASS PHYSICAL MODEL\n"
75  " instr 2\n"
76  "\n"
77  "; INITIALIZATIONS\n"
78  "ifqc = cpspch(p5)\n"
79  "kcount init 0\n"
80  "abody1 init 0\n"
81  "abody2 init 0\n"
82  "adline init 0\n"
83  "\n"
84  "; ENVELOPES\n"
85  ";**********\n"
86  "; FILTER ENVELOPE\n"
87  "kenvflt linseg 0, .01, 1, p3-.11, 1, .1, 0\n"
88  "; THIS ENVELOPE LOADS THE STRING WITH A TRIANGLE WAVE.\n"
89  "kenvstr linseg 0, 1/ifqc/8, -p4/2, 1/ifqc/4, p4/2, 1/ifqc/8, 0, p3-1/ifqc, 0\n"
90  "; THIS ENVELOPE IS FOR THE BODY RESONANCE\n"
91  "kenvres linseg 0, .1, 1, p3-.1, 1\n"
92  "\n"
93  "; DELAY LINE WITH FILTERED FEEDBACK\n"
94  "afiltr tone adline, ifqc*ifqc/10\n"
95  "adline delay afiltr + kenvstr, 1/ifqc\n"
96  "\n"
97  "; RESONANCE OF THE BODY\n"
98  "abody1 reson afiltr, 160, 40\n"
99  "abody2 reson afiltr, 80, 20\n"
100  "\n"
101  "aout = afiltr + .0001*kenvres*abody1 + .00004*kenvres*abody2\n"
102  " out aout * kenvflt\n"
103  " endin\n";
104  };

Member Data Documentation

float64 Nsound::Instrument::sample_rate_
protectedinherited

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