2010-03-24 09:44:51 +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
|
2010-03-24 09:44:51 +00:00
|
|
|
An audio time-stretching and pitch-shifting library.
|
2021-01-08 17:13:52 +00:00
|
|
|
Copyright 2007-2021 Particular Programs Ltd.
|
2012-09-09 16:57:42 +01:00
|
|
|
|
2010-03-24 09:44:51 +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.
|
2010-03-24 09:44:51 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include "CompoundAudioCurve.h"
|
|
|
|
|
|
2021-10-04 12:21:39 +01:00
|
|
|
#include "../dsp/MovingMedian.h"
|
2010-03-24 09:44:51 +00:00
|
|
|
|
|
|
|
|
#include <iostream>
|
|
|
|
|
|
|
|
|
|
namespace RubberBand
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
CompoundAudioCurve::CompoundAudioCurve(Parameters parameters) :
|
|
|
|
|
AudioCurveCalculator(parameters),
|
|
|
|
|
m_percussive(parameters),
|
|
|
|
|
m_hf(parameters),
|
|
|
|
|
m_hfFilter(new MovingMedian<double>(19, 85)),
|
|
|
|
|
m_hfDerivFilter(new MovingMedian<double>(19, 90)),
|
2011-03-19 12:41:38 +00:00
|
|
|
m_type(CompoundDetector),
|
2010-03-24 09:44:51 +00:00
|
|
|
m_lastHf(0.0),
|
|
|
|
|
m_lastResult(0.0),
|
|
|
|
|
m_risingCount(0)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CompoundAudioCurve::~CompoundAudioCurve()
|
|
|
|
|
{
|
|
|
|
|
delete m_hfFilter;
|
|
|
|
|
delete m_hfDerivFilter;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
CompoundAudioCurve::setType(Type type)
|
|
|
|
|
{
|
|
|
|
|
m_type = type;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
CompoundAudioCurve::reset()
|
|
|
|
|
{
|
|
|
|
|
m_percussive.reset();
|
|
|
|
|
m_hf.reset();
|
|
|
|
|
m_hfFilter->reset();
|
|
|
|
|
m_hfDerivFilter->reset();
|
|
|
|
|
m_lastHf = 0.0;
|
|
|
|
|
m_lastResult = 0.0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
2010-05-16 10:44:38 +01:00
|
|
|
CompoundAudioCurve::setFftSize(int newSize)
|
2010-03-24 09:44:51 +00:00
|
|
|
{
|
2010-05-16 10:44:38 +01:00
|
|
|
m_percussive.setFftSize(newSize);
|
|
|
|
|
m_hf.setFftSize(newSize);
|
|
|
|
|
m_fftSize = newSize;
|
2010-03-24 09:44:51 +00:00
|
|
|
m_lastHf = 0.0;
|
|
|
|
|
m_lastResult = 0.0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
float
|
|
|
|
|
CompoundAudioCurve::processFloat(const float *R__ mag, int increment)
|
|
|
|
|
{
|
|
|
|
|
float percussive = 0.f;
|
|
|
|
|
float hf = 0.f;
|
|
|
|
|
switch (m_type) {
|
|
|
|
|
case PercussiveDetector:
|
|
|
|
|
percussive = m_percussive.processFloat(mag, increment);
|
|
|
|
|
break;
|
|
|
|
|
case CompoundDetector:
|
|
|
|
|
percussive = m_percussive.processFloat(mag, increment);
|
|
|
|
|
hf = m_hf.processFloat(mag, increment);
|
|
|
|
|
break;
|
|
|
|
|
case SoftDetector:
|
|
|
|
|
hf = m_hf.processFloat(mag, increment);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
return processFiltering(percussive, hf);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
double
|
|
|
|
|
CompoundAudioCurve::processDouble(const double *R__ mag, int increment)
|
|
|
|
|
{
|
|
|
|
|
double percussive = 0.0;
|
|
|
|
|
double hf = 0.0;
|
|
|
|
|
switch (m_type) {
|
|
|
|
|
case PercussiveDetector:
|
|
|
|
|
percussive = m_percussive.processDouble(mag, increment);
|
|
|
|
|
break;
|
|
|
|
|
case CompoundDetector:
|
|
|
|
|
percussive = m_percussive.processDouble(mag, increment);
|
|
|
|
|
hf = m_hf.processDouble(mag, increment);
|
|
|
|
|
break;
|
|
|
|
|
case SoftDetector:
|
|
|
|
|
hf = m_hf.processDouble(mag, increment);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
return processFiltering(percussive, hf);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
double
|
|
|
|
|
CompoundAudioCurve::processFiltering(double percussive, double hf)
|
|
|
|
|
{
|
|
|
|
|
if (m_type == PercussiveDetector) {
|
2010-04-30 22:29:37 +01:00
|
|
|
return percussive;
|
2010-03-24 09:44:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
double rv = 0.f;
|
|
|
|
|
|
|
|
|
|
double hfDeriv = hf - m_lastHf;
|
|
|
|
|
|
|
|
|
|
m_hfFilter->push(hf);
|
|
|
|
|
m_hfDerivFilter->push(hfDeriv);
|
|
|
|
|
|
|
|
|
|
double hfFiltered = m_hfFilter->get();
|
|
|
|
|
double hfDerivFiltered = m_hfDerivFilter->get();
|
|
|
|
|
|
|
|
|
|
m_lastHf = hf;
|
|
|
|
|
|
|
|
|
|
double result = 0.f;
|
|
|
|
|
|
|
|
|
|
double hfExcess = hf - hfFiltered;
|
|
|
|
|
|
|
|
|
|
if (hfExcess > 0.0) {
|
|
|
|
|
result = hfDeriv - hfDerivFiltered;
|
|
|
|
|
}
|
|
|
|
|
|
2010-04-30 22:29:37 +01:00
|
|
|
if (result < m_lastResult) {
|
|
|
|
|
if (m_risingCount > 3 && m_lastResult > 0) rv = 0.5;
|
2010-03-24 09:44:51 +00:00
|
|
|
m_risingCount = 0;
|
|
|
|
|
} else {
|
2010-04-30 22:29:37 +01:00
|
|
|
m_risingCount ++;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (m_type == CompoundDetector) {
|
|
|
|
|
if (percussive > 0.35 && percussive > rv) {
|
|
|
|
|
rv = percussive;
|
2010-03-24 09:44:51 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
m_lastResult = result;
|
|
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|