46 using namespace Nsound;
56 const float64 & window_size_seconds,
57 const float64 & max_delta_window)
60 sample_rate_(sample_rate),
69 Sine sin(sample_rate);
80 sample_rate_(copy.sample_rate_),
82 window_length_(copy.window_length_),
83 max_delta_(copy.max_delta_),
84 show_progress_(copy.show_progress_)
105 if(
this == & rhs)
return *
this;
154 uint32 mod_frames = n_frames / 100;
156 if(n_frames < 100) mod_frames = n_frames;
162 printf(
"Using CUDA\n");
169 if(0 == omp_get_thread_num())
171 printf(
"Using OpenMP with %d threads\n",
172 omp_get_num_threads());
180 printf(
"Analyizing %3.0f%%", 0.0);
184 for(
uint32 j = 0; j < n_frames-1; ++j)
202 printf(
"%3.0f%%\n", 100.0);
212 uint32 search_index)
const
222 #pragma omp parallel for shared(t, min_score)
233 if(score < min_score)
250 Buffer source_fft = vec[0].getPhase();
260 Buffer test_fft = vec[0].getPhase();
262 Buffer delta = source_fft - test_fft;
268 if(score < min_score)
276 return t + search_index;
298 uint32 mod_frames = n_frames / 100;
300 if(n_frames < 100) mod_frames = n_frames;
304 printf(
"Creating output %3.0f%%", 0.0);
308 for(
uint32 i = 1; i < n_frames; ++i)
323 output.
add(next_window, i * half_length);
329 printf(
"%3.0f%%\n", 100.0);
350 return y.getResample(1.0/factor);
367 return y.getSpeedUp(factor);
Buffer subbuffer(uint32 start_index, uint32 n_samples=0) const
Slice the Buffer.
Buffer getSpeedUp(float64 step_size) const
Resamples a copy of this Buffer by the step_size, no interpolation.
float64 getSampleRate() const
Returns the sample rate of the stream.
AudioStream pitchShift(const AudioStream &x, const float64 &factor)
uint32 searchForBestMatch(const Buffer &input, uint32 source_index, uint32 search_index) const
Stretcher & operator=(const Stretcher &rhs)
Assignment.
Buffer overlapAdd(const Buffer &input) const
circular_iterator cbegin()
Retruns the itreator at the start of the Buffer.
virtual ~Stretcher()
Destructor.
Buffer drawWindowHanning(const float64 &duration) const
Draws a Hanning window.
uint32 getLength() const
Returns the number of samples in the Buffer.
uint32 getNChannels(void) const
Returns the number of audio channels in the stream.
AudioStream timeShift(const AudioStream &x, const float64 &factor)
float64 getSum() const
Returns the sum of all samples.
A Buffer for storing audio samples.
Buffer getResample(float64 factor, const uint32 N=10, float64 beta=5.0) const
Resamples a copy of this Buffer using discrete-time resampling.
AudioStream getMono() const
Collapses all channels into one Buffer making it mono.
void analyize(const Buffer &input, const float64 &factor)
Stretcher(const float64 &sample_rate, const float64 &window_size_seconds=0.08, const float64 &max_delta_window=0.25)
Default Constructor.
Buffer drawLine(const float64 &duration, const float64 &litude_start, const float64 &litude_finish) const
This method draws a linear line beteween 2 points.
void add(const Buffer &buffer, uint32 offset=0, uint32 n_samples=0)
This method adds buffer to *this.
Buffer getReverse() const
Reverses the samples in a copy of this Buffer.
std::vector< FFTChunk > FFTChunkVector