Nsound  0.9.4
example2.cc
Go to the documentation of this file.
1 //-----------------------------------------------------------------------------
2 //
3 // $Id: example2.cc 874 2014-09-08 02:21:29Z weegreenblobbie $
4 //
5 //-----------------------------------------------------------------------------
6 
7 // Include the Nsound headers
8 #include <Nsound/NsoundAll.h>
9 
10 using namespace Nsound;
11 
12 using std::cerr;
13 using std::endl;
14 
15 int
16 main(void)
17 {
18  float64 sr = 44100.0;
19 
20  // Create a new instance of the Sine Generator
21  Sine sine(sr);
22 
23  Buffer pan;
24 
25  pan << sine.generate(1.0, 3.0);
26 
27  // Create a stereo AudioStream.
28  AudioStream as(sr, 2);
29 
30  // Fill it with a 220 Hz sine wave.
31  as << 0.5 * sine.generate(4.9, 220);
32 
33  // Execute the pan method.
34  as.pan(pan);
35 
36  // Write the AudioStream to a wave file
37  as >> "example2.wav";
38 
39  // Play it through the sound card
40 
41  try
42  {
43  AudioPlayback pb(sr, 2, 16);
44  as >> pb;
45  }
46  catch(Exception e)
47  {
48  cerr << "Could not play audio: " << e.what() << endl;
49  }
50 
51  return 0;
52 }
double float64
Definition: Nsound.h:146
const char * what() const
Definition: Nsound.h:169
int main(void)
Definition: example2.cc:16
virtual float64 generate(const float64 &frequency)
This is a real-time method for the wavetable oscillator.
Definition: Generator.cc:972
A Buffer for storing audio samples.
Definition: Buffer.h:60
void pan(float64 pan)
Sets the amplitude level left vs right.
Definition: AudioStream.cc:627
DOXME.
Definition: Sine.h:43
float64 sr
Definition: example3.cc:24