Nsound  0.9.4
stretcher.cc
Go to the documentation of this file.
1 //-----------------------------------------------------------------------------
2 //
3 // $Id: stretcher.cc 913 2015-08-08 16:41:22Z weegreenblobbie $
4 //
5 //-----------------------------------------------------------------------------
6 
7 // Nsound headers
8 #include <Nsound/NsoundAll.h>
9 
10 // C++ header
11 #include <iostream>
12 
13 using namespace Nsound;
14 
15 using std::cout;
16 using std::endl;
17 
18 //-----------------------------------------------------------------------------
19 int
20 main(void)
21 {
22  AudioStream a("Temperature_in.wav");
23 
24  // Grab sample rate.
25  float64 sr = a.getSampleRate();
26 
27  // Create a audio playback object
28 
29  AudioPlaybackRt pb(sr, a.getNChannels());
30 
31  // Grab the duration in seconds.
32  float64 duration = a.getDuration();
33 
34  // Create a Gaussian curve for pitch/time shifting.
35  Sine sin(sr);
36 
37  Buffer bend = sin.drawFatGaussian(duration, 0.15) + 1.0;
38 
39  // Create a Stretcher instance
40  Stretcher stretch(sr, 0.08, 0.25);
41 
42  // Print progress to command line.
43  stretch.showProgress(true);
44 
45  cout << "Pitch Shifting Up" << endl;
46 
47  // Create new output AudioStream, pitch shift input AudioStream.
48  AudioStream out(sr, 2);
49 
50  out << stretch.pitchShift(a, bend);
51  out >> "Temperature_Pitch_Shifted_Up.wav";
52  out * 0.666 >> pb;
53 
54  cout << "Time Shifting Faster" << endl;
55 
56  // Time shift input AudioStream.
57  out = AudioStream(sr, 2);
58 
59  out << stretch.timeShift(a, 1.0 / bend);
60  out >> "Temperature_Time_Shifted_Faster.wav";
61  out * 0.666 >> pb;
62 
63  bend = 1.0 - 0.25 * sin.drawFatGaussian(duration, 0.15);
64 
65  cout << "Pitch Shifting Down" << endl;
66 
67  out = AudioStream(sr, 2);
68  out << stretch.pitchShift(a, bend);
69  out >> "Temperature_Pitch_Shifted_Down.wav";
70  out * 0.666 >> pb;
71 
72  cout << "Time Shifting Slower" << endl;
73 
74  bend = 1.0 + 0.75 * sin.drawFatGaussian(duration, 0.15);
75 
76  out = AudioStream(sr,2);
77  out << stretch.timeShift(a, bend);
78  out >> "Temperature_Time_Shifted_Slower.wav";
79  out * 0.666 >> pb;
80 
81  return 0;
82 }
83 
int main(void)
Definition: stretcher.cc:20
float64 getDuration() const
Returns the number of seconds of audio data in the stream.
Definition: AudioStream.cc:183
Buffer drawFatGaussian(const float64 &duration, const float64 &pass_band_percent=0.01) const
This method draws a standard Gaussian curve over duration seconds, with a specified pass band...
Definition: Generator.cc:434
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
double float64
Definition: Nsound.h:146
uint32 getNChannels(void) const
Returns the number of audio channels in the stream.
Definition: AudioStream.h:212
void showProgress(boolean flag)
Definition: Stretcher.h:86
AudioStream timeShift(const AudioStream &x, const float64 &factor)
Definition: Stretcher.cc:396
A Buffer for storing audio samples.
Definition: Buffer.h:60
DOXME.
Definition: Sine.h:43
float64 sr
Definition: example3.cc:24