Nsound  0.9.4
Functions
example6.cc File Reference
#include <Nsound/NsoundAll.h>
Include dependency graph for example6.cc:

Go to the source code of this file.

Functions

AudioStream softTones (const float64 sr, const float64 duration, const float64 f1, const float64 f2, const float64 gaussian_width)
 
int main (void)
 

Function Documentation

AudioStream softTones ( const float64  sr,
const float64  duration,
const float64  f1,
const float64  f2,
const float64  gaussian_width 
)

Definition at line 17 of file example6.cc.

References Nsound::Generator::drawFatGaussian(), and Nsound::Generator::generate().

Referenced by main().

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 }
A Buffer for storing audio samples.
Definition: Buffer.h:60
DOXME.
Definition: Sine.h:43
float64 sr
Definition: example3.cc:24
int main ( void  )

Definition at line 38 of file example6.cc.

References Nsound::ReverberationRoom::filter(), Nsound::Generator::silence(), softTones(), sr, and Nsound::Exception::what().

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 }
double float64
Definition: Nsound.h:146
const char * what() const
Definition: Nsound.h:169
AudioStream softTones(const float64 sr, const float64 duration, const float64 f1, const float64 f2, const float64 gaussian_width)
Definition: example6.cc:17
DOXME.
Definition: Sine.h:43
float64 sr
Definition: example3.cc:24