Nsound  0.9.4
DrumKickBass.cc
Go to the documentation of this file.
1 //-----------------------------------------------------------------------------
2 //
3 // $Id: DrumKickBass.cc 874 2014-09-08 02:21:29Z weegreenblobbie $
4 //
5 // Copyright (c) 2004-2008 Nick Hilton
6 //
7 // weegreenblobbie_yahoo_com (replace '_' with '@' and '.')
8 //
9 //-----------------------------------------------------------------------------
10 
11 //-----------------------------------------------------------------------------
12 //
13 // This program is free software; you can redistribute it and/or modify
14 // it under the terms of the GNU General Public License as published by
15 // the Free Software Foundation; either version 2 of the License, or
16 // (at your option) any later version.
17 //
18 // This program is distributed in the hope that it will be useful,
19 // but WITHOUT ANY WARRANTY; without even the implied warranty of
20 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 // GNU Library General Public License for more details.
22 //
23 // You should have received a copy of the GNU General Public License
24 // along with this program; if not, write to the Free Software
25 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
26 //
27 //-----------------------------------------------------------------------------
28 
29 #include <Nsound/AudioStream.h>
30 #include <Nsound/Buffer.h>
31 #include <Nsound/DrumKickBass.h>
33 #include <Nsound/Square.h>
34 
35 // DEBUG
36 #include <Nsound/Plotter.h>
37 
38 using namespace Nsound;
39 
40 //-----------------------------------------------------------------------------
43  const float64 & sample_rate,
44  const float64 & high_frequency,
45  const float64 & low_frequency)
46  :
47  Instrument(sample_rate),
48  hi_f_(high_frequency),
49  lo_f_( low_frequency){}
50 
51 //-----------------------------------------------------------------------------
54 
58 {
60 
61  y << play(0.6, 120.0, 51.0)
62  << play(0.6, 120.0, 51.0)
63  << play(0.6, 120.0, 51.0)
64  << play(0.6, 120.0, 51.0);
65 
66  return y;
67 }
68 
72  const float64 & duration,
73  const float64 & frequency)
74 {
75  return play(duration, frequency, lo_f_);
76 }
77 
78 
82  const float64 & duration,
83  const float64 & hi_freq,
84  const float64 & low_freq)
85 {
86  Square square(sample_rate_);
87 
88  Buffer signal_freqs = 2.333 * hi_freq * square.drawDecay(0.08, 7.0)
89  + low_freq
90  << square.drawLine(duration - 0.08, low_freq, low_freq);
91 
92  Buffer signal = -0.5 * square.generate(duration, signal_freqs) << 0.0;
93 
94 
95  Buffer filter_freqs = 0.8*square.drawDecay(duration * 0.5, 7.0) + 0.2
96  << square.drawLine(duration * 0.5, 0.2, 0.0);
97 
98  filter_freqs *= 2.0 * signal_freqs;
99 
102  sample_rate_, filter_freqs[0], 0.7071, 0.0);
103 
106  sample_rate_, signal_freqs[0] * 3.0, 1.0, 2.0);
107 
110  sample_rate_, low_freq * 1.25, 1.0, 2.5);
111 
113 
114  y = f1.filter(signal, filter_freqs);
115 
116  for(uint32 i = 0; i < y.getLength(); ++i)
117  {
118  y[0][1] = std::atan(y[0][i] * 20.0);
119  }
120 
121  y = f2.filter(y, signal_freqs * 3.0);
122 
123  y = f3.filter(y) * 0.56;
124 
125  return y;
126 }
127 
131  const float64 & duration,
132  const Buffer & high_frequency,
133  const Buffer & low_frequency)
134 {
135 
136  // FIXME FIXME FIXME FIXME, this is not dynamic!
137  return play(duration, high_frequency[0], low_frequency[0]);
138 
139 }
140 
141 
142 // :mode=c++: jEdit modeline
Implementation of Zoelzer's parametric equalizer filters, with some modifications by the author...
unsigned int uint32
Definition: Nsound.h:153
AudioStream play()
Plays a demo for this instrument.
Definition: DrumKickBass.cc:57
uint32 getLength() const
Returns the number of samples of audio data in the stream.
Definition: AudioStream.cc:197
Square generator.
Definition: Square.h:50
double float64
Definition: Nsound.h:146
DrumKickBass(const float64 &sample_rate, const float64 &high_frequency, const float64 &low_frequency)
Creates a Bass Kick Drum.
Definition: DrumKickBass.cc:42
AudioStream filter(const AudioStream &x)
~DrumKickBass()
Destructor.
Definition: DrumKickBass.cc:53
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
The Nsound Instrument baseclass. All Nsound instruments extend this class.
Definition: Instrument.h:50
float64 sample_rate_
Definition: Instrument.h:76
A Buffer for storing audio samples.
Definition: Buffer.h:60
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