Nsound  0.9.4
example1.cc
Go to the documentation of this file.
1 //-----------------------------------------------------------------------------
2 //
3 // $Id$
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 
22  // Creating the Pac Man background tone.
23 
24  Sine sine(sr);
25 
26  float64 time = 0.40;
27  float64 h_time = time / 2.0;
28 
29  // The first tone.
30  Buffer f1 = sine.drawLine(h_time, 345, 923)
31  << sine.drawLine(h_time, 923, 345);
32 
33  Buffer pac_man = sine.generate(7*time, f1);
34 
35  // Here we create an envelop to smoothly finish the waveform, removing
36  // any clicking that might have occured.
37  Buffer envelope = sine.drawLine(7*time-0.005, 1.0, 1.0)
38  << sine.drawLine(0.005, 1.0, 0.0);
39 
40  pac_man *= envelope;
41 
42  pac_man.normalize();
43  pac_man *= 0.25;
44 
45  pac_man >> "example1.wav";
46 
47  // Play to audio device.
48 
49  try
50  {
51  AudioPlayback pb(sr, 1, 16);
52  pac_man >> pb;
53  }
54  catch(Exception e)
55  {
56  cerr << "Could not play audio: " << e.what() << endl;
57  }
58 
59  return 0;
60 }
double float64
Definition: Nsound.h:146
const char * what() const
Definition: Nsound.h:169
int main(void)
Definition: example1.cc:18
virtual float64 generate(const float64 &frequency)
This is a real-time method for the wavetable oscillator.
Definition: Generator.cc:972
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
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
DOXME.
Definition: Sine.h:43
float64 sr
Definition: example3.cc:24