2022-05-18 17:51:20 +01:00
|
|
|
/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
Rubber Band Library
|
|
|
|
|
An audio time-stretching and pitch-shifting library.
|
|
|
|
|
Copyright 2007-2022 Particular Programs Ltd.
|
|
|
|
|
|
|
|
|
|
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.
|
|
|
|
|
|
|
|
|
|
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.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#ifndef RUBBERBAND_R3_STRETCHERIMPL_H
|
|
|
|
|
#define RUBBERBAND_R3_STRETCHERIMPL_H
|
|
|
|
|
|
|
|
|
|
#include <map>
|
|
|
|
|
#include <memory>
|
|
|
|
|
|
2022-05-19 13:34:51 +01:00
|
|
|
#include "BinSegmenter.h"
|
2022-05-19 16:31:21 +01:00
|
|
|
#include "Guide.h"
|
2022-05-19 13:34:51 +01:00
|
|
|
#include "Peak.h"
|
2022-05-20 15:29:52 +01:00
|
|
|
#include "PhaseAdvance.h"
|
2022-05-18 17:51:20 +01:00
|
|
|
|
2022-05-19 13:34:51 +01:00
|
|
|
#include "../common/FFT.h"
|
2022-05-20 15:29:52 +01:00
|
|
|
#include "../common/FixedVector.h"
|
2022-05-19 13:34:51 +01:00
|
|
|
#include "../common/Allocators.h"
|
2022-05-20 15:29:52 +01:00
|
|
|
#include "../common/Window.h"
|
2022-05-19 13:13:47 +01:00
|
|
|
|
2022-05-18 17:51:20 +01:00
|
|
|
namespace RubberBand
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
class R3StretcherImpl
|
|
|
|
|
{
|
|
|
|
|
public:
|
2022-05-19 17:28:38 +01:00
|
|
|
R3StretcherImpl(double sampleRate, int channels) :
|
|
|
|
|
m_sampleRate(sampleRate), m_channels(channels),
|
|
|
|
|
m_guide(Guide::Parameters(sampleRate)),
|
|
|
|
|
m_guideConfiguration(m_guide.getConfiguration())
|
|
|
|
|
{ }
|
2022-05-18 17:51:20 +01:00
|
|
|
~R3StretcherImpl();
|
|
|
|
|
|
|
|
|
|
void reset();
|
|
|
|
|
|
|
|
|
|
void setTimeRatio(double ratio);
|
|
|
|
|
void setPitchScale(double scale);
|
|
|
|
|
|
|
|
|
|
double getTimeRatio() const;
|
|
|
|
|
double getPitchScale() const;
|
|
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
struct ChannelScaleData {
|
|
|
|
|
int fftSize;
|
2022-05-20 15:29:52 +01:00
|
|
|
int bufSize; // size of every freq-domain array here: fftSize/2 + 1
|
|
|
|
|
FixedVector<float> mag;
|
|
|
|
|
FixedVector<float> phase;
|
|
|
|
|
FixedVector<int> nearestPeaks;
|
|
|
|
|
FixedVector<int> nearestTroughs;
|
|
|
|
|
FixedVector<float> prevOutMag;
|
|
|
|
|
FixedVector<double> prevOutPhase;
|
|
|
|
|
FixedVector<int> prevNearestPeaks;
|
|
|
|
|
FixedVector<float> timeDomainFrame;
|
|
|
|
|
Window<float> analysisWindow;
|
|
|
|
|
Window<float> synthesisWindow;
|
2022-05-18 17:51:20 +01:00
|
|
|
|
|
|
|
|
ChannelScaleData(int _fftSize) :
|
2022-05-20 15:29:52 +01:00
|
|
|
fftSize(_fftSize), bufSize(fftSize/2 + 1),
|
|
|
|
|
mag(bufSize, 0.f), phase(bufSize, 0.f),
|
|
|
|
|
nearestPeaks(bufSize, 0), nearestTroughs(bufSize, 0),
|
|
|
|
|
prevOutMag(bufSize, 0.f), prevOutPhase(bufSize, 0.f),
|
|
|
|
|
prevNearestPeaks(bufSize, 0), timeDomainFrame(fftSize, 0.f),
|
|
|
|
|
analysisWindow(HannWindow, fftSize),
|
|
|
|
|
synthesisWindow(HannWindow, fftSize/2)
|
|
|
|
|
{ }
|
2022-05-18 17:51:20 +01:00
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
ChannelScaleData(const ChannelScaleData &) =delete;
|
|
|
|
|
ChannelScaleData &operator=(const ChannelScaleData &) =delete;
|
|
|
|
|
};
|
2022-05-19 17:28:38 +01:00
|
|
|
|
2022-05-18 17:51:20 +01:00
|
|
|
struct ChannelData {
|
|
|
|
|
std::map<int, std::shared_ptr<ChannelScaleData>> scales;
|
2022-05-19 09:16:13 +01:00
|
|
|
std::unique_ptr<BinSegmenter> segmenter;
|
|
|
|
|
BinSegmenter::Segmentation segmentation;
|
|
|
|
|
BinSegmenter::Segmentation prevSegmentation;
|
|
|
|
|
BinSegmenter::Segmentation nextSegmentation;
|
2022-05-19 16:31:21 +01:00
|
|
|
Guide::Guidance guidance;
|
2022-05-20 15:29:52 +01:00
|
|
|
RingBuffer<float> inbuf;
|
|
|
|
|
RingBuffer<float> outbuf;
|
2022-05-18 17:51:20 +01:00
|
|
|
};
|
2022-05-20 15:29:52 +01:00
|
|
|
|
|
|
|
|
double m_sampleRate;
|
|
|
|
|
int m_channels;
|
|
|
|
|
|
|
|
|
|
double m_timeRatio;
|
|
|
|
|
double m_pitchScale;
|
|
|
|
|
|
|
|
|
|
std::vector<ChannelData> m_channelData;
|
2022-05-18 17:51:20 +01:00
|
|
|
std::map<int, std::shared_ptr<FFT>> m_ffts;
|
2022-05-19 17:28:38 +01:00
|
|
|
Guide m_guide;
|
|
|
|
|
Guide::Configuration m_guideConfiguration;
|
2022-05-18 17:51:20 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endif
|