Nsound  0.9.4
test_granulator.cc
Go to the documentation of this file.
1 //-----------------------------------------------------------------------------
2 //
3 // $Id: test_granulator.cc 874 2014-09-08 02:21:29Z weegreenblobbie $
4 //
5 // Copyright (c) 2002-2007 Nick Hilton
6 //
7 // weegreenblobbie_yahoo_com (replace '_' with '@' and '.')
8 //
9 //-----------------------------------------------------------------------------
10 
11 //-----------------------------------------------------------------------------
12 //
13 // This program is free software; you can redistribute it and/or modify
14 // it under the terms of the GNU General Public License as published by
15 // the Free Software Foundation; either version 2 of the License, or
16 // (at your option) any later version.
17 //
18 // This program is distributed in the hope that it will be useful,
19 // but WITHOUT ANY WARRANTY; without even the implied warranty of
20 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 // GNU Library General Public License for more details.
22 //
23 // You should have received a copy of the GNU General Public License
24 // along with this program; if not, write to the Free Software
25 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
26 //
27 //-----------------------------------------------------------------------------
28 
29 #include <Nsound/AudioStream.h>
30 #include <Nsound/Buffer.h>
31 #include <Nsound/Granulator.h>
32 #include <Nsound/Sine.h>
33 #include <Nsound/TicToc.h>
34 #include <Nsound/Wavefile.h>
35 
36 #include <cmath>
37 #include <iostream>
38 
39 using namespace Nsound;
40 
41 using std::cerr;
42 using std::cout;
43 using std::endl;
44 using std::flush;
45 
46 int
47 main(int argc, char ** argv)
48 {
51 
52  Granulator grains(44100, Granulator::GAUSSIAN_30);
53  Sine sin(44100);
54 
55  Buffer grain_freqs;
56  grain_freqs << 180;
57 
58  Buffer waves_per_grain;
59  waves_per_grain << 2.0;
60 
61  Buffer grains_per_second = 1200 * sin.drawDecay(5.0);
62 
63  Tic();
64  cout << "gran.generate() ... " << flush;
65 
66  Buffer output(4096);
67 
68  output << 0.6 * grains.generate(5, grain_freqs, waves_per_grain, grains_per_second);
69 
70  cout << Toc() << " seconds" << endl << flush;
71 
72  output >> "grains.wav";
73 
74  return 0;
75 }
Nsound::Buffer generate(const float64 &duration, const float64 &grain_frequency, const float64 &waves_per_grain, const float64 &grains_per_second)
Definition: Granulator.cc:193
Buffer drawDecay(const float64 &duration, const float64 &alpha=2.0 *M_PI) const
This method draws an exponential curve that decays from 1.0 to 0.0 over the duration.
Definition: Generator.cc:388
A Buffer for storing audio samples.
Definition: Buffer.h:60
int main(int argc, char **argv)
static void setDefaultSampleRate(const int32 rate)
Definition: Wavefile.cc:70
Nsound::float64 Toc()
Definition: TicToc.cc:42
static void setDefaultSampleSize(uint32 size)
Definition: Wavefile.cc:79
void Tic()
Definition: TicToc.cc:37
DOXME.
Definition: Sine.h:43