2007-11-06 21:41:16 +00:00
|
|
|
/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
|
|
|
|
|
|
|
|
|
|
/*
|
2012-09-09 16:57:42 +01:00
|
|
|
Rubber Band Library
|
2007-11-06 21:41:16 +00:00
|
|
|
An audio time-stretching and pitch-shifting library.
|
2014-05-29 18:00:22 +01:00
|
|
|
Copyright 2007-2014 Particular Programs Ltd.
|
2012-09-09 16:57:42 +01:00
|
|
|
|
2007-11-06 21:41:16 +00:00
|
|
|
This program is free software; you can redistribute it and/or
|
|
|
|
|
modify it under the terms of the GNU General Public License as
|
|
|
|
|
published by the Free Software Foundation; either version 2 of the
|
|
|
|
|
License, or (at your option) any later version. See the file
|
|
|
|
|
COPYING included with this distribution for more information.
|
2012-09-09 16:57:42 +01:00
|
|
|
|
|
|
|
|
Alternatively, if you have a valid commercial licence for the
|
|
|
|
|
Rubber Band Library obtained by agreement with the copyright
|
|
|
|
|
holders, you may redistribute and/or modify it under the terms
|
|
|
|
|
described in that licence.
|
|
|
|
|
|
|
|
|
|
If you wish to distribute code using the Rubber Band Library
|
|
|
|
|
under terms other than those of the GNU General Public License,
|
|
|
|
|
you must obtain a valid commercial licence before doing so.
|
2007-11-06 21:41:16 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#ifndef _RUBBERBAND_STRETCHERCHANNELDATA_H_
|
|
|
|
|
#define _RUBBERBAND_STRETCHERCHANNELDATA_H_
|
|
|
|
|
|
|
|
|
|
#include "StretcherImpl.h"
|
|
|
|
|
|
|
|
|
|
#include <set>
|
|
|
|
|
|
2008-05-22 16:54:27 +00:00
|
|
|
//#define EXPERIMENT 1
|
|
|
|
|
|
2007-11-06 21:41:16 +00:00
|
|
|
namespace RubberBand
|
|
|
|
|
{
|
|
|
|
|
|
2010-03-24 09:44:51 +00:00
|
|
|
class Resampler;
|
|
|
|
|
|
2008-07-01 10:25:17 +00:00
|
|
|
class RubberBandStretcher::Impl::ChannelData
|
2007-11-06 21:41:16 +00:00
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
/**
|
|
|
|
|
* Construct a ChannelData structure.
|
|
|
|
|
*
|
2010-05-16 10:44:38 +01:00
|
|
|
* The sizes passed in here are for the time-domain analysis
|
|
|
|
|
* window and FFT calculation, and most of the buffer sizes also
|
|
|
|
|
* depend on them. In practice they are always powers of two, the
|
|
|
|
|
* window and FFT sizes are either equal or generally in a 2:1
|
|
|
|
|
* relationship either way, and except for very extreme stretches
|
|
|
|
|
* the FFT size is either 1024, 2048 or 4096.
|
2007-11-06 21:41:16 +00:00
|
|
|
*
|
|
|
|
|
* The outbuf size depends on other factors as well, including
|
|
|
|
|
* the pitch scale factor and any maximum processing block
|
|
|
|
|
* size specified by the user of the code.
|
|
|
|
|
*/
|
2010-05-16 10:44:38 +01:00
|
|
|
ChannelData(size_t windowSize,
|
|
|
|
|
size_t fftSize,
|
|
|
|
|
size_t outbufSize);
|
2007-11-06 21:41:16 +00:00
|
|
|
|
|
|
|
|
/**
|
2010-05-16 10:44:38 +01:00
|
|
|
* Construct a ChannelData structure that can process at different
|
|
|
|
|
* FFT sizes without requiring reallocation when the size changes.
|
|
|
|
|
* The sizes can subsequently be changed with a call to setSizes.
|
|
|
|
|
* Reallocation will only be necessary if setSizes is called with
|
|
|
|
|
* values not equal to any of those passed in to the constructor.
|
2007-11-06 21:41:16 +00:00
|
|
|
*
|
|
|
|
|
* The outbufSize should be the maximum possible outbufSize to
|
|
|
|
|
* avoid reallocation, which will happen if setOutbufSize is
|
|
|
|
|
* called subsequently.
|
|
|
|
|
*/
|
2010-05-16 10:44:38 +01:00
|
|
|
ChannelData(const std::set<size_t> &sizes,
|
|
|
|
|
size_t initialWindowSize,
|
|
|
|
|
size_t initialFftSize,
|
|
|
|
|
size_t outbufSize);
|
2007-11-06 21:41:16 +00:00
|
|
|
~ChannelData();
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Reset buffers
|
|
|
|
|
*/
|
|
|
|
|
void reset();
|
|
|
|
|
|
|
|
|
|
/**
|
2010-05-16 10:44:38 +01:00
|
|
|
* Set the FFT, analysis window, and buffer sizes. If this
|
|
|
|
|
* ChannelData was constructed with a set of sizes and the given
|
|
|
|
|
* window and FFT sizes here were among them, no reallocation will
|
|
|
|
|
* be required.
|
2007-11-06 21:41:16 +00:00
|
|
|
*/
|
2010-05-16 10:44:38 +01:00
|
|
|
void setSizes(size_t windowSize, size_t fftSizes);
|
2007-11-06 21:41:16 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Set the outbufSize for the channel data. Reallocation will
|
|
|
|
|
* occur.
|
|
|
|
|
*/
|
|
|
|
|
void setOutbufSize(size_t outbufSize);
|
|
|
|
|
|
2008-05-22 16:54:27 +00:00
|
|
|
/**
|
|
|
|
|
* Set the resampler buffer size. Default if not called is no
|
|
|
|
|
* buffer allocated at all.
|
|
|
|
|
*/
|
|
|
|
|
void setResampleBufSize(size_t resamplebufSize);
|
|
|
|
|
|
2007-11-06 21:41:16 +00:00
|
|
|
RingBuffer<float> *inbuf;
|
|
|
|
|
RingBuffer<float> *outbuf;
|
|
|
|
|
|
2011-01-07 21:46:36 +00:00
|
|
|
process_t *mag;
|
|
|
|
|
process_t *phase;
|
2007-11-06 21:41:16 +00:00
|
|
|
|
2011-01-07 21:46:36 +00:00
|
|
|
process_t *prevPhase;
|
|
|
|
|
process_t *prevError;
|
|
|
|
|
process_t *unwrappedPhase;
|
2007-11-06 21:41:16 +00:00
|
|
|
|
|
|
|
|
float *accumulator;
|
|
|
|
|
size_t accumulatorFill;
|
|
|
|
|
float *windowAccumulator;
|
2013-05-15 10:55:11 +01:00
|
|
|
float *ms; // only used when mid-side processing
|
2010-05-29 22:07:54 +01:00
|
|
|
float *interpolator; // only used when time-domain smoothing is on
|
|
|
|
|
int interpolatorScale;
|
2007-11-06 21:41:16 +00:00
|
|
|
|
|
|
|
|
float *fltbuf;
|
2011-01-07 21:46:36 +00:00
|
|
|
process_t *dblbuf; // owned by FFT object, only used for time domain FFT i/o
|
|
|
|
|
process_t *envelope; // for cepstral formant shift
|
2008-05-22 16:54:27 +00:00
|
|
|
bool unchanged;
|
2007-11-06 21:41:16 +00:00
|
|
|
|
|
|
|
|
size_t prevIncrement; // only used in RT mode
|
|
|
|
|
|
2007-11-18 21:38:18 +00:00
|
|
|
size_t chunkCount;
|
2007-11-06 21:41:16 +00:00
|
|
|
size_t inCount;
|
|
|
|
|
long inputSize; // set only after known (when data ended); -1 previously
|
|
|
|
|
size_t outCount;
|
|
|
|
|
|
|
|
|
|
bool draining;
|
|
|
|
|
bool outputComplete;
|
|
|
|
|
|
|
|
|
|
FFT *fft;
|
|
|
|
|
std::map<size_t, FFT *> ffts;
|
|
|
|
|
|
|
|
|
|
Resampler *resampler;
|
|
|
|
|
float *resamplebuf;
|
|
|
|
|
size_t resamplebufSize;
|
|
|
|
|
|
|
|
|
|
private:
|
2010-05-16 10:44:38 +01:00
|
|
|
void construct(const std::set<size_t> &sizes,
|
|
|
|
|
size_t initialWindowSize, size_t initialFftSize,
|
|
|
|
|
size_t outbufSize);
|
2007-11-06 21:41:16 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endif
|