Nsound  0.9.4
example6.cc
Go to the documentation of this file.
1 //-----------------------------------------------------------------------------
2 //
3 // $Id: example6.cc 874 2014-09-08 02:21:29Z weegreenblobbie $
4 //
5 //-----------------------------------------------------------------------------
6 
7 // Nsound headers
8 #include <Nsound/NsoundAll.h>
9 
10 using namespace Nsound;
11 
12 using std::cerr;
13 using std::endl;
14 
15 //-----------------------------------------------------------------------------
18  const float64 sr,
19  const float64 duration,
20  const float64 f1,
21  const float64 f2,
22  const float64 gaussian_width)
23 {
24  Sine sin(sr);
25 
26  AudioStream as(sr, 2);
27 
28  Buffer env = sin.drawFatGaussian(duration, gaussian_width);
29 
30  as[0] = sin.generate(duration, f1);
31  as[1] = sin.generate(duration, f2);
32 
33  return as * env;
34 }
35 
36 //-----------------------------------------------------------------------------
37 int
38 main(void)
39 {
40  float64 sr = 44100;
41 
42  Sine sine(sr);
43 
44  AudioStream out(sr, 2);
45 
46  out << softTones(sr, 0.25, 261.63, 523.25, 0.90)
47  << softTones(sr, 0.25, 493.87, 293.66, 0.90)
48  << softTones(sr, 0.25, 329.61, 439.96, 0.90)
49  << softTones(sr, 0.25, 391.97, 349.22, 0.90)
50  << softTones(sr, 0.25, 349.22, 391.97, 0.90)
51  << softTones(sr, 0.25, 439.96, 329.61, 0.90)
52  << softTones(sr, 0.25, 293.66, 493.87, 0.90)
53  << softTones(sr, 0.25, 523.25, 261.63, 0.90)
54  << softTones(sr, 0.25, 261.63, 523.25, 0.90)
55  << softTones(sr, 0.25, 493.87, 293.66, 0.90)
56  << softTones(sr, 0.25, 329.61, 439.96, 0.90)
57  << softTones(sr, 0.25, 391.97, 349.22, 0.90)
58  << softTones(sr, 0.25, 349.22, 391.97, 0.90)
59  << softTones(sr, 0.25, 439.96, 329.61, 0.90)
60  << softTones(sr, 0.25, 293.66, 493.87, 0.90)
61  << softTones(sr, 0.25, 523.25, 261.63, 0.90)
62  << sine.silence(0.25);
63 
64  out << softTones(sr, 0.25, 261.63, 523.25, 0.30)
65  << softTones(sr, 0.25, 493.87, 293.66, 0.30)
66  << softTones(sr, 0.25, 329.61, 439.96, 0.30)
67  << softTones(sr, 0.25, 391.97, 349.22, 0.30)
68  << softTones(sr, 0.25, 349.22, 391.97, 0.30)
69  << softTones(sr, 0.25, 439.96, 329.61, 0.30)
70  << softTones(sr, 0.25, 293.66, 493.87, 0.30)
71  << softTones(sr, 0.25, 523.25, 261.63, 0.30)
72  << softTones(sr, 0.25, 261.63, 523.25, 0.30)
73  << softTones(sr, 0.25, 493.87, 293.66, 0.30)
74  << softTones(sr, 0.25, 329.61, 439.96, 0.30)
75  << softTones(sr, 0.25, 391.97, 349.22, 0.30)
76  << softTones(sr, 0.25, 349.22, 391.97, 0.30)
77  << softTones(sr, 0.25, 439.96, 329.61, 0.30)
78  << softTones(sr, 0.25, 293.66, 493.87, 0.30)
79  << softTones(sr, 0.25, 523.25, 261.63, 0.30)
80  << sine.silence(0.25);
81 
82  out *= 0.5;
83 
84  out >> "example6.wav";
85 
86  // ReverberationRoom(sample_rate, room_feedback, wet_percent, dry_percent, low_pass_freq)
87  ReverberationRoom room(sr, 0.50, 1.0, 1.0, 100.0);
88 
89  AudioStream out2 = 0.5 * room.filter(out);
90 
91  out2 >> "example6_reverb.wav";
92 
93  // Try to play the audio
94 
95  try
96  {
97  AudioPlayback pb(sr, 2, 16);
98  out2 >> pb;
99  }
100  catch(Exception e)
101  {
102  cerr << "Could not play audio: " << e.what() << endl;
103  }
104 
105  return 0;
106 }
107 
Buffer drawFatGaussian(const float64 &duration, const float64 &pass_band_percent=0.01) const
This method draws a standard Gaussian curve over duration seconds, with a specified pass band...
Definition: Generator.cc:434
double float64
Definition: Nsound.h:146
AudioStream filter(const AudioStream &x)
Buffer silence(const float64 &duration) const
This method generates silence.
Definition: Generator.cc:1310
const char * what() const
Definition: Nsound.h:169
int main(void)
Definition: example6.cc:38
virtual float64 generate(const float64 &frequency)
This is a real-time method for the wavetable oscillator.
Definition: Generator.cc:972
AudioStream softTones(const float64 sr, const float64 duration, const float64 f1, const float64 f2, const float64 gaussian_width)
Definition: example6.cc:17
A Buffer for storing audio samples.
Definition: Buffer.h:60
DOXME.
Definition: Sine.h:43
float64 sr
Definition: example3.cc:24