Nsound  0.9.4
example4.cc
Go to the documentation of this file.
1 //-----------------------------------------------------------------------------
2 //
3 // $Id: example4.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 #include <iostream>
13 
14 using std::cerr;
15 using std::endl;
16 
17 //-----------------------------------------------------------------------------
18 int
19 main(void)
20 {
21  float64 sr = 44100.0;
22 
23  Sine sine(sr);
24 
25  GuitarBass bass(sr);
26  FluteSlide slide(sr);
27  Clarinet clarinet(sr);
28 
29  AudioStream out(sr, 1);
30 
31  out << bass.play() << sine.silence(1.0)
32  << slide.play() << sine.silence(1.0)
33  << clarinet.play() << sine.silence(1.0);
34 
35  out *= 0.5;
36 
37  // Set the default Wavefile sample size and rate.
38  Wavefile::setDefaults(sr, 16);
39 
40  out >> "example4.wav";
41 
42  ReverberationRoom room(sr, 0.9); // 0.9 = room feed back (0.0 to 1.0)
43 
44  AudioStream out2 = room.filter(0.5 * (bass.play() << sine.silence(1.5)));
45 
46  out2 >> "example4_reverb.wav";
47 
48  // Try to play the audio
49 
50  try
51  {
52  AudioPlayback pb(sr, 2, 16);
53  out >> pb;
54  out2 >> pb;
55  }
56  catch(Exception e)
57  {
58  cerr << "Could not play audio: " << e.what() << endl;
59  }
60 
61  return 0;
62 }
63 
AudioStream play()
Plays a demo for this instrument.
Definition: Clarinet.cc:56
Class Drum.
Definition: Clarinet.h:48
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: example4.cc:19
static void setDefaults(const float64 &sample_rate=44100.0, const float64 &sample_bits=16.0, const boolean &use_ieee_floats=false)
Definition: Wavefile.cc:117
AudioStream play()
Plays a demo for this instrument.
Definition: GuitarBass.cc:56
Class Drum.
Definition: FluteSlide.h:50
AudioStream play()
Plays a demo for this instrument.
Definition: FluteSlide.cc:54
DOXME.
Definition: Sine.h:43
float64 sr
Definition: example3.cc:24
Class Drum.
Definition: GuitarBass.h:50