Nsound  0.9.4
bebot.cc
Go to the documentation of this file.
1 //-----------------------------------------------------------------------------
2 //
3 // $Id: bebot.cc 913 2015-08-08 16:41:22Z weegreenblobbie $
4 //
5 //-----------------------------------------------------------------------------
6 
7 #include <Nsound/NsoundAll.h>
8 
9 #include <iostream>
10 
11 using std::cout;
12 using std::cerr;
13 using std::endl;
14 
15 using namespace Nsound;
16 
17 int
18 main(void)
19 {
20  float64 sr = 44100.0;
21 //~ float64 freq = 110.0;
22 
23 //~ float64 T = 10.0 / freq;
24 
25  FilterLowPassIIR lpf(sr, 6, 80, 0.05);
26 
27  Sine gen(sr);
28  Triangle gent(sr, 0.02, 0.02);
29 
30  GeneratorDecay gend(sr);
31 
32  gend.addSlaveSync(gen);
33 //~ gend.addSlaveSync(gent);
34 
35  AudioStream aout(sr, 1);
36 
37  //-------------------------------------------------------------------------
38  // Const frequency, n harmonics ramp up
39 
40  Buffer freqs = gen.drawLine(2, 49.0, 49.0);
41  Buffer Ks = gen.drawLine(2, 275, 8000.0);
42  Buffer alpha = gen.drawLine(2, 6, 36);
43  Buffer f_cut = gen.drawLine(2, 1000, 8000);
44 
45  aout << gen.silence(0.5);
46 
47  Buffer temp = gend.generate2(2, freqs, alpha);
48  temp *= gen.generate(2, Ks);
49 
50  temp -= temp.getMin();
51 
52  temp.normalize();
53 
54  temp *= gent.generate(2, freqs);
55 
56  aout << lpf.filter(temp, f_cut);
57 
58  //-------------------------------------------------------------------------
59  // Frequency ramp, n harmonics constant
60 
61  aout << gen.silence(0.5);
62 
63  freqs = gen.drawLine(2.0, 49, 600.0);
64  Ks = gen.drawLine(2.0, 8000, 8000);
65 
66  temp = gend.generate2(2, freqs, 36);
67  temp *= gen.generate(2, Ks);
68 
69  temp -= temp.getMin();
70  temp.normalize();
71 
72  temp *= gent.generate(2, freqs);
73 
74  aout << lpf.filter(temp, 8000);
75 
76  //-------------------------------------------------------------------------
77  // Frequency const, n harmonics ramp down
78 
79  aout << gen.silence(0.5);
80 
81  freqs = gen.drawLine(2.0, 600, 600.0);
82  Ks = gen.drawLine(2.0, 8000, 275);
83  alpha = gen.drawLine(2, 36, 6);
84  f_cut = gen.drawLine(2, 8000, 1000);
85 
86  temp = gend.generate2(2, freqs, alpha);
87  temp *= gen.generate(2, Ks);
88 
89  temp -= temp.getMin();
90  temp.normalize();
91 
92  temp *= gent.generate(2, freqs);
93 
94  aout << lpf.filter(temp, f_cut);
95 
96  //-------------------------------------------------------------------------
97  // Frequency ramp down, n harmonics constant
98 
99  aout << gen.silence(0.5);
100 
101  freqs = gen.drawLine(2.0, 600, 49.0);
102  Ks = gen.drawLine(2.0, 275, 275);
103  alpha = gen.drawLine(2, 6, 6);
104  f_cut = gen.drawLine(2, 1000, 1000);
105 
106  temp = gend.generate2(2, freqs, alpha);
107  temp *= gen.generate(2, Ks);
108 
109  temp -= temp.getMin();
110  temp.normalize();
111 
112  temp *= gent.generate(2, freqs);
113 
114  aout << lpf.filter(temp, f_cut);
115 
116  //-------------------------------------------------------------------------
117  // output
118 
119  aout << gen.silence(0.5);
120 
121  aout *= 0.666;
122 
123  aout >> "bebot.wav";
124 
125  AudioPlaybackRt pb(sr, 1, 3, 0.05);
126 
127  aout >> pb;
128 
129  return 0;
130 }
Triangle generator.
Definition: Triangle.h:48
AudioStream filter(const AudioStream &x)
A class tha generates decay curves.
double float64
Definition: Nsound.h:146
void addSlaveSync(Generator &slave)
Adds a generator as a slave to this instance for syncing.
Definition: Generator.cc:237
Buffer silence(const float64 &duration) const
This method generates silence.
Definition: Generator.cc:1310
virtual float64 generate(const float64 &frequency)
This is a real-time method for the wavetable oscillator.
Definition: Generator.cc:972
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
A Buffer for storing audio samples.
Definition: Buffer.h:60
int main(void)
Definition: bebot.cc:18
float64 getMin() const
Returns the minimum sample value in the Buffer.
Definition: Buffer.cc:1004
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
virtual float64 generate2(const float64 &frequency, const float64 &alpha)
This is a real-time method for the wavetable oscillator.
DOXME.
Definition: Sine.h:43
float64 sr
Definition: example3.cc:24