Nsound  0.9.4
mynameis.cc
Go to the documentation of this file.
1 //-----------------------------------------------------------------------------
2 //
3 // $Id: mynameis.cc 874 2014-09-08 02:21:29Z weegreenblobbie $
4 //
5 //-----------------------------------------------------------------------------
6 
7 // Nsound headers
8 #include <Nsound/NsoundAll.h>
9 
10 using namespace Nsound;
11 
12 int
13 main(void)
14 {
15  AudioStream as0("mynameis.wav");
16 
17  float64 sr = as0.getSampleRate();
18 
19  // Get rid of some low frequency noise from the recording.
20  FilterHighPassIIR hp(sr, 6, 200.0, 0.01);
21 
22  as0 = hp.filter(as0);
23 
24  Buffer raw = as0[0];
25 
26  raw.normalize();
27  raw *= 0.5;
28 
29  AudioStream as1(sr, 2);
30 
31  as1 << raw;
32 
33  float64 raw_duration = as1.getDuration();
34 
35  // dynamic pan
36  Sine sine(sr);
37 
38  AudioStream temp = as1.getPan(sine.generate(1.0,8.0));
39 
40  temp >> "mynameis-pan.wav";
41 
42  // Create a Stretcher instance
43  Stretcher stretch(sr, 0.08, 0.25);
44 
45  stretch.showProgress(true);
46 
47  // Pitch UP
48  temp = stretch.pitchShift(as1, 1.3);
49 
50  temp >> "mynameis-high-pitch.wav";
51 
52  // Pitch DOWN
53  temp = stretch.pitchShift(as1, 0.7);
54 
55  temp >> "mynameis-low-pitch.wav";
56 
57  // Speed UP
58  temp = stretch.timeShift(as1, 0.7);
59 
60  temp >> "mynameis-faster.wav";
61 
62  // Speed DOWN
63  temp = stretch.timeShift(as1, 1.3);
64 
65  temp >> "mynameis-slower.wav";
66 
67  // wobble
68  Buffer wobble = 1.0 + 0.25 * sine.generate(1.0,5.0);
69 
70  temp = stretch.pitchShift(as1, wobble);
71 
72  temp >> "mynameis-wobble.wav";
73 
74  // ramp
75  Buffer ramp = sine.drawLine(as1.getDuration(), 0.7, 1.3);
76 
77  temp = stretch.pitchShift(as1, ramp);
78 
79  temp >> "mynameis-ramp.wav";
80 
81  // dynamic filter
82  Buffer low_freqs = sine.drawLine(1.0, 1000, 1000)
83  << sine.drawLine(raw_duration - 1.0, 1000, 20);
84 
85  Buffer high_freqs = sine.drawLine(1.0, 2000, 2000)
86  << sine.drawLine(raw_duration - 1.0, 2000, 16000);
87 
88  FilterBandPassIIR bpf(sr, 4, 1000, 2000, 0.01);
89 
90  AudioStream filtered(sr, 1);
91 
92  filtered << raw << sine.silence(0.25);
93 
94  filtered = bpf.filter(filtered, low_freqs, high_freqs);
95 
96  // There is a large click at the end of this result from the IIR high pass
97  // portion, IIR filter are not stable at every frequency.
98 
99  // Cut off the click.
100  filtered = filtered.substream(0.0f, 3.7f);
101 
102  filtered.normalize();
103  filtered *= 0.5;
104 
105  filtered >> "mynameis-filtered.wav";
106 
107  return 0;
108 }
float64 getDuration() const
Returns the number of seconds of audio data in the stream.
Definition: AudioStream.cc:183
float64 getSampleRate() const
Returns the sample rate of the stream.
Definition: AudioStream.h:217
AudioStream pitchShift(const AudioStream &x, const float64 &factor)
Definition: Stretcher.cc:338
AudioStream substream(uint32 start_index, uint32 n_samples=0) const
Definition: AudioStream.cc:825
double float64
Definition: Nsound.h:146
A class for filtering audio in the frequecy domain.
Buffer silence(const float64 &duration) const
This method generates silence.
Definition: Generator.cc:1310
void normalize()
Multiplies the AudioStream by a constant gain so the peak sample has magnitude 1.0.
Definition: AudioStream.cc:285
virtual float64 generate(const float64 &frequency)
This is a real-time method for the wavetable oscillator.
Definition: Generator.cc:972
AudioStream getPan(float64 pan) const
Sets the amplitude level left vs right.
Definition: AudioStream.h:353
void normalize()
Multiplies the Buffer by a constant gain so the peak sample has magnitude 1.0.
Definition: Buffer.cc:1064
void showProgress(boolean flag)
Definition: Stretcher.h:86
int main(void)
Definition: mynameis.cc:13
AudioStream timeShift(const AudioStream &x, const float64 &factor)
Definition: Stretcher.cc:396
A Buffer for storing audio samples.
Definition: Buffer.h:60
AudioStream filter(const AudioStream &x)
AudioStream filter(const AudioStream &x)
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