Nsound  0.9.4
Macros | Functions
test_pluck.cc File Reference
#include <Nsound/NsoundAll.h>
#include "Test.h"
#include <math.h>
#include <iostream>
Include dependency graph for test_pluck.cc:

Go to the source code of this file.

Macros

#define THIS_FILE   "test_pluck.cc"
 

Functions

int main (int argc, char **argv)
 

Macro Definition Documentation

#define THIS_FILE   "test_pluck.cc"

Definition at line 43 of file test_pluck.cc.

Function Documentation

int main ( int  argc,
char **  argv 
)

Definition at line 45 of file test_pluck.cc.

References Nsound::Buffer::add(), Nsound::Pluck::generate(), Nsound::AudioStream::getReverse(), Nsound::Generator::silence(), TEST_HEADER, Nsound::Tic(), and Nsound::Toc().

46 {
47  Pluck pluck(44100, 1024);
48 
49  AudioStream output(44100, 1);
50 
51  cout << TEST_HEADER
52  << "pluck.generate() ..." << flush;
53 
54  Tic();
55 
56  Buffer temp = pluck.generate(2.0, 246.94);
57 
58  cout << " " << Toc() << " seconds" << endl << flush;
59 
60  output << temp;
61  output << temp.getReverse() << pluck.silence(1.0);
62 
63  cout << TEST_HEADER
64  << "pluck.generate(): plucking 6 strings: guitar chord E ..."
65  << flush;
66 
67  Tic();
68 
69  Buffer string6 = pluck.generate(2.0, 82.41); // E2 C4 = middle C
70  Buffer string5 = pluck.generate(2.0, 123.47); // B2
71  Buffer string4 = pluck.generate(2.0, 164.81); // E3
72  Buffer string3 = pluck.generate(2.0, 207.65); // G3#
73  Buffer string2 = pluck.generate(2.0, 246.94); // B3
74  Buffer string1 = pluck.generate(2.0, 329.63); // E4
75 
76  // add in each string with a little delay
77 
78  uint32 offset = static_cast<uint32>(0.150 * 44100.0);
79 
80  Buffer final(string6);
81 
82  final.add(string5, offset );
83  final.add(string4, offset * 2);
84  final.add(string3, offset * 3);
85  final.add(string2, offset * 4);
86  final.add(string1, offset * 5);
87 
88  final.normalize();
89 
90  cout << " " << Toc() << " seconds" << endl << flush;
91 
92  output << final;
93  output << final.getReverse()
94  << pluck.silence(0.5);
95 
96  output >> "test_pluck.wav";
97 
98  return 0;
99 }
unsigned int uint32
Definition: Nsound.h:153
Implements a simple Karplus-Strong String Synthesis algorithim.
Definition: Pluck.h:42
#define TEST_HEADER
Definition: Test.h:45
A Buffer for storing audio samples.
Definition: Buffer.h:60
Nsound::float64 Toc()
Definition: TicToc.cc:42
void Tic()
Definition: TicToc.cc:37
void add(const Buffer &buffer, uint32 offset=0, uint32 n_samples=0)
This method adds buffer to *this.
Definition: Buffer.cc:225
Buffer getReverse() const
Reverses the samples in a copy of this Buffer.
Definition: Buffer.h:1558