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

Go to the source code of this file.

Functions

int main (void)
 

Function Documentation

int main ( void  )

Definition at line 18 of file example1.cc.

References Nsound::Generator::drawLine(), Nsound::Generator::generate(), Nsound::Buffer::normalize(), sr, and Nsound::Exception::what().

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
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
DOXME.
Definition: Sine.h:43
float64 sr
Definition: example3.cc:24