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

Go to the source code of this file.

Functions

AudioStream stretch_to (const AudioStream &x, float64 new_duration)
 
int main (void)
 

Function Documentation

AudioStream stretch_to ( const AudioStream x,
float64  new_duration 
)

Definition at line 19 of file demo-stretcher.cc.

References Nsound::AudioStream::getDuration(), Nsound::AudioStream::getSampleRate(), and Nsound::Stretcher::showProgress().

Referenced by main().

20 {
21  float64 x_dur = x.getDuration();
22 
23  float64 ratio = new_duration / x_dur;
24 
25  Stretcher st(x.getSampleRate());
26 
27  st.showProgress(true);
28 
29  return st.timeShift(x, ratio);
30 }
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
double float64
Definition: Nsound.h:146
void showProgress(boolean flag)
Definition: Stretcher.h:86
int main ( void  )

Definition at line 34 of file demo-stretcher.cc.

References Nsound::AudioStream::add(), Nsound::AudioStream::getDuration(), Nsound::AudioStream::getLength(), Nsound::AudioStream::getSampleRate(), Nsound::AudioStream::normalize(), and stretch_to().

35 {
36  AudioStream x0("california.wav");
37 
38  float64 dur = x0.getDuration();
39 
40  AudioStream x1 = stretch_to(x0, 1.15 * dur);
41  AudioStream x2 = stretch_to(x0, 1.30 * dur);
42 
43  // The longest one is x2, so add all of them to x2.
44 
45  cout
46  << "x2.getLength() = " << x2.getLength() << "\n"
47  << "x1.getLength() = " << x1.getLength() << "\n"
48  << "x0.getLength() = " << x0.getLength() << "\n";
49 
50  x2.add(x0, 1.30 * dur - dur);
51  x2.add(x1, 1.15 * dur - dur);
52 
53  for(uint32 i = 0; i < x0.getSampleRate() / 2.0; ++i)
54  {
55  x2 << 0.0;
56  }
57 
58  x2.normalize();
59  x2 *= 0.666;
60 
61  cout << "x2.getLength() = " << x2.getLength() << "\n";
62 
63  x2 >> "demo-st.wav";
64 
65  return 0;
66 }
unsigned int uint32
Definition: Nsound.h:153
uint32 getLength() const
Returns the number of samples of audio data in the stream.
Definition: AudioStream.cc:197
double float64
Definition: Nsound.h:146
AudioStream stretch_to(const AudioStream &x, float64 new_duration)
void normalize()
Multiplies the AudioStream by a constant gain so the peak sample has magnitude 1.0.
Definition: AudioStream.cc:285
void add(const AudioStream &as, uint32 offset, uint32 n_samples=0)
This method adds the passed AudioStream to this AudioStream.
Definition: AudioStream.cc:121