|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#include "tsop.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "tsound_t.h"
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//TRop::ResampleFilterType Tau_resample_filter = Hamming3;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//---------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
typedef enum {
|
|
Toshihiro Shimizu |
890ddd |
FLT_NONE,
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
FLT_TRIANGLE, /* triangle filter */
|
|
Toshihiro Shimizu |
890ddd |
FLT_MITCHELL, /* Mitchell-Netravali filter */
|
|
Toshihiro Shimizu |
890ddd |
FLT_CUBIC_5, /* cubic convolution, a = .5 */
|
|
Toshihiro Shimizu |
890ddd |
FLT_CUBIC_75, /* cubic convolution, a = .75 */
|
|
Toshihiro Shimizu |
890ddd |
FLT_CUBIC_1, /* cubic convolution, a = 1 */
|
|
Toshihiro Shimizu |
890ddd |
FLT_HANN2, /* Hann window, rad = 2 */
|
|
Toshihiro Shimizu |
890ddd |
FLT_HANN3, /* Hann window, rad = 3 */
|
|
Toshihiro Shimizu |
890ddd |
FLT_HAMMING2, /* Hamming window, rad = 2 */
|
|
Toshihiro Shimizu |
890ddd |
FLT_HAMMING3, /* Hamming window, rad = 3 */
|
|
Toshihiro Shimizu |
890ddd |
FLT_LANCZOS2, /* Lanczos window, rad = 2 */
|
|
Toshihiro Shimizu |
890ddd |
FLT_LANCZOS3, /* Lanczos window, rad = 3 */
|
|
Toshihiro Shimizu |
890ddd |
FLT_GAUSS, /* Gaussian convolution */
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
FLT_HOW_MANY
|
|
Toshihiro Shimizu |
890ddd |
} FLT_TYPE;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//---------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
typedef enum {
|
|
Toshihiro Shimizu |
890ddd |
RESORDER_NONE,
|
|
Toshihiro Shimizu |
890ddd |
RESORDER_BITS_RATE_CHANS,
|
|
Toshihiro Shimizu |
890ddd |
RESORDER_CHANS_RATE_BITS,
|
|
Toshihiro Shimizu |
890ddd |
RESORDER_RATE_BITS_CHANS,
|
|
Toshihiro Shimizu |
890ddd |
RESORDER_CHANS_BITS_RATE,
|
|
Toshihiro Shimizu |
890ddd |
RESORDER_BITS_RATE,
|
|
Toshihiro Shimizu |
890ddd |
RESORDER_RATE_BITS,
|
|
Toshihiro Shimizu |
890ddd |
RESORDER_CHANS_RATE,
|
|
Toshihiro Shimizu |
890ddd |
RESORDER_RATE_CHANS,
|
|
Toshihiro Shimizu |
890ddd |
RESORDER_RATE,
|
|
Toshihiro Shimizu |
890ddd |
RESORDER_SIGN,
|
|
Toshihiro Shimizu |
890ddd |
RESORDER_HOW_MANY
|
|
Toshihiro Shimizu |
890ddd |
} RESORDER_TYPE;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//---------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
typedef struct
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
int src_offset; /* of weight[0] relative to start of period */
|
|
Toshihiro Shimizu |
890ddd |
int n_weights;
|
|
Toshihiro Shimizu |
890ddd |
double *weight; /* [n_weights], -1.0 <= weight <= 1.0 */
|
|
Toshihiro Shimizu |
890ddd |
} WEIGHTSET;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//---------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
typedef struct
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
int src_period; /* after a period src and dst are in step again */
|
|
Toshihiro Shimizu |
890ddd |
int dst_period;
|
|
Toshihiro Shimizu |
890ddd |
WEIGHTSET *weightset; /* [dst_period] */
|
|
Toshihiro Shimizu |
890ddd |
} FILTER;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//---------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#define M_PIF ((float)TConsts::pi)
|
|
Toshihiro Shimizu |
890ddd |
#define SINC0(x, a) (sin((TConsts::pi / (a)) * (x)) / ((TConsts::pi / (a)) * (x)))
|
|
Toshihiro Shimizu |
890ddd |
#define SINC0F(x, a) (sinf((M_PIF / (a)) * (x)) / ((M_PIF / (a)) * (x)))
|
|
Toshihiro Shimizu |
890ddd |
#define SINC(x, a) ((x) == 0.0 ? 1.0 : SINC0(x, a))
|
|
Toshihiro Shimizu |
890ddd |
#define SINCF(x, a) ((x) == 0.0F ? 1.0F : SINC0F(x, a))
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#define FULL_INT_MUL_DIV(X, Y, Z) ((int)(((double)(X) * (Y) + ((Z)-1)) / (Z)))
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//prototipi
|
|
Toshihiro Shimizu |
890ddd |
void convert(TSoundTrackP &dst, const TSoundTrackP &src);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
namespace
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//---------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void simplifyRatio(int *p_a, int *p_b)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
int a = *p_a, b = *p_b;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
while (a != b)
|
|
Toshihiro Shimizu |
890ddd |
if (a > b)
|
|
Toshihiro Shimizu |
890ddd |
a -= b;
|
|
Toshihiro Shimizu |
890ddd |
else
|
|
Toshihiro Shimizu |
890ddd |
b -= a;
|
|
Toshihiro Shimizu |
890ddd |
if (a != 1) {
|
|
Toshihiro Shimizu |
890ddd |
*p_a /= a;
|
|
Toshihiro Shimizu |
890ddd |
*p_b /= a;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//---------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
int getFilterRadius(FLT_TYPE flt_type)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
int result = 0;
|
|
Toshihiro Shimizu |
890ddd |
switch (flt_type) {
|
|
Toshihiro Shimizu |
890ddd |
case FLT_TRIANGLE:
|
|
Toshihiro Shimizu |
890ddd |
result = 1;
|
|
Toshihiro Shimizu |
890ddd |
CASE FLT_MITCHELL : result = 2;
|
|
Toshihiro Shimizu |
890ddd |
CASE FLT_CUBIC_5 : result = 2;
|
|
Toshihiro Shimizu |
890ddd |
CASE FLT_CUBIC_75 : result = 2;
|
|
Toshihiro Shimizu |
890ddd |
CASE FLT_CUBIC_1 : result = 2;
|
|
Toshihiro Shimizu |
890ddd |
CASE FLT_HANN2 : result = 2;
|
|
Toshihiro Shimizu |
890ddd |
CASE FLT_HANN3 : result = 3;
|
|
Toshihiro Shimizu |
890ddd |
CASE FLT_HAMMING2 : result = 2;
|
|
Toshihiro Shimizu |
890ddd |
CASE FLT_HAMMING3 : result = 3;
|
|
Toshihiro Shimizu |
890ddd |
CASE FLT_LANCZOS2 : result = 2;
|
|
Toshihiro Shimizu |
890ddd |
CASE FLT_LANCZOS3 : result = 3;
|
|
Toshihiro Shimizu |
890ddd |
CASE FLT_GAUSS : result = 2;
|
|
Toshihiro Shimizu |
890ddd |
DEFAULT:
|
|
Toshihiro Shimizu |
890ddd |
assert(!"bad filter type");
|
|
Toshihiro Shimizu |
890ddd |
break;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
return result;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//---------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
double filterValue(FLT_TYPE flt_type, double x)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
if (!x)
|
|
Toshihiro Shimizu |
890ddd |
return 1.0;
|
|
Toshihiro Shimizu |
890ddd |
double result;
|
|
Toshihiro Shimizu |
890ddd |
switch (flt_type) {
|
|
Toshihiro Shimizu |
890ddd |
case FLT_TRIANGLE:
|
|
Toshihiro Shimizu |
890ddd |
if (x < -1.0)
|
|
Toshihiro Shimizu |
890ddd |
result = 0.0;
|
|
Toshihiro Shimizu |
890ddd |
else if (x < 0.0)
|
|
Toshihiro Shimizu |
890ddd |
result = 1.0 + x;
|
|
Toshihiro Shimizu |
890ddd |
else if (x < 1.0)
|
|
Toshihiro Shimizu |
890ddd |
result = 1.0 - x;
|
|
Toshihiro Shimizu |
890ddd |
else
|
|
Toshihiro Shimizu |
890ddd |
result = 0.0;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
CASE FLT_MITCHELL:
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
static double p0, p2, p3, q0, q1, q2, q3;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
if (!p0) {
|
|
Toshihiro Shimizu |
890ddd |
const double b = 1.0 / 3.0;
|
|
Toshihiro Shimizu |
890ddd |
const double c = 1.0 / 3.0;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
p0 = (6.0 - 2.0 * b) / 6.0;
|
|
Toshihiro Shimizu |
890ddd |
p2 = (-18.0 + 12.0 * b + 6.0 * c) / 6.0;
|
|
Toshihiro Shimizu |
890ddd |
p3 = (12.0 - 9.0 * b - 6.0 * c) / 6.0;
|
|
Toshihiro Shimizu |
890ddd |
q0 = (8.0 * b + 24.0 * c) / 6.0;
|
|
Toshihiro Shimizu |
890ddd |
q1 = (-12.0 * b - 48.0 * c) / 6.0;
|
|
Toshihiro Shimizu |
890ddd |
q2 = (6.0 * b + 30.0 * c) / 6.0;
|
|
Toshihiro Shimizu |
890ddd |
q3 = (-b - 6.0 * c) / 6.0;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
if (x < -2.0)
|
|
Toshihiro Shimizu |
890ddd |
result = 0.0;
|
|
Toshihiro Shimizu |
890ddd |
else if (x < -1.0)
|
|
Toshihiro Shimizu |
890ddd |
result = (q0 - x * (q1 - x * (q2 - x * q3)));
|
|
Toshihiro Shimizu |
890ddd |
else if (x < 0.0)
|
|
Toshihiro Shimizu |
890ddd |
result = (p0 + x * x * (p2 - x * p3));
|
|
Toshihiro Shimizu |
890ddd |
else if (x < 1.0)
|
|
Toshihiro Shimizu |
890ddd |
result = (p0 + x * x * (p2 + x * p3));
|
|
Toshihiro Shimizu |
890ddd |
else if (x < 2.0)
|
|
Toshihiro Shimizu |
890ddd |
result = (q0 + x * (q1 + x * (q2 + x * q3)));
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
CASE FLT_CUBIC_5 : if (x < 0.0) x = -x;
|
|
Toshihiro Shimizu |
890ddd |
else if (x < 1.0) result = 2.5 * x * x * x - 3.5 * x * x + 1;
|
|
Toshihiro Shimizu |
890ddd |
else if (x < 2.0) result = 0.5 * x * x * x - 2.5 * x * x + 4 * x - 2;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
CASE FLT_CUBIC_75 : if (x < 0.0) x = -x;
|
|
Toshihiro Shimizu |
890ddd |
else if (x < 1.0) result = 2.75 * x * x * x - 3.75 * x * x + 1;
|
|
Toshihiro Shimizu |
890ddd |
else if (x < 2.0) result = 0.75 * x * x * x - 3.75 * x * x + 6 * x - 3;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
CASE FLT_CUBIC_1 : if (x < 0.0) x = -x;
|
|
Toshihiro Shimizu |
890ddd |
else if (x < 1.0) result = 3 * x * x * x - 4 * x * x + 1;
|
|
Toshihiro Shimizu |
890ddd |
else if (x < 2.0) result = x * x * x - 5 * x * x + 8 * x - 4;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
CASE FLT_HANN2 : if (x <= -2.0) result = 0.0;
|
|
Toshihiro Shimizu |
890ddd |
else if (x < 2.0) result = SINC0(x, 1) * (0.5 + 0.5 * cos((TConsts::pi_2)*x));
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
CASE FLT_HANN3 : if (x <= -3.0) result = 0.0;
|
|
Toshihiro Shimizu |
890ddd |
else if (x < 3.0) result = SINC0(x, 1) * (0.5 + 0.5 * cos((TConsts::pi / 3) * x));
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
CASE FLT_HAMMING2 : if (x <= -2.0) result = 0.0;
|
|
Toshihiro Shimizu |
890ddd |
else if (x < 2.0) result = SINC0(x, 1) * (0.54 + 0.46 * cos((TConsts::pi_2)*x));
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
CASE FLT_HAMMING3 : if (x <= -3.0) result = 0.0;
|
|
Toshihiro Shimizu |
890ddd |
else if (x < 3.0) result = SINC0(x, 1) * (0.54 + 0.46 * cos((TConsts::pi / 3) * x));
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
CASE FLT_LANCZOS2 : if (x <= -2.0) result = 0.0;
|
|
Toshihiro Shimizu |
890ddd |
else if (x < 2.0) result = SINC0(x, 1) * SINC0(x, 2);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
CASE FLT_LANCZOS3 : if (x <= -3.0) result = 0.0;
|
|
Toshihiro Shimizu |
890ddd |
else if (x < 3.0) result = SINC0(x, 1) * SINC0(x, 3);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
CASE FLT_GAUSS : if (x <= -2.0) result = 0.0;
|
|
Toshihiro Shimizu |
890ddd |
else if (x < 2.0) result = exp((-TConsts::pi) * x * x);
|
|
Toshihiro Shimizu |
890ddd |
/* exp(-M_PI*2*2)~=3.5*10^-6 */
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
DEFAULT:
|
|
Toshihiro Shimizu |
890ddd |
assert(!"bad filter type");
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
return result;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//---------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
} //namespace
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//==============================================================================
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
template <class class="" t1,="" t2=""></class>
|
|
Toshihiro Shimizu |
890ddd |
void convertSamplesT(TSoundTrackT<t1> &dst, const TSoundTrackT<t2> &src)</t2></t1>
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
const T2 *srcSample = src.samples();
|
|
Toshihiro Shimizu |
890ddd |
T1 *dstSample = dst.samples();
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
const T2 *srcEndSample = srcSample + tmin(src.getSampleCount(), dst.getSampleCount());
|
|
Toshihiro Shimizu |
890ddd |
while (srcSample < srcEndSample) {
|
|
Toshihiro Shimizu |
890ddd |
*dstSample = T1::from(*srcSample);
|
|
Toshihiro Shimizu |
890ddd |
++dstSample;
|
|
Toshihiro Shimizu |
890ddd |
++srcSample;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//==============================================================================
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
template <class t=""></class>
|
|
Toshihiro Shimizu |
890ddd |
T *resampleT(T &src, TINT32 sampleRate, FLT_TYPE flt_type)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
typedef typename T::SampleType SampleType;
|
|
Toshihiro Shimizu |
890ddd |
typedef typename T::SampleType::ChannelValueType ChannelValueType;
|
|
Toshihiro Shimizu |
890ddd |
T *dst = new TSoundTrackT<sampletype>(</sampletype>
|
|
Toshihiro Shimizu |
890ddd |
sampleRate,
|
|
Toshihiro Shimizu |
890ddd |
src.getChannelCount(),
|
|
Toshihiro Shimizu |
890ddd |
(TINT32)(src.getSampleCount() * (sampleRate / (double)src.getSampleRate())));
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
double src_rad, f, src_f0, src_to_f;
|
|
Toshihiro Shimizu |
890ddd |
double weight, weightsum;
|
|
Toshihiro Shimizu |
890ddd |
int iw, is, s0, ip, first, last;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
FILTER filter;
|
|
Toshihiro Shimizu |
890ddd |
filter.src_period = (int)src.getSampleRate();
|
|
Toshihiro Shimizu |
890ddd |
filter.dst_period = (int)dst->getSampleRate();
|
|
Toshihiro Shimizu |
890ddd |
simplifyRatio(&filter.src_period, &filter.dst_period);
|
|
Toshihiro Shimizu |
890ddd |
filter.weightset = new WEIGHTSET[filter.dst_period];
|
|
Toshihiro Shimizu |
890ddd |
if (!filter.weightset)
|
|
Toshihiro Shimizu |
890ddd |
return 0;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
int flt_rad = getFilterRadius(flt_type);
|
|
Toshihiro Shimizu |
890ddd |
double dstRate = (double)dst->getSampleRate();
|
|
Toshihiro Shimizu |
890ddd |
double srcRate = (double)src.getSampleRate();
|
|
Toshihiro Shimizu |
890ddd |
double dst_to_src = srcRate / dstRate;
|
|
Toshihiro Shimizu |
890ddd |
if (srcRate > dstRate) {
|
|
Toshihiro Shimizu |
890ddd |
src_rad = flt_rad * dst_to_src;
|
|
Toshihiro Shimizu |
890ddd |
src_to_f = dstRate / srcRate;
|
|
Toshihiro Shimizu |
890ddd |
} else {
|
|
Toshihiro Shimizu |
890ddd |
src_rad = flt_rad;
|
|
Toshihiro Shimizu |
890ddd |
src_to_f = 1.0;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
for (ip = 0; ip < filter.dst_period; ip++) {
|
|
Toshihiro Shimizu |
890ddd |
src_f0 = ip * dst_to_src;
|
|
Toshihiro Shimizu |
890ddd |
if (ip == 0 && srcRate < dstRate)
|
|
Toshihiro Shimizu |
890ddd |
first = last = 0;
|
|
Toshihiro Shimizu |
890ddd |
else {
|
|
Toshihiro Shimizu |
890ddd |
first = intGT(src_f0 - src_rad);
|
|
Toshihiro Shimizu |
890ddd |
last = intLT(src_f0 + src_rad);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
filter.weightset[ip].src_offset = first;
|
|
Toshihiro Shimizu |
890ddd |
filter.weightset[ip].n_weights = last - first + 1;
|
|
Toshihiro Shimizu |
890ddd |
filter.weightset[ip].weight = new double[filter.weightset[ip].n_weights];
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
if (!filter.weightset[ip].weight)
|
|
Toshihiro Shimizu |
890ddd |
return 0;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
weightsum = 0.0;
|
|
Toshihiro Shimizu |
890ddd |
for (is = first; is <= last; is++) {
|
|
Toshihiro Shimizu |
890ddd |
f = (is - src_f0) * src_to_f;
|
|
Toshihiro Shimizu |
890ddd |
weight = filterValue(flt_type, f);
|
|
Toshihiro Shimizu |
890ddd |
filter.weightset[ip].weight[is - first] = weight;
|
|
Toshihiro Shimizu |
890ddd |
weightsum += weight;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
assert(weightsum);
|
|
Toshihiro Shimizu |
890ddd |
for (is = first; is <= last; is++)
|
|
Toshihiro Shimizu |
890ddd |
filter.weightset[ip].weight[is - first] /= weightsum;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
ip = 0;
|
|
Toshihiro Shimizu |
890ddd |
s0 = 0;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
for (TINT32 id = 0; id < dst->getSampleCount(); id++) {
|
|
Toshihiro Shimizu |
890ddd |
SampleType dstSample;
|
|
Toshihiro Shimizu |
890ddd |
SampleType srcSample;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
is = s0 + filter.weightset[ip].src_offset;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
int iwFirst, iwLast;
|
|
Toshihiro Shimizu |
890ddd |
if (is > 0) {
|
|
Toshihiro Shimizu |
890ddd |
iwFirst = 0;
|
|
Toshihiro Shimizu |
890ddd |
iwLast = tmin<int>(filter.weightset[ip].n_weights, src.getSampleCount() - is);</int>
|
|
Toshihiro Shimizu |
890ddd |
} else {
|
|
Toshihiro Shimizu |
890ddd |
iwFirst = -is;
|
|
Toshihiro Shimizu |
890ddd |
is = 0;
|
|
Toshihiro Shimizu |
890ddd |
iwLast = tmin<int>(filter.weightset[ip].n_weights, src.getSampleCount());</int>
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
double dstChannel[2];
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
dstChannel[0] = 0;
|
|
Toshihiro Shimizu |
890ddd |
dstChannel[1] = 0;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
dstSample = SampleType();
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
for (iw = iwFirst; iw < iwLast; iw++, is++) {
|
|
Toshihiro Shimizu |
890ddd |
weight = filter.weightset[ip].weight[iw];
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
srcSample = *(src.samples() + is);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
/*
|
|
Toshihiro Shimizu |
890ddd |
T::SampleType tmp = srcSample*weight;
|
|
Toshihiro Shimizu |
890ddd |
dstSample += tmp;
|
|
Toshihiro Shimizu |
890ddd |
*/
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
for (int i = 0; i < src.getChannelCount(); i++)
|
|
Toshihiro Shimizu |
890ddd |
dstChannel[i] += (double)(srcSample.getValue(i) * weight);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//assert(dstSample.getValue(0) == dstChannel[0]);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
for (int i = 0; i < src.getChannelCount(); i++)
|
|
Toshihiro Shimizu |
890ddd |
dstSample.setValue(i, (ChannelValueType)(tround(dstChannel[i])));
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
*(dst->samples() + id) = dstSample;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
ip++;
|
|
Toshihiro Shimizu |
890ddd |
if (ip == filter.dst_period) {
|
|
Toshihiro Shimizu |
890ddd |
ip = 0;
|
|
Toshihiro Shimizu |
890ddd |
s0 += filter.src_period;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
for (ip = 0; ip < filter.dst_period; ip++)
|
|
Toshihiro Shimizu |
890ddd |
delete[] filter.weightset[ip].weight;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
delete[] filter.weightset;
|
|
Toshihiro Shimizu |
890ddd |
return dst;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//=============================================================================
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
class TSoundTrackResample : public TSoundTransform
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
TINT32 m_sampleRate;
|
|
Toshihiro Shimizu |
890ddd |
FLT_TYPE m_filterType;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
public:
|
|
Toshihiro Shimizu |
890ddd |
TSoundTrackResample(TINT32 sampleRate, FLT_TYPE filterType)
|
|
Toshihiro Shimizu |
890ddd |
: TSoundTransform(), m_sampleRate(sampleRate), m_filterType(filterType)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
~TSoundTrackResample(){};
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TSoundTrackP compute(const TSoundTrackMono8Signed &src)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
TSoundTrackMono8Signed *dst = resampleT(
|
|
Toshihiro Shimizu |
890ddd |
const_cast<tsoundtrackmono8signed &="">(src),</tsoundtrackmono8signed>
|
|
Toshihiro Shimizu |
890ddd |
m_sampleRate, m_filterType);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
return TSoundTrackP(dst);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TSoundTrackP compute(const TSoundTrackMono8Unsigned &src)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TSoundTrackMono8Unsigned *dst = resampleT(
|
|
Toshihiro Shimizu |
890ddd |
const_cast<tsoundtrackmono8unsigned &="">(src),</tsoundtrackmono8unsigned>
|
|
Toshihiro Shimizu |
890ddd |
m_sampleRate, m_filterType);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
return TSoundTrackP(dst);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TSoundTrackP compute(const TSoundTrackStereo8Signed &src)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
TSoundTrackStereo8Signed *dst = resampleT(
|
|
Toshihiro Shimizu |
890ddd |
const_cast<tsoundtrackstereo8signed &="">(src),</tsoundtrackstereo8signed>
|
|
Toshihiro Shimizu |
890ddd |
m_sampleRate, m_filterType);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
return TSoundTrackP(dst);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TSoundTrackP compute(const TSoundTrackStereo8Unsigned &src)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
TSoundTrackStereo8Unsigned *dst = resampleT(
|
|
Toshihiro Shimizu |
890ddd |
const_cast<tsoundtrackstereo8unsigned &="">(src),</tsoundtrackstereo8unsigned>
|
|
Toshihiro Shimizu |
890ddd |
m_sampleRate, m_filterType);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
return TSoundTrackP(dst);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TSoundTrackP compute(const TSoundTrackMono16 &src)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
TSoundTrackMono16 *dst = resampleT(
|
|
Toshihiro Shimizu |
890ddd |
const_cast<tsoundtrackmono16 &="">(src),</tsoundtrackmono16>
|
|
Toshihiro Shimizu |
890ddd |
m_sampleRate, m_filterType);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
return TSoundTrackP(dst);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TSoundTrackP compute(const TSoundTrackStereo16 &src)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
TSoundTrackStereo16 *dst = resampleT(
|
|
Toshihiro Shimizu |
890ddd |
const_cast<tsoundtrackstereo16 &="">(src),</tsoundtrackstereo16>
|
|
Toshihiro Shimizu |
890ddd |
m_sampleRate, m_filterType);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
return TSoundTrackP(dst);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TSoundTrackP compute(const TSoundTrackMono24 &src)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
TSoundTrackMono24 *dst = resampleT(
|
|
Toshihiro Shimizu |
890ddd |
const_cast<tsoundtrackmono24 &="">(src),</tsoundtrackmono24>
|
|
Toshihiro Shimizu |
890ddd |
m_sampleRate, m_filterType);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
return TSoundTrackP(dst);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TSoundTrackP compute(const TSoundTrackStereo24 &src)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
TSoundTrackStereo24 *dst = resampleT(
|
|
Toshihiro Shimizu |
890ddd |
const_cast<tsoundtrackstereo24 &="">(src),</tsoundtrackstereo24>
|
|
Toshihiro Shimizu |
890ddd |
m_sampleRate, m_filterType);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
return TSoundTrackP(dst);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
};
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//==============================================================================
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TSoundTrackP TSop::resample(TSoundTrackP src, TINT32 sampleRate)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
TSoundTrackResample *resample = new TSoundTrackResample(sampleRate, FLT_HAMMING3);
|
|
Toshihiro Shimizu |
890ddd |
TSoundTrackP dst = src->apply(resample);
|
|
Toshihiro Shimizu |
890ddd |
delete resample;
|
|
Toshihiro Shimizu |
890ddd |
return dst;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//==============================================================================
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
template <class src=""></class>
|
|
Toshihiro Shimizu |
890ddd |
TSoundTrackP doConvertWithoutResamplingT(
|
|
Toshihiro Shimizu |
890ddd |
SRC *src, const TSoundTrackFormat &dstFormat)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
TSoundTrackP dst = TSoundTrack::create(dstFormat, src->getSampleCount());
|
|
Toshihiro Shimizu |
890ddd |
if (!dst)
|
|
Toshihiro Shimizu |
890ddd |
return 0;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TSoundTrackMono8Unsigned *dstM8U =
|
|
Toshihiro Shimizu |
890ddd |
dynamic_cast<tsoundtrackmono8unsigned *="">(dst.getPointer());</tsoundtrackmono8unsigned>
|
|
Toshihiro Shimizu |
890ddd |
if (dstM8U) {
|
|
Toshihiro Shimizu |
890ddd |
convertSamplesT(*dstM8U, *src);
|
|
Toshihiro Shimizu |
890ddd |
return dstM8U;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TSoundTrackMono8Signed *dstM8S =
|
|
Toshihiro Shimizu |
890ddd |
dynamic_cast<tsoundtrackmono8signed *="">(dst.getPointer());</tsoundtrackmono8signed>
|
|
Toshihiro Shimizu |
890ddd |
if (dstM8S) {
|
|
Toshihiro Shimizu |
890ddd |
convertSamplesT(*dstM8S, *src);
|
|
Toshihiro Shimizu |
890ddd |
return dstM8S;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TSoundTrackStereo8Signed *dstS8S =
|
|
Toshihiro Shimizu |
890ddd |
dynamic_cast<tsoundtrackstereo8signed *="">(dst.getPointer());</tsoundtrackstereo8signed>
|
|
Toshihiro Shimizu |
890ddd |
if (dstS8S) {
|
|
Toshihiro Shimizu |
890ddd |
convertSamplesT(*dstS8S, *src);
|
|
Toshihiro Shimizu |
890ddd |
return dstS8S;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TSoundTrackStereo8Unsigned *dstS8U =
|
|
Toshihiro Shimizu |
890ddd |
dynamic_cast<tsoundtrackstereo8unsigned *="">(dst.getPointer());</tsoundtrackstereo8unsigned>
|
|
Toshihiro Shimizu |
890ddd |
if (dstS8U) {
|
|
Toshihiro Shimizu |
890ddd |
convertSamplesT(*dstS8U, *src);
|
|
Toshihiro Shimizu |
890ddd |
return dstS8U;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TSoundTrackMono16 *dstM16 =
|
|
Toshihiro Shimizu |
890ddd |
dynamic_cast<tsoundtrackmono16 *="">(dst.getPointer());</tsoundtrackmono16>
|
|
Toshihiro Shimizu |
890ddd |
if (dstM16) {
|
|
Toshihiro Shimizu |
890ddd |
convertSamplesT(*dstM16, *src);
|
|
Toshihiro Shimizu |
890ddd |
return dstM16;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TSoundTrackStereo16 *dstS16 =
|
|
Toshihiro Shimizu |
890ddd |
dynamic_cast<tsoundtrackstereo16 *="">(dst.getPointer());</tsoundtrackstereo16>
|
|
Toshihiro Shimizu |
890ddd |
if (dstS16) {
|
|
Toshihiro Shimizu |
890ddd |
convertSamplesT(*dstS16, *src);
|
|
Toshihiro Shimizu |
890ddd |
return dstS16;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TSoundTrackMono24 *dstM24 =
|
|
Toshihiro Shimizu |
890ddd |
dynamic_cast<tsoundtrackmono24 *="">(dst.getPointer());</tsoundtrackmono24>
|
|
Toshihiro Shimizu |
890ddd |
if (dstM24) {
|
|
Toshihiro Shimizu |
890ddd |
convertSamplesT(*dstM24, *src);
|
|
Toshihiro Shimizu |
890ddd |
return dstM24;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TSoundTrackStereo24 *dstS24 =
|
|
Toshihiro Shimizu |
890ddd |
dynamic_cast<tsoundtrackstereo24 *="">(dst.getPointer());</tsoundtrackstereo24>
|
|
Toshihiro Shimizu |
890ddd |
if (dstS24) {
|
|
Toshihiro Shimizu |
890ddd |
convertSamplesT(*dstS24, *src);
|
|
Toshihiro Shimizu |
890ddd |
return dstS24;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
return 0;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//------------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
class TSoundTrackConverterWithoutResampling : public TSoundTransform
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TSoundTrackFormat m_format;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
public:
|
|
Toshihiro Shimizu |
890ddd |
TSoundTrackConverterWithoutResampling(const TSoundTrackFormat &format)
|
|
Toshihiro Shimizu |
890ddd |
: m_format(format) {}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
~TSoundTrackConverterWithoutResampling(){};
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TSoundTrackP compute(const TSoundTrackMono8Signed &src)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
return doConvertWithoutResamplingT(&src, m_format);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TSoundTrackP compute(const TSoundTrackMono8Unsigned &src)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
return doConvertWithoutResamplingT(&src, m_format);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TSoundTrackP compute(const TSoundTrackStereo8Signed &src)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
return doConvertWithoutResamplingT(&src, m_format);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TSoundTrackP compute(const TSoundTrackStereo8Unsigned &src)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
return doConvertWithoutResamplingT(&src, m_format);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TSoundTrackP compute(const TSoundTrackMono16 &src)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
return doConvertWithoutResamplingT(&src, m_format);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TSoundTrackP compute(const TSoundTrackStereo16 &src)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
return doConvertWithoutResamplingT(&src, m_format);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
TSoundTrackP compute(const TSoundTrackMono24 &src)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
return doConvertWithoutResamplingT(&src, m_format);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TSoundTrackP compute(const TSoundTrackStereo24 &src)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
return doConvertWithoutResamplingT(&src, m_format);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
};
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
namespace
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void convertWithoutResampling(TSoundTrackP &dst, const TSoundTrackP &src)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
TSoundTrackConverterWithoutResampling *converter;
|
|
Toshihiro Shimizu |
890ddd |
converter = new TSoundTrackConverterWithoutResampling(dst->getFormat());
|
|
Toshihiro Shimizu |
890ddd |
dst = src->apply(converter);
|
|
Toshihiro Shimizu |
890ddd |
delete converter;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
} // namespace
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//==============================================================================
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TSoundTrackP TSop::convert(
|
|
Toshihiro Shimizu |
890ddd |
const TSoundTrackP &src,
|
|
Toshihiro Shimizu |
890ddd |
const TSoundTrackFormat &dstFormat)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
TINT32 dstSampleCount =
|
|
Toshihiro Shimizu |
890ddd |
(TINT32)(src->getSampleCount() * (dstFormat.m_sampleRate / (double)src->getSampleRate()));
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TSoundTrackP dst = TSoundTrack::create(dstFormat, dstSampleCount);
|
|
Toshihiro Shimizu |
890ddd |
TSop::convert(dst, src);
|
|
Toshihiro Shimizu |
890ddd |
return dst;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//------------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void TSop::convert(TSoundTrackP &dst, const TSoundTrackP &src)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
int src_reslen, dst_reslen;
|
|
Toshihiro Shimizu |
890ddd |
int src_bits, dst_bits;
|
|
Toshihiro Shimizu |
890ddd |
int src_chans, dst_chans;
|
|
Toshihiro Shimizu |
890ddd |
TSoundTrackP tmp, tmq;
|
|
Toshihiro Shimizu |
890ddd |
RESORDER_TYPE order;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
assert(src->getSampleCount() >= 0 && dst->getSampleCount() >= 0);
|
|
Toshihiro Shimizu |
890ddd |
if (!dst->getSampleCount())
|
|
Toshihiro Shimizu |
890ddd |
return;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
if (!src->getSampleCount()) {
|
|
Toshihiro Shimizu |
890ddd |
dst->blank(0L, (TINT32)(dst->getSampleCount() - 1));
|
|
Toshihiro Shimizu |
890ddd |
return;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
if (src->getSampleRate() == dst->getSampleRate()) {
|
|
Toshihiro Shimizu |
890ddd |
src_reslen = dst->getSampleCount();
|
|
Toshihiro Shimizu |
890ddd |
notMoreThan((int)src->getSampleCount(), src_reslen);
|
|
Toshihiro Shimizu |
890ddd |
dst_reslen = src_reslen;
|
|
Toshihiro Shimizu |
890ddd |
convertWithoutResampling(dst, src);
|
|
Toshihiro Shimizu |
890ddd |
} else {
|
|
Toshihiro Shimizu |
890ddd |
src_reslen = FULL_INT_MUL_DIV(
|
|
Toshihiro Shimizu |
890ddd |
dst->getSampleCount(),
|
|
Toshihiro Shimizu |
890ddd |
src->getSampleRate(),
|
|
Toshihiro Shimizu |
890ddd |
dst->getSampleRate());
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
if (src_reslen > src->getSampleCount()) {
|
|
Toshihiro Shimizu |
890ddd |
src_reslen = src->getSampleCount();
|
|
Toshihiro Shimizu |
890ddd |
dst_reslen = FULL_INT_MUL_DIV(
|
|
Toshihiro Shimizu |
890ddd |
src_reslen, dst->getSampleRate(), src->getSampleRate());
|
|
Toshihiro Shimizu |
890ddd |
} else
|
|
Toshihiro Shimizu |
890ddd |
dst_reslen = dst->getSampleCount();
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
src_chans = src->getChannelCount();
|
|
Toshihiro Shimizu |
890ddd |
dst_chans = dst->getChannelCount();
|
|
Toshihiro Shimizu |
890ddd |
src_bits = src->getBitPerSample();
|
|
Toshihiro Shimizu |
890ddd |
dst_bits = dst->getBitPerSample();
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
if (src_chans == dst_chans && src_bits == dst_bits)
|
|
Toshihiro Shimizu |
890ddd |
if (src->isSampleSigned() == dst->isSampleSigned())
|
|
Toshihiro Shimizu |
890ddd |
order = RESORDER_RATE;
|
|
Toshihiro Shimizu |
890ddd |
else
|
|
Toshihiro Shimizu |
890ddd |
order = RESORDER_SIGN;
|
|
Toshihiro Shimizu |
890ddd |
else if (src_chans < dst_chans) {
|
|
Toshihiro Shimizu |
890ddd |
if (src_bits < dst_bits)
|
|
Toshihiro Shimizu |
890ddd |
order = RESORDER_BITS_RATE_CHANS;
|
|
Toshihiro Shimizu |
890ddd |
else
|
|
Toshihiro Shimizu |
890ddd |
order = RESORDER_RATE_BITS_CHANS;
|
|
Toshihiro Shimizu |
890ddd |
} else if (src_chans > dst_chans) {
|
|
Toshihiro Shimizu |
890ddd |
if (src_bits > dst_bits)
|
|
Toshihiro Shimizu |
890ddd |
order = RESORDER_CHANS_RATE_BITS;
|
|
Toshihiro Shimizu |
890ddd |
else
|
|
Toshihiro Shimizu |
890ddd |
order = RESORDER_CHANS_BITS_RATE;
|
|
Toshihiro Shimizu |
890ddd |
} else {
|
|
Toshihiro Shimizu |
890ddd |
if (src_bits > dst_bits)
|
|
Toshihiro Shimizu |
890ddd |
order = RESORDER_RATE_BITS;
|
|
Toshihiro Shimizu |
890ddd |
else
|
|
Toshihiro Shimizu |
890ddd |
order = RESORDER_BITS_RATE;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
switch (order) {
|
|
Toshihiro Shimizu |
890ddd |
case RESORDER_CHANS_RATE_BITS:
|
|
Toshihiro Shimizu |
890ddd |
case RESORDER_BITS_RATE_CHANS:
|
|
Toshihiro Shimizu |
890ddd |
int chans, bitPerSample;
|
|
Toshihiro Shimizu |
890ddd |
if (src->getChannelCount() <= dst->getChannelCount())
|
|
Toshihiro Shimizu |
890ddd |
chans = src->getChannelCount();
|
|
Toshihiro Shimizu |
890ddd |
else
|
|
Toshihiro Shimizu |
890ddd |
chans = dst->getChannelCount();
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
if (src->getBitPerSample() >= dst->getBitPerSample())
|
|
Toshihiro Shimizu |
890ddd |
bitPerSample = src->getBitPerSample();
|
|
Toshihiro Shimizu |
890ddd |
else
|
|
Toshihiro Shimizu |
890ddd |
bitPerSample = dst->getBitPerSample();
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
tmp = TSoundTrack::create(
|
|
Toshihiro Shimizu |
890ddd |
(int)src->getSampleRate(),
|
|
Toshihiro Shimizu |
890ddd |
bitPerSample,
|
|
Toshihiro Shimizu |
890ddd |
chans,
|
|
Toshihiro Shimizu |
890ddd |
src_reslen * src->getSampleSize());
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
convertWithoutResampling(tmp, src);
|
|
Toshihiro Shimizu |
890ddd |
tmq = TSop::resample(tmp, (TINT32)dst->getSampleRate());
|
|
Toshihiro Shimizu |
890ddd |
convertWithoutResampling(dst, tmq);
|
|
Toshihiro Shimizu |
890ddd |
break;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
case RESORDER_RATE_BITS_CHANS:
|
|
Toshihiro Shimizu |
890ddd |
case RESORDER_RATE_BITS:
|
|
Toshihiro Shimizu |
890ddd |
case RESORDER_RATE_CHANS:
|
|
Toshihiro Shimizu |
890ddd |
tmp = TSop::resample(src, (TINT32)dst->getSampleRate());
|
|
Toshihiro Shimizu |
890ddd |
convertWithoutResampling(dst, tmp);
|
|
Toshihiro Shimizu |
890ddd |
break;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
case RESORDER_CHANS_BITS_RATE:
|
|
Toshihiro Shimizu |
890ddd |
case RESORDER_BITS_RATE:
|
|
Toshihiro Shimizu |
890ddd |
case RESORDER_CHANS_RATE:
|
|
Toshihiro Shimizu |
890ddd |
case RESORDER_SIGN:
|
|
Toshihiro Shimizu |
890ddd |
tmp = TSoundTrack::create(
|
|
Toshihiro Shimizu |
890ddd |
(int)src->getSampleRate(),
|
|
Toshihiro Shimizu |
890ddd |
dst->getBitPerSample(),
|
|
Toshihiro Shimizu |
890ddd |
dst->getChannelCount(),
|
|
Toshihiro Shimizu |
890ddd |
src_reslen * dst->getSampleSize(),
|
|
Toshihiro Shimizu |
890ddd |
dst->isSampleSigned());
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
convertWithoutResampling(tmp, src);
|
|
Toshihiro Shimizu |
890ddd |
dst = TSop::resample(tmp, (TINT32)dst->getSampleRate());
|
|
Toshihiro Shimizu |
890ddd |
break;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
case RESORDER_RATE:
|
|
Toshihiro Shimizu |
890ddd |
dst = TSop::resample(src, (TINT32)dst->getSampleRate());
|
|
Toshihiro Shimizu |
890ddd |
break;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
default:
|
|
Toshihiro Shimizu |
890ddd |
assert(false);
|
|
Toshihiro Shimizu |
890ddd |
break;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
if (dst_reslen < dst->getSampleCount())
|
|
Toshihiro Shimizu |
890ddd |
dst->blank((TINT32)dst_reslen, (TINT32)(dst->getSampleCount() - 1));
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//==============================================================================
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
template <class t=""></class>
|
|
Toshihiro Shimizu |
890ddd |
TSoundTrackP doReverb(
|
|
Toshihiro Shimizu |
890ddd |
TSoundTrackT<t> *src,</t>
|
|
Toshihiro Shimizu |
890ddd |
double delayTime,
|
|
Toshihiro Shimizu |
890ddd |
double decayFactor,
|
|
Toshihiro Shimizu |
890ddd |
double extendTime)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
TINT32 dstSampleCount = src->getSampleCount() + (TINT32)(src->getSampleRate() * extendTime);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TSoundTrackT<t> *dst = new TSoundTrackT<t>(</t></t>
|
|
Toshihiro Shimizu |
890ddd |
src->getSampleRate(),
|
|
Toshihiro Shimizu |
890ddd |
src->getChannelCount(),
|
|
Toshihiro Shimizu |
890ddd |
dstSampleCount);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TINT32 sampleRate = (TINT32)src->getSampleRate();
|
|
Toshihiro Shimizu |
890ddd |
TINT32 k = (TINT32)(sampleRate * delayTime);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
T *srcSample = src->samples();
|
|
Toshihiro Shimizu |
890ddd |
T *dstSample = dst->samples();
|
|
Toshihiro Shimizu |
890ddd |
T *endDstSample = dst->samples() + k;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
while (dstSample < endDstSample)
|
|
Toshihiro Shimizu |
890ddd |
*dstSample++ = *srcSample++;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
// la formula del reverb e'
|
|
Toshihiro Shimizu |
890ddd |
// out(i) = in(i) + decayFactor * out(i - k)
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
// int channelCount = src->getChannelCount();
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
endDstSample = dst->samples() + tmin(dstSampleCount, (TINT32)src->getSampleCount());
|
|
Toshihiro Shimizu |
890ddd |
while (dstSample < endDstSample) {
|
|
Toshihiro Shimizu |
890ddd |
//*dstSample = *srcSample + *(dstSample - k)*decayFactor;
|
|
Toshihiro Shimizu |
890ddd |
*dstSample = T::mix(*srcSample, 1, *(dstSample - k), decayFactor);
|
|
Toshihiro Shimizu |
890ddd |
++dstSample;
|
|
Toshihiro Shimizu |
890ddd |
++srcSample;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
endDstSample = dst->samples() + dstSampleCount;
|
|
Toshihiro Shimizu |
890ddd |
while (dstSample < endDstSample) {
|
|
Toshihiro Shimizu |
890ddd |
//*dstSample = *(dstSample - k)*decayFactor;
|
|
Toshihiro Shimizu |
890ddd |
*dstSample = T::mix(T(), 0, *(dstSample - k), decayFactor);
|
|
Toshihiro Shimizu |
890ddd |
++dstSample;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
return TSoundTrackP(dst);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//==============================================================================
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
class TSoundReverb : public TSoundTransform
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
double m_delayTime;
|
|
Toshihiro Shimizu |
890ddd |
double m_decayFactor;
|
|
Toshihiro Shimizu |
890ddd |
double m_extendTime;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
public:
|
|
Toshihiro Shimizu |
890ddd |
TSoundReverb(
|
|
Toshihiro Shimizu |
890ddd |
double delayTime,
|
|
Toshihiro Shimizu |
890ddd |
double decayFactor,
|
|
Toshihiro Shimizu |
890ddd |
double extendTime)
|
|
Toshihiro Shimizu |
890ddd |
: m_delayTime(delayTime), m_decayFactor(decayFactor), m_extendTime(extendTime)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
~TSoundReverb() {}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
virtual TSoundTrackP compute(const TSoundTrackMono8Signed &src)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
return doReverb(
|
|
Toshihiro Shimizu |
890ddd |
const_cast<tsoundtrackmono8signed *="">(&src),</tsoundtrackmono8signed>
|
|
Toshihiro Shimizu |
890ddd |
m_delayTime,
|
|
Toshihiro Shimizu |
890ddd |
m_decayFactor,
|
|
Toshihiro Shimizu |
890ddd |
m_extendTime);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
virtual TSoundTrackP compute(const TSoundTrackMono8Unsigned &src)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
return doReverb(
|
|
Toshihiro Shimizu |
890ddd |
const_cast<tsoundtrackmono8unsigned *="">(&src),</tsoundtrackmono8unsigned>
|
|
Toshihiro Shimizu |
890ddd |
m_delayTime,
|
|
Toshihiro Shimizu |
890ddd |
m_decayFactor,
|
|
Toshihiro Shimizu |
890ddd |
m_extendTime);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
virtual TSoundTrackP compute(const TSoundTrackStereo8Signed &src)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
return doReverb(
|
|
Toshihiro Shimizu |
890ddd |
const_cast<tsoundtrackstereo8signed *="">(&src),</tsoundtrackstereo8signed>
|
|
Toshihiro Shimizu |
890ddd |
m_delayTime,
|
|
Toshihiro Shimizu |
890ddd |
m_decayFactor,
|
|
Toshihiro Shimizu |
890ddd |
m_extendTime);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
virtual TSoundTrackP compute(const TSoundTrackStereo8Unsigned &src)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
return doReverb(
|
|
Toshihiro Shimizu |
890ddd |
const_cast<tsoundtrackstereo8unsigned *="">(&src),</tsoundtrackstereo8unsigned>
|
|
Toshihiro Shimizu |
890ddd |
m_delayTime,
|
|
Toshihiro Shimizu |
890ddd |
m_decayFactor,
|
|
Toshihiro Shimizu |
890ddd |
m_extendTime);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
virtual TSoundTrackP compute(const TSoundTrackMono16 &src)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
return doReverb(
|
|
Toshihiro Shimizu |
890ddd |
const_cast<tsoundtrackmono16 *="">(&src),</tsoundtrackmono16>
|
|
Toshihiro Shimizu |
890ddd |
m_delayTime,
|
|
Toshihiro Shimizu |
890ddd |
m_decayFactor,
|
|
Toshihiro Shimizu |
890ddd |
m_extendTime);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
virtual TSoundTrackP compute(const TSoundTrackStereo16 &src)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
return doReverb(
|
|
Toshihiro Shimizu |
890ddd |
const_cast<tsoundtrackstereo16 *="">(&src),</tsoundtrackstereo16>
|
|
Toshihiro Shimizu |
890ddd |
m_delayTime,
|
|
Toshihiro Shimizu |
890ddd |
m_decayFactor,
|
|
Toshihiro Shimizu |
890ddd |
m_extendTime);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
virtual TSoundTrackP compute(const TSoundTrackMono24 &src)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
return doReverb(
|
|
Toshihiro Shimizu |
890ddd |
const_cast<tsoundtrackmono24 *="">(&src),</tsoundtrackmono24>
|
|
Toshihiro Shimizu |
890ddd |
m_delayTime,
|
|
Toshihiro Shimizu |
890ddd |
m_decayFactor,
|
|
Toshihiro Shimizu |
890ddd |
m_extendTime);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
virtual TSoundTrackP compute(const TSoundTrackStereo24 &src)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
return doReverb(
|
|
Toshihiro Shimizu |
890ddd |
const_cast<tsoundtrackstereo24 *="">(&src),</tsoundtrackstereo24>
|
|
Toshihiro Shimizu |
890ddd |
m_delayTime,
|
|
Toshihiro Shimizu |
890ddd |
m_decayFactor,
|
|
Toshihiro Shimizu |
890ddd |
m_extendTime);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
};
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//==============================================================================
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TSoundTrackP TSop::reverb(
|
|
Toshihiro Shimizu |
890ddd |
TSoundTrackP src,
|
|
Toshihiro Shimizu |
890ddd |
double delayTime,
|
|
Toshihiro Shimizu |
890ddd |
double decayFactor,
|
|
Toshihiro Shimizu |
890ddd |
double extendTime)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
TSoundReverb *reverb = new TSoundReverb(delayTime, decayFactor, extendTime);
|
|
Toshihiro Shimizu |
890ddd |
assert(reverb);
|
|
Toshihiro Shimizu |
890ddd |
if (!reverb)
|
|
Toshihiro Shimizu |
890ddd |
return TSoundTrackP();
|
|
Toshihiro Shimizu |
890ddd |
TSoundTrackP dst = src->apply(reverb);
|
|
Toshihiro Shimizu |
890ddd |
delete reverb;
|
|
Toshihiro Shimizu |
890ddd |
return dst;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//==============================================================================
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
template <class t=""></class>
|
|
Toshihiro Shimizu |
890ddd |
TSoundTrackP doGate(
|
|
Toshihiro Shimizu |
890ddd |
TSoundTrackT<t> *src,</t>
|
|
Toshihiro Shimizu |
890ddd |
double threshold,
|
|
Toshihiro Shimizu |
890ddd |
double holdTime,
|
|
Toshihiro Shimizu |
890ddd |
double /*releaseTime*/)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TSoundTrackT<t> *dst = new TSoundTrackT<t>(</t></t>
|
|
Toshihiro Shimizu |
890ddd |
src->getSampleRate(),
|
|
Toshihiro Shimizu |
890ddd |
src->getChannelCount(),
|
|
Toshihiro Shimizu |
890ddd |
src->getSampleCount());
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
double sampleExcursion_inv =
|
|
Toshihiro Shimizu |
890ddd |
1.0 / (double)(src->getMaxPressure(0, src->getSampleCount() - 1, 0) - src->getMinPressure(0, src->getSampleCount() - 1, 0));
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TINT32 holdTimeSamples = src->secondsToSamples(holdTime);
|
|
Toshihiro Shimizu |
890ddd |
TINT32 time = 0;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
const T *srcSample = src->samples();
|
|
Toshihiro Shimizu |
890ddd |
const T *srcEndSample = srcSample + src->getSampleCount();
|
|
Toshihiro Shimizu |
890ddd |
T *dstSample = dst->samples();
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
while (srcSample < srcEndSample) {
|
|
Toshihiro Shimizu |
890ddd |
if (fabs(srcSample->getValue(0) * sampleExcursion_inv) < threshold) {
|
|
Toshihiro Shimizu |
890ddd |
if (time >= holdTimeSamples)
|
|
Toshihiro Shimizu |
890ddd |
*dstSample = T();
|
|
Toshihiro Shimizu |
890ddd |
else
|
|
Toshihiro Shimizu |
890ddd |
*dstSample = *srcSample;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
++time;
|
|
Toshihiro Shimizu |
890ddd |
} else {
|
|
Toshihiro Shimizu |
890ddd |
time = 0;
|
|
Toshihiro Shimizu |
890ddd |
*dstSample = *srcSample;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
++srcSample;
|
|
Toshihiro Shimizu |
890ddd |
++dstSample;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
return dst;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//==============================================================================
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
class TSoundGate : public TSoundTransform
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
double m_threshold;
|
|
Toshihiro Shimizu |
890ddd |
double m_holdTime;
|
|
Toshihiro Shimizu |
890ddd |
double m_releaseTime;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
public:
|
|
Toshihiro Shimizu |
890ddd |
TSoundGate(
|
|
Toshihiro Shimizu |
890ddd |
double threshold,
|
|
Toshihiro Shimizu |
890ddd |
double holdTime,
|
|
Toshihiro Shimizu |
890ddd |
double releaseTime)
|
|
Toshihiro Shimizu |
890ddd |
: m_threshold(threshold), m_holdTime(holdTime), m_releaseTime(releaseTime)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
~TSoundGate() {}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TSoundTrackP compute(const TSoundTrackMono8Signed &src)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
return doGate(
|
|
Toshihiro Shimizu |
890ddd |
const_cast<tsoundtrackmono8signed *="">(&src),</tsoundtrackmono8signed>
|
|
Toshihiro Shimizu |
890ddd |
m_threshold,
|
|
Toshihiro Shimizu |
890ddd |
m_holdTime,
|
|
Toshihiro Shimizu |
890ddd |
m_releaseTime);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TSoundTrackP compute(const TSoundTrackMono8Unsigned &src)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
return doGate(
|
|
Toshihiro Shimizu |
890ddd |
const_cast<tsoundtrackmono8unsigned *="">(&src),</tsoundtrackmono8unsigned>
|
|
Toshihiro Shimizu |
890ddd |
m_threshold,
|
|
Toshihiro Shimizu |
890ddd |
m_holdTime,
|
|
Toshihiro Shimizu |
890ddd |
m_releaseTime);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TSoundTrackP compute(const TSoundTrackStereo8Signed &src)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
return doGate(
|
|
Toshihiro Shimizu |
890ddd |
const_cast<tsoundtrackstereo8signed *="">(&src),</tsoundtrackstereo8signed>
|
|
Toshihiro Shimizu |
890ddd |
m_threshold,
|
|
Toshihiro Shimizu |
890ddd |
m_holdTime,
|
|
Toshihiro Shimizu |
890ddd |
m_releaseTime);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TSoundTrackP compute(const TSoundTrackStereo8Unsigned &src)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
return doGate(
|
|
Toshihiro Shimizu |
890ddd |
const_cast<tsoundtrackstereo8unsigned *="">(&src),</tsoundtrackstereo8unsigned>
|
|
Toshihiro Shimizu |
890ddd |
m_threshold,
|
|
Toshihiro Shimizu |
890ddd |
m_holdTime,
|
|
Toshihiro Shimizu |
890ddd |
m_releaseTime);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TSoundTrackP compute(const TSoundTrackMono16 &src)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
return doGate(
|
|
Toshihiro Shimizu |
890ddd |
const_cast<tsoundtrackmono16 *="">(&src),</tsoundtrackmono16>
|
|
Toshihiro Shimizu |
890ddd |
m_threshold,
|
|
Toshihiro Shimizu |
890ddd |
m_holdTime,
|
|
Toshihiro Shimizu |
890ddd |
m_releaseTime);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TSoundTrackP compute(const TSoundTrackStereo16 &src)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
return doGate(
|
|
Toshihiro Shimizu |
890ddd |
const_cast<tsoundtrackstereo16 *="">(&src),</tsoundtrackstereo16>
|
|
Toshihiro Shimizu |
890ddd |
m_threshold,
|
|
Toshihiro Shimizu |
890ddd |
m_holdTime,
|
|
Toshihiro Shimizu |
890ddd |
m_releaseTime);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TSoundTrackP compute(const TSoundTrackMono24 &src)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
return doGate(
|
|
Toshihiro Shimizu |
890ddd |
const_cast<tsoundtrackmono24 *="">(&src),</tsoundtrackmono24>
|
|
Toshihiro Shimizu |
890ddd |
m_threshold,
|
|
Toshihiro Shimizu |
890ddd |
m_holdTime,
|
|
Toshihiro Shimizu |
890ddd |
m_releaseTime);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TSoundTrackP compute(const TSoundTrackStereo24 &src)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
return doGate(
|
|
Toshihiro Shimizu |
890ddd |
const_cast<tsoundtrackstereo24 *="">(&src),</tsoundtrackstereo24>
|
|
Toshihiro Shimizu |
890ddd |
m_threshold,
|
|
Toshihiro Shimizu |
890ddd |
m_holdTime,
|
|
Toshihiro Shimizu |
890ddd |
m_releaseTime);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
};
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//==============================================================================
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TSoundTrackP TSop::gate(
|
|
Toshihiro Shimizu |
890ddd |
TSoundTrackP src,
|
|
Toshihiro Shimizu |
890ddd |
double threshold,
|
|
Toshihiro Shimizu |
890ddd |
double holdTime,
|
|
Toshihiro Shimizu |
890ddd |
double releaseTime)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
TSoundGate *gate = new TSoundGate(threshold, holdTime, releaseTime);
|
|
Toshihiro Shimizu |
890ddd |
assert(gate);
|
|
Toshihiro Shimizu |
890ddd |
if (!gate)
|
|
Toshihiro Shimizu |
890ddd |
return TSoundTrackP();
|
|
Toshihiro Shimizu |
890ddd |
TSoundTrackP dst = src->apply(gate);
|
|
Toshihiro Shimizu |
890ddd |
delete gate;
|
|
Toshihiro Shimizu |
890ddd |
return dst;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//==============================================================================
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TSoundTrackP TSop::timeStrech(TSoundTrackP src, double ratio)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
TINT32 sampleRate = (TINT32)(src->getSampleRate() * ratio);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
if (sampleRate > 100000)
|
|
Toshihiro Shimizu |
890ddd |
sampleRate = 100000;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TSoundTrackP st;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
if (sampleRate > 0) {
|
|
Toshihiro Shimizu |
890ddd |
TSoundTrackResample *resample = new TSoundTrackResample(sampleRate, FLT_TRIANGLE);
|
|
Toshihiro Shimizu |
890ddd |
st = src->apply(resample);
|
|
Toshihiro Shimizu |
890ddd |
delete resample;
|
|
Toshihiro Shimizu |
890ddd |
st->setSampleRate(src->getSampleRate());
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
return st;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//========================================================================================
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
template <class t=""></class>
|
|
Toshihiro Shimizu |
890ddd |
TSoundTrackP doEcho(
|
|
Toshihiro Shimizu |
890ddd |
TSoundTrackT<t> *src,</t>
|
|
Toshihiro Shimizu |
890ddd |
double delayTime,
|
|
Toshihiro Shimizu |
890ddd |
double decayFactor,
|
|
Toshihiro Shimizu |
890ddd |
double extendTime)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
typedef typename T::ChannelValueType ChannelValueType;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TINT32 dstSampleCount = src->getSampleCount() + (TINT32)(src->getSampleRate() * extendTime);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TSoundTrackT<t> *dst = new TSoundTrackT<t>(</t></t>
|
|
Toshihiro Shimizu |
890ddd |
src->getSampleRate(),
|
|
Toshihiro Shimizu |
890ddd |
src->getChannelCount(),
|
|
Toshihiro Shimizu |
890ddd |
dstSampleCount);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TINT32 sampleRate = (TINT32)src->getSampleRate();
|
|
Toshihiro Shimizu |
890ddd |
TINT32 k = (TINT32)(sampleRate * delayTime);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
T *srcSample = src->samples();
|
|
Toshihiro Shimizu |
890ddd |
T *dstSample = dst->samples();
|
|
Toshihiro Shimizu |
890ddd |
T *endDstSample = dst->samples() + k;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
while (dstSample < endDstSample)
|
|
Toshihiro Shimizu |
890ddd |
*dstSample++ = *srcSample++;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
// la formula dell'echo e'
|
|
Toshihiro Shimizu |
890ddd |
// out(i) = in(i) + decayFactor * in(i - k)
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
bool chans = src->getChannelCount() == 2;
|
|
Toshihiro Shimizu |
890ddd |
endDstSample = dst->samples() + tmin(dstSampleCount, (TINT32)src->getSampleCount());
|
|
Toshihiro Shimizu |
890ddd |
while (dstSample < endDstSample) {
|
|
Toshihiro Shimizu |
890ddd |
//*dstSample = *srcSample + *(srcSample - k)*decayFactor;
|
|
Toshihiro Shimizu |
890ddd |
ChannelValueType val =
|
|
Toshihiro Shimizu |
890ddd |
(ChannelValueType)((srcSample - k)->getValue(TSound::MONO) * decayFactor);
|
|
Toshihiro Shimizu |
890ddd |
dstSample->setValue(TSound::MONO, srcSample->getValue(TSound::MONO) + val);
|
|
Toshihiro Shimizu |
890ddd |
if (chans) {
|
|
Toshihiro Shimizu |
890ddd |
ChannelValueType val =
|
|
Toshihiro Shimizu |
890ddd |
(ChannelValueType)((srcSample - k)->getValue(TSound::RIGHT) * decayFactor);
|
|
Toshihiro Shimizu |
890ddd |
dstSample->setValue(TSound::RIGHT, srcSample->getValue(TSound::RIGHT) + val);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
++dstSample;
|
|
Toshihiro Shimizu |
890ddd |
++srcSample;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
endDstSample = dstSample + k;
|
|
Toshihiro Shimizu |
890ddd |
while (dstSample < endDstSample) {
|
|
Toshihiro Shimizu |
890ddd |
//*dstSample = *(srcSample - k)*decayFactor;
|
|
Toshihiro Shimizu |
890ddd |
ChannelValueType val =
|
|
Toshihiro Shimizu |
890ddd |
(ChannelValueType)((srcSample - k)->getValue(TSound::MONO) * decayFactor);
|
|
Toshihiro Shimizu |
890ddd |
dstSample->setValue(TSound::MONO, val);
|
|
Toshihiro Shimizu |
890ddd |
if (chans) {
|
|
Toshihiro Shimizu |
890ddd |
ChannelValueType val =
|
|
Toshihiro Shimizu |
890ddd |
(ChannelValueType)((srcSample - k)->getValue(TSound::RIGHT) * decayFactor);
|
|
Toshihiro Shimizu |
890ddd |
dstSample->setValue(TSound::RIGHT, val);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
++dstSample;
|
|
Toshihiro Shimizu |
890ddd |
++srcSample;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
srcSample = src->samples() + src->getSampleCount() - 1;
|
|
Toshihiro Shimizu |
890ddd |
endDstSample = dst->samples() + dstSampleCount;
|
|
Toshihiro Shimizu |
890ddd |
while (dstSample < endDstSample) {
|
|
Toshihiro Shimizu |
890ddd |
//*dstSample = *(srcSample)*decayFactor;
|
|
Toshihiro Shimizu |
890ddd |
ChannelValueType val =
|
|
Toshihiro Shimizu |
890ddd |
(ChannelValueType)(srcSample->getValue(TSound::MONO) * decayFactor);
|
|
Toshihiro Shimizu |
890ddd |
dstSample->setValue(TSound::MONO, val);
|
|
Toshihiro Shimizu |
890ddd |
if (chans) {
|
|
Toshihiro Shimizu |
890ddd |
ChannelValueType val =
|
|
Toshihiro Shimizu |
890ddd |
(ChannelValueType)(srcSample->getValue(TSound::RIGHT) * decayFactor);
|
|
Toshihiro Shimizu |
890ddd |
dstSample->setValue(TSound::RIGHT, val);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
++dstSample;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
return TSoundTrackP(dst);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//------------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void TSop::echo(
|
|
Toshihiro Shimizu |
890ddd |
TSoundTrackP &dst,
|
|
Toshihiro Shimizu |
890ddd |
const TSoundTrackP &src,
|
|
Toshihiro Shimizu |
890ddd |
double delayTime,
|
|
Toshihiro Shimizu |
890ddd |
double decayFactor,
|
|
Toshihiro Shimizu |
890ddd |
double extendTime)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
TSoundTrackMono8Signed *srcM8S;
|
|
Toshihiro Shimizu |
890ddd |
srcM8S = dynamic_cast<tsoundtrackmono8signed *="">(src.getPointer());</tsoundtrackmono8signed>
|
|
Toshihiro Shimizu |
890ddd |
if (srcM8S)
|
|
Toshihiro Shimizu |
890ddd |
dst = doEcho(srcM8S, delayTime, decayFactor, extendTime);
|
|
Toshihiro Shimizu |
890ddd |
else {
|
|
Toshihiro Shimizu |
890ddd |
TSoundTrackMono8Unsigned *srcM8U;
|
|
Toshihiro Shimizu |
890ddd |
srcM8U = dynamic_cast<tsoundtrackmono8unsigned *="">(src.getPointer());</tsoundtrackmono8unsigned>
|
|
Toshihiro Shimizu |
890ddd |
if (srcM8U)
|
|
Toshihiro Shimizu |
890ddd |
dst = doEcho(srcM8U, delayTime, decayFactor, extendTime);
|
|
Toshihiro Shimizu |
890ddd |
else {
|
|
Toshihiro Shimizu |
890ddd |
TSoundTrackStereo8Signed *srcS8S;
|
|
Toshihiro Shimizu |
890ddd |
srcS8S = dynamic_cast<tsoundtrackstereo8signed *="">(src.getPointer());</tsoundtrackstereo8signed>
|
|
Toshihiro Shimizu |
890ddd |
if (srcS8S)
|
|
Toshihiro Shimizu |
890ddd |
dst = doEcho(srcS8S, delayTime, decayFactor, extendTime);
|
|
Toshihiro Shimizu |
890ddd |
else {
|
|
Toshihiro Shimizu |
890ddd |
TSoundTrackStereo8Unsigned *srcS8U;
|
|
Toshihiro Shimizu |
890ddd |
srcS8U = dynamic_cast<tsoundtrackstereo8unsigned *="">(src.getPointer());</tsoundtrackstereo8unsigned>
|
|
Toshihiro Shimizu |
890ddd |
if (srcS8U)
|
|
Toshihiro Shimizu |
890ddd |
dst = doEcho(srcS8U, delayTime, decayFactor, extendTime);
|
|
Toshihiro Shimizu |
890ddd |
else {
|
|
Toshihiro Shimizu |
890ddd |
TSoundTrackMono16 *srcM16;
|
|
Toshihiro Shimizu |
890ddd |
srcM16 = dynamic_cast<tsoundtrackmono16 *="">(src.getPointer());</tsoundtrackmono16>
|
|
Toshihiro Shimizu |
890ddd |
if (srcM16)
|
|
Toshihiro Shimizu |
890ddd |
dst = doEcho(srcM16, delayTime, decayFactor, extendTime);
|
|
Toshihiro Shimizu |
890ddd |
else {
|
|
Toshihiro Shimizu |
890ddd |
TSoundTrackStereo16 *srcS16;
|
|
Toshihiro Shimizu |
890ddd |
srcS16 = dynamic_cast<tsoundtrackstereo16 *="">(src.getPointer());</tsoundtrackstereo16>
|
|
Toshihiro Shimizu |
890ddd |
if (srcS16)
|
|
Toshihiro Shimizu |
890ddd |
dst = doEcho(srcS16, delayTime, decayFactor, extendTime);
|
|
Toshihiro Shimizu |
890ddd |
else {
|
|
Toshihiro Shimizu |
890ddd |
TSoundTrackMono24 *srcM24;
|
|
Toshihiro Shimizu |
890ddd |
srcM24 = dynamic_cast<tsoundtrackmono24 *="">(src.getPointer());</tsoundtrackmono24>
|
|
Toshihiro Shimizu |
890ddd |
if (srcM24)
|
|
Toshihiro Shimizu |
890ddd |
dst = doEcho(srcM24, delayTime, decayFactor, extendTime);
|
|
Toshihiro Shimizu |
890ddd |
else {
|
|
Toshihiro Shimizu |
890ddd |
TSoundTrackStereo24 *srcS24;
|
|
Toshihiro Shimizu |
890ddd |
srcS24 = dynamic_cast<tsoundtrackstereo24 *="">(src.getPointer());</tsoundtrackstereo24>
|
|
Toshihiro Shimizu |
890ddd |
if (srcS24)
|
|
Toshihiro Shimizu |
890ddd |
dst = doEcho(srcS24, delayTime, decayFactor, extendTime);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//------------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TSoundTrackP TSop::insertBlank(TSoundTrackP src, TINT32 s0, TINT32 len)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
assert(len >= 0);
|
|
Toshihiro Shimizu |
890ddd |
if (len == 0)
|
|
Toshihiro Shimizu |
890ddd |
return src;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TINT32 ss0 = tcrop<tint32>(s0, 0, src->getSampleCount());</tint32>
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TSoundTrackFormat format = src->getFormat();
|
|
Toshihiro Shimizu |
890ddd |
TSoundTrackP dst = TSoundTrack::create(
|
|
Toshihiro Shimizu |
890ddd |
format, (src->getSampleCount() + len));
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
UCHAR *dstRawData = (UCHAR *)dst->getRawData();
|
|
Toshihiro Shimizu |
890ddd |
UCHAR *srcRawData = (UCHAR *)src->getRawData();
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
int bytePerSample = dst->getSampleSize();
|
|
Toshihiro Shimizu |
890ddd |
memcpy(dstRawData, srcRawData, ss0 * bytePerSample);
|
|
Toshihiro Shimizu |
890ddd |
if (format.m_signedSample)
|
|
Toshihiro Shimizu |
890ddd |
memset(dstRawData + ss0 * bytePerSample, 0, len * bytePerSample);
|
|
Toshihiro Shimizu |
890ddd |
else
|
|
Toshihiro Shimizu |
890ddd |
memset(dstRawData + ss0 * bytePerSample, 127, len * bytePerSample);
|
|
Toshihiro Shimizu |
890ddd |
memcpy(
|
|
Toshihiro Shimizu |
890ddd |
dstRawData + (ss0 + len) * bytePerSample,
|
|
Toshihiro Shimizu |
890ddd |
srcRawData + ss0 * bytePerSample,
|
|
Toshihiro Shimizu |
890ddd |
(src->getSampleCount() - ss0) * bytePerSample);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
return dst;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//------------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TSoundTrackP TSop::insertBlank(TSoundTrackP src, double t0, double len)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
return insertBlank(src, src->secondsToSamples(t0), src->secondsToSamples(len));
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//------------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TSoundTrackP TSop::remove(TSoundTrackP src, TINT32 s0, TINT32 s1, TSoundTrackP &paste)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
TINT32 ss0, ss1;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
ss0 = tmax<tint32>((TINT32)0, s0);</tint32>
|
|
Toshihiro Shimizu |
890ddd |
ss1 = tmin(s1, (TINT32)(src->getSampleCount() - 1));
|
|
Toshihiro Shimizu |
890ddd |
TSoundTrackP soundTrackSlice;
|
|
Toshihiro Shimizu |
890ddd |
if (ss0 <= ss1)
|
|
Toshihiro Shimizu |
890ddd |
soundTrackSlice = src->extract(ss0, ss1);
|
|
Toshihiro Shimizu |
890ddd |
if (!soundTrackSlice) {
|
|
Toshihiro Shimizu |
890ddd |
paste = TSoundTrackP();
|
|
Toshihiro Shimizu |
890ddd |
return src;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
paste = soundTrackSlice->clone();
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TSoundTrackFormat format = src->getFormat();
|
|
Toshihiro Shimizu |
890ddd |
TSoundTrackP dst = TSoundTrack::create(format, (src->getSampleCount() - (ss1 - ss0 + 1)));
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TINT32 dstSampleSize = dst->getSampleSize();
|
|
Toshihiro Shimizu |
890ddd |
UCHAR *newRowData = (UCHAR *)dst->getRawData();
|
|
Toshihiro Shimizu |
890ddd |
UCHAR *srcRowData = (UCHAR *)src->getRawData();
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
memcpy(newRowData, srcRowData, ss0 * dstSampleSize);
|
|
Toshihiro Shimizu |
890ddd |
memcpy(
|
|
Toshihiro Shimizu |
890ddd |
newRowData + (ss0 * dstSampleSize),
|
|
Toshihiro Shimizu |
890ddd |
srcRowData + (ss1 + 1) * dstSampleSize,
|
|
Toshihiro Shimizu |
890ddd |
(src->getSampleCount() - ss1 - 1) * dst->getSampleSize());
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
return dst;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//------------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TSoundTrackP TSop::remove(TSoundTrackP src, double t0, double t1, TSoundTrackP &paste)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
return remove(src, src->secondsToSamples(t0), src->secondsToSamples(t1), paste);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//------------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
template <class t=""></class>
|
|
Toshihiro Shimizu |
890ddd |
TSoundTrackP mixT(
|
|
Toshihiro Shimizu |
890ddd |
TSoundTrackT<t> *st1, double a1, TSoundTrackT<t> *st2, double a2)</t></t>
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
TINT32 sampleCount = tmax(st1->getSampleCount(), st2->getSampleCount());
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TSoundTrackT<t> *dst = new TSoundTrackT<t>(</t></t>
|
|
Toshihiro Shimizu |
890ddd |
st1->getSampleRate(),
|
|
Toshihiro Shimizu |
890ddd |
st1->getChannelCount(),
|
|
Toshihiro Shimizu |
890ddd |
sampleCount);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
T *dstSample = dst->samples();
|
|
Toshihiro Shimizu |
890ddd |
T *endDstSample = dstSample + tmin(st1->getSampleCount(), st2->getSampleCount());
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
T *st1Sample = st1->samples();
|
|
Toshihiro Shimizu |
890ddd |
T *st2Sample = st2->samples();
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
while (dstSample < endDstSample) {
|
|
Toshihiro Shimizu |
890ddd |
*dstSample++ = T::mix(*st1Sample, a1, *st2Sample, a2);
|
|
Toshihiro Shimizu |
890ddd |
++st1Sample;
|
|
Toshihiro Shimizu |
890ddd |
++st2Sample;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
T *srcSample = st1->getSampleCount() > st2->getSampleCount() ? st1Sample : st2Sample;
|
|
Toshihiro Shimizu |
890ddd |
endDstSample = dst->samples() + sampleCount;
|
|
Toshihiro Shimizu |
890ddd |
while (dstSample < endDstSample)
|
|
Toshihiro Shimizu |
890ddd |
*dstSample++ = *srcSample++;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
return TSoundTrackP(dst);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//=============================================================================
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
class TSoundTrackMixer : public TSoundTransform
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
double m_alpha1, m_alpha2;
|
|
Toshihiro Shimizu |
890ddd |
TSoundTrackP m_sndtrack;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
public:
|
|
Toshihiro Shimizu |
890ddd |
TSoundTrackMixer(double a1, double a2, const TSoundTrackP &st2)
|
|
Toshihiro Shimizu |
890ddd |
: TSoundTransform(), m_alpha1(a1), m_alpha2(a2), m_sndtrack(st2)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
~TSoundTrackMixer(){};
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TSoundTrackP compute(const TSoundTrackMono8Signed &src)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
assert(src.getFormat() == m_sndtrack->getFormat());
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
return (mixT(
|
|
Toshihiro Shimizu |
890ddd |
const_cast<tsoundtrackmono8signed *="">(&src), m_alpha1,</tsoundtrackmono8signed>
|
|
Toshihiro Shimizu |
890ddd |
dynamic_cast<tsoundtrackmono8signed *="">(m_sndtrack.getPointer()), m_alpha2));</tsoundtrackmono8signed>
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TSoundTrackP compute(const TSoundTrackMono8Unsigned &src)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
assert(src.getFormat() == m_sndtrack->getFormat());
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
return (mixT(
|
|
Toshihiro Shimizu |
890ddd |
const_cast<tsoundtrackmono8unsigned *="">(&src), m_alpha1,</tsoundtrackmono8unsigned>
|
|
Toshihiro Shimizu |
890ddd |
dynamic_cast<tsoundtrackmono8unsigned *="">(m_sndtrack.getPointer()), m_alpha2));</tsoundtrackmono8unsigned>
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TSoundTrackP compute(const TSoundTrackStereo8Signed &src)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
assert(src.getFormat() == m_sndtrack->getFormat());
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
return (mixT(
|
|
Toshihiro Shimizu |
890ddd |
const_cast<tsoundtrackstereo8signed *="">(&src), m_alpha1,</tsoundtrackstereo8signed>
|
|
Toshihiro Shimizu |
890ddd |
dynamic_cast<tsoundtrackstereo8signed *="">(m_sndtrack.getPointer()), m_alpha2));</tsoundtrackstereo8signed>
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TSoundTrackP compute(const TSoundTrackStereo8Unsigned &src)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
assert(src.getFormat() == m_sndtrack->getFormat());
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
return (mixT(
|
|
Toshihiro Shimizu |
890ddd |
const_cast<tsoundtrackstereo8unsigned *="">(&src), m_alpha1,</tsoundtrackstereo8unsigned>
|
|
Toshihiro Shimizu |
890ddd |
dynamic_cast<tsoundtrackstereo8unsigned *="">(m_sndtrack.getPointer()), m_alpha2));</tsoundtrackstereo8unsigned>
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TSoundTrackP compute(const TSoundTrackMono16 &src)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
assert(src.getFormat() == m_sndtrack->getFormat());
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
return (mixT(
|
|
Toshihiro Shimizu |
890ddd |
const_cast<tsoundtrackmono16 *="">(&src), m_alpha1,</tsoundtrackmono16>
|
|
Toshihiro Shimizu |
890ddd |
dynamic_cast<tsoundtrackmono16 *="">(m_sndtrack.getPointer()), m_alpha2));</tsoundtrackmono16>
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TSoundTrackP compute(const TSoundTrackStereo16 &src)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
assert(src.getFormat() == m_sndtrack->getFormat());
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
return (mixT(
|
|
Toshihiro Shimizu |
890ddd |
const_cast<tsoundtrackstereo16 *="">(&src), m_alpha1,</tsoundtrackstereo16>
|
|
Toshihiro Shimizu |
890ddd |
dynamic_cast<tsoundtrackstereo16 *="">(m_sndtrack.getPointer()), m_alpha2));</tsoundtrackstereo16>
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TSoundTrackP compute(const TSoundTrackMono24 &src)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
assert(src.getFormat() == m_sndtrack->getFormat());
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
return (mixT(
|
|
Toshihiro Shimizu |
890ddd |
const_cast<tsoundtrackmono24 *="">(&src), m_alpha1,</tsoundtrackmono24>
|
|
Toshihiro Shimizu |
890ddd |
dynamic_cast<tsoundtrackmono24 *="">(m_sndtrack.getPointer()), m_alpha2));</tsoundtrackmono24>
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TSoundTrackP compute(const TSoundTrackStereo24 &src)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
assert(src.getFormat() == m_sndtrack->getFormat());
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
return (mixT(
|
|
Toshihiro Shimizu |
890ddd |
const_cast<tsoundtrackstereo24 *="">(&src), m_alpha1,</tsoundtrackstereo24>
|
|
Toshihiro Shimizu |
890ddd |
dynamic_cast<tsoundtrackstereo24 *="">(m_sndtrack.getPointer()), m_alpha2));</tsoundtrackstereo24>
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
};
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TSoundTrackP TSop::mix(
|
|
Toshihiro Shimizu |
890ddd |
const TSoundTrackP &st1,
|
|
Toshihiro Shimizu |
890ddd |
const TSoundTrackP &st2,
|
|
Toshihiro Shimizu |
890ddd |
double a1,
|
|
Toshihiro Shimizu |
890ddd |
double a2)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
TSoundTrackMixer *converter;
|
|
Toshihiro Shimizu |
890ddd |
a1 = tcrop<double>(a1, 0.0, 1.0);</double>
|
|
Toshihiro Shimizu |
890ddd |
a2 = tcrop<double>(a2, 0.0, 1.0);</double>
|
|
Toshihiro Shimizu |
890ddd |
converter = new TSoundTrackMixer(a1, a2, st2);
|
|
Toshihiro Shimizu |
890ddd |
TSoundTrackP snd = st1->apply(converter);
|
|
Toshihiro Shimizu |
890ddd |
delete converter;
|
|
Toshihiro Shimizu |
890ddd |
return (snd);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//==============================================================================
|
|
Toshihiro Shimizu |
890ddd |
//
|
|
Toshihiro Shimizu |
890ddd |
// TSop::FadeIn
|
|
Toshihiro Shimizu |
890ddd |
//
|
|
Toshihiro Shimizu |
890ddd |
//==============================================================================
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
template <class t=""></class>
|
|
Toshihiro Shimizu |
890ddd |
TSoundTrackP doFadeIn(const TSoundTrackT<t> &track, double riseFactor)</t>
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
typedef typename T::ChannelValueType ChannelValueType;
|
|
Toshihiro Shimizu |
890ddd |
int sampleCount = (int)((double)track.getSampleCount() * riseFactor);
|
|
Toshihiro Shimizu |
890ddd |
if (!sampleCount)
|
|
Toshihiro Shimizu |
890ddd |
sampleCount = 1;
|
|
Toshihiro Shimizu |
890ddd |
assert(sampleCount);
|
|
Toshihiro Shimizu |
890ddd |
int channelCount = track.getChannelCount();
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TSoundTrackT<t> *out =</t>
|
|
Toshihiro Shimizu |
890ddd |
new TSoundTrackT<t>(track.getSampleRate(), channelCount, sampleCount);</t>
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
double val[2], step[2];
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
ChannelValueType chan[2];
|
|
Toshihiro Shimizu |
890ddd |
const T *firstSample = track.samples();
|
|
Toshihiro Shimizu |
890ddd |
for (int k = 0; k < channelCount; ++k) {
|
|
Toshihiro Shimizu |
890ddd |
chan[k] = firstSample->getValue(k);
|
|
Toshihiro Shimizu |
890ddd |
if (firstSample->isSampleSigned()) {
|
|
Toshihiro Shimizu |
890ddd |
val[k] = 0;
|
|
Toshihiro Shimizu |
890ddd |
step[k] = (double)chan[k] / (double)sampleCount;
|
|
Toshihiro Shimizu |
890ddd |
} else {
|
|
Toshihiro Shimizu |
890ddd |
val[k] = 127;
|
|
Toshihiro Shimizu |
890ddd |
step[k] = (double)(chan[k] - 128) / (double)sampleCount;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
T *psample = out->samples();
|
|
Toshihiro Shimizu |
890ddd |
T *end = psample + out->getSampleCount();
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
while (psample < end) {
|
|
Toshihiro Shimizu |
890ddd |
T sample;
|
|
Toshihiro Shimizu |
890ddd |
for (int k = 0; k < channelCount; ++k) {
|
|
Toshihiro Shimizu |
890ddd |
sample.setValue(k, (ChannelValueType)val[k]);
|
|
Toshihiro Shimizu |
890ddd |
val[k] += step[k];
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
*psample = sample;
|
|
Toshihiro Shimizu |
890ddd |
++psample;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
return out;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//------------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
class TSoundTrackFaderIn : public TSoundTransform
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
public:
|
|
Toshihiro Shimizu |
890ddd |
TSoundTrackFaderIn(double riseFactor)
|
|
Toshihiro Shimizu |
890ddd |
: TSoundTransform(), m_riseFactor(riseFactor)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TSoundTrackP compute(const TSoundTrackMono8Signed &);
|
|
Toshihiro Shimizu |
890ddd |
TSoundTrackP compute(const TSoundTrackStereo8Signed &);
|
|
Toshihiro Shimizu |
890ddd |
TSoundTrackP compute(const TSoundTrackMono8Unsigned &);
|
|
Toshihiro Shimizu |
890ddd |
TSoundTrackP compute(const TSoundTrackStereo8Unsigned &);
|
|
Toshihiro Shimizu |
890ddd |
TSoundTrackP compute(const TSoundTrackMono16 &);
|
|
Toshihiro Shimizu |
890ddd |
TSoundTrackP compute(const TSoundTrackStereo16 &);
|
|
Toshihiro Shimizu |
890ddd |
TSoundTrackP compute(const TSoundTrackMono24 &);
|
|
Toshihiro Shimizu |
890ddd |
TSoundTrackP compute(const TSoundTrackStereo24 &);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
double m_riseFactor;
|
|
Toshihiro Shimizu |
890ddd |
};
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//------------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TSoundTrackP TSoundTrackFaderIn::compute(const TSoundTrackMono8Signed &track)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
return doFadeIn(track, m_riseFactor);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//------------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TSoundTrackP TSoundTrackFaderIn::compute(const TSoundTrackStereo8Signed &track)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
return doFadeIn(track, m_riseFactor);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//------------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TSoundTrackP TSoundTrackFaderIn::compute(const TSoundTrackMono8Unsigned &track)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
return doFadeIn(track, m_riseFactor);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//------------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TSoundTrackP TSoundTrackFaderIn::compute(const TSoundTrackStereo8Unsigned &track)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
return doFadeIn(track, m_riseFactor);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//------------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TSoundTrackP TSoundTrackFaderIn::compute(const TSoundTrackMono16 &track)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
return doFadeIn(track, m_riseFactor);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//------------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TSoundTrackP TSoundTrackFaderIn::compute(const TSoundTrackStereo16 &track)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
return doFadeIn(track, m_riseFactor);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
//------------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TSoundTrackP TSoundTrackFaderIn::compute(const TSoundTrackMono24 &track)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
return doFadeIn(track, m_riseFactor);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
//------------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TSoundTrackP TSoundTrackFaderIn::compute(const TSoundTrackStereo24 &track)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
return doFadeIn(track, m_riseFactor);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//------------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TSoundTrackP TSop::fadeIn(const TSoundTrackP src, double riseFactor)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
TSoundTrackFaderIn *fader = new TSoundTrackFaderIn(riseFactor);
|
|
Toshihiro Shimizu |
890ddd |
TSoundTrackP out = src->apply(fader);
|
|
Toshihiro Shimizu |
890ddd |
delete fader;
|
|
Toshihiro Shimizu |
890ddd |
return out;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//==============================================================================
|
|
Toshihiro Shimizu |
890ddd |
//
|
|
Toshihiro Shimizu |
890ddd |
// TSop::FadeOut
|
|
Toshihiro Shimizu |
890ddd |
//
|
|
Toshihiro Shimizu |
890ddd |
//==============================================================================
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
template <class t=""></class>
|
|
Toshihiro Shimizu |
890ddd |
TSoundTrackP doFadeOut(
|
|
Toshihiro Shimizu |
890ddd |
const TSoundTrackT<t> &track, double decayFactor)</t>
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
typedef typename T::ChannelValueType ChannelValueType;
|
|
Toshihiro Shimizu |
890ddd |
int sampleCount = (int)((double)track.getSampleCount() * decayFactor);
|
|
Toshihiro Shimizu |
890ddd |
if (!sampleCount)
|
|
Toshihiro Shimizu |
890ddd |
sampleCount = 1;
|
|
Toshihiro Shimizu |
890ddd |
assert(sampleCount);
|
|
Toshihiro Shimizu |
890ddd |
int channelCount = track.getChannelCount();
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TSoundTrackT<t> *out =</t>
|
|
Toshihiro Shimizu |
890ddd |
new TSoundTrackT<t>(track.getSampleRate(), channelCount, sampleCount);</t>
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
double val[2], step[2];
|
|
Toshihiro Shimizu |
890ddd |
ChannelValueType chan[2];
|
|
Toshihiro Shimizu |
890ddd |
const T *lastSample = (track.samples() + track.getSampleCount() - 1);
|
|
Toshihiro Shimizu |
890ddd |
for (int k = 0; k < channelCount; ++k) {
|
|
Toshihiro Shimizu |
890ddd |
chan[k] = lastSample->getValue(k);
|
|
Toshihiro Shimizu |
890ddd |
val[k] = (double)chan[k];
|
|
Toshihiro Shimizu |
890ddd |
if (lastSample->isSampleSigned())
|
|
Toshihiro Shimizu |
890ddd |
step[k] = (double)chan[k] / (double)sampleCount;
|
|
Toshihiro Shimizu |
890ddd |
else
|
|
Toshihiro Shimizu |
890ddd |
step[k] = (double)(chan[k] - 128) / (double)sampleCount;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
T *psample = out->samples();
|
|
Toshihiro Shimizu |
890ddd |
T *end = psample + out->getSampleCount();
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
while (psample < end) {
|
|
Toshihiro Shimizu |
890ddd |
T sample;
|
|
Toshihiro Shimizu |
890ddd |
for (int k = 0; k < channelCount; ++k) {
|
|
Toshihiro Shimizu |
890ddd |
sample.setValue(k, (ChannelValueType)val[k]);
|
|
Toshihiro Shimizu |
890ddd |
val[k] -= step[k];
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
*psample = sample;
|
|
Toshihiro Shimizu |
890ddd |
++psample;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
return out;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//------------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
class TSoundTrackFaderOut : public TSoundTransform
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
public:
|
|
Toshihiro Shimizu |
890ddd |
TSoundTrackFaderOut(double decayFactor)
|
|
Toshihiro Shimizu |
890ddd |
: TSoundTransform(), m_decayFactor(decayFactor)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TSoundTrackP compute(const TSoundTrackMono8Signed &);
|
|
Toshihiro Shimizu |
890ddd |
TSoundTrackP compute(const TSoundTrackStereo8Signed &);
|
|
Toshihiro Shimizu |
890ddd |
TSoundTrackP compute(const TSoundTrackMono8Unsigned &);
|
|
Toshihiro Shimizu |
890ddd |
TSoundTrackP compute(const TSoundTrackStereo8Unsigned &);
|
|
Toshihiro Shimizu |
890ddd |
TSoundTrackP compute(const TSoundTrackMono16 &);
|
|
Toshihiro Shimizu |
890ddd |
TSoundTrackP compute(const TSoundTrackStereo16 &);
|
|
Toshihiro Shimizu |
890ddd |
TSoundTrackP compute(const TSoundTrackMono24 &);
|
|
Toshihiro Shimizu |
890ddd |
TSoundTrackP compute(const TSoundTrackStereo24 &);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
double m_decayFactor;
|
|
Toshihiro Shimizu |
890ddd |
};
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//------------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TSoundTrackP TSoundTrackFaderOut::compute(const TSoundTrackMono8Signed &track)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
return doFadeOut(track, m_decayFactor);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//------------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TSoundTrackP TSoundTrackFaderOut::compute(const TSoundTrackStereo8Signed &track)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
return doFadeOut(track, m_decayFactor);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//------------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TSoundTrackP TSoundTrackFaderOut::compute(const TSoundTrackMono8Unsigned &track)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
return doFadeOut(track, m_decayFactor);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//------------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TSoundTrackP TSoundTrackFaderOut::compute(const TSoundTrackStereo8Unsigned &track)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
return doFadeOut(track, m_decayFactor);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//------------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TSoundTrackP TSoundTrackFaderOut::compute(const TSoundTrackMono16 &track)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
return doFadeOut(track, m_decayFactor);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//------------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TSoundTrackP TSoundTrackFaderOut::compute(const TSoundTrackStereo16 &track)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
return doFadeOut(track, m_decayFactor);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
//------------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TSoundTrackP TSoundTrackFaderOut::compute(const TSoundTrackMono24 &track)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
return doFadeOut(track, m_decayFactor);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
//------------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TSoundTrackP TSoundTrackFaderOut::compute(const TSoundTrackStereo24 &track)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
return doFadeOut(track, m_decayFactor);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//------------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TSoundTrackP TSop::fadeOut(const TSoundTrackP src, double decayFactor)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
TSoundTrackFaderOut *fader = new TSoundTrackFaderOut(decayFactor);
|
|
Toshihiro Shimizu |
890ddd |
TSoundTrackP out = src->apply(fader);
|
|
Toshihiro Shimizu |
890ddd |
delete fader;
|
|
Toshihiro Shimizu |
890ddd |
return out;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//==============================================================================
|
|
Toshihiro Shimizu |
890ddd |
//
|
|
Toshihiro Shimizu |
890ddd |
// TSop::CrossFade
|
|
Toshihiro Shimizu |
890ddd |
//
|
|
Toshihiro Shimizu |
890ddd |
//==============================================================================
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
template <class t=""></class>
|
|
Toshihiro Shimizu |
890ddd |
TSoundTrackP doCrossFade(
|
|
Toshihiro Shimizu |
890ddd |
const TSoundTrackT<t> &track1,</t>
|
|
Toshihiro Shimizu |
890ddd |
TSoundTrackT<t> *track2,</t>
|
|
Toshihiro Shimizu |
890ddd |
double crossFactor)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
typedef typename T::ChannelValueType ChannelValueType;
|
|
Toshihiro Shimizu |
890ddd |
int channelCount = track2->getChannelCount();
|
|
Toshihiro Shimizu |
890ddd |
int sampleCount = (int)((double)track2->getSampleCount() * crossFactor);
|
|
Toshihiro Shimizu |
890ddd |
if (!sampleCount)
|
|
Toshihiro Shimizu |
890ddd |
sampleCount = 1;
|
|
Toshihiro Shimizu |
890ddd |
assert(sampleCount);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//ultimo campione di track1
|
|
Toshihiro Shimizu |
890ddd |
ChannelValueType chanTrack1[2];
|
|
Toshihiro Shimizu |
890ddd |
const T *lastSample = (track1.samples() + track1.getSampleCount() - 1);
|
|
Toshihiro Shimizu |
890ddd |
int k;
|
|
Toshihiro Shimizu |
890ddd |
for (k = 0; k < channelCount; ++k)
|
|
Toshihiro Shimizu |
890ddd |
chanTrack1[k] = lastSample->getValue(k);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
double val[2], step[2];
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//primo campione di track2
|
|
Toshihiro Shimizu |
890ddd |
ChannelValueType chanTrack2[2];
|
|
Toshihiro Shimizu |
890ddd |
const T *firstSample = track2->samples();
|
|
Toshihiro Shimizu |
890ddd |
for (k = 0; k < channelCount; ++k) {
|
|
Toshihiro Shimizu |
890ddd |
chanTrack2[k] = firstSample->getValue(k);
|
|
Toshihiro Shimizu |
890ddd |
val[k] = chanTrack1[k] - chanTrack2[k];
|
|
Toshihiro Shimizu |
890ddd |
step[k] = val[k] / (double)sampleCount;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TSoundTrackT<t> *out =</t>
|
|
Toshihiro Shimizu |
890ddd |
new TSoundTrackT<t>(track2->getSampleRate(), channelCount, sampleCount);</t>
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
T *psample = out->samples();
|
|
Toshihiro Shimizu |
890ddd |
T *end = psample + out->getSampleCount();
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
while (psample < end) {
|
|
Toshihiro Shimizu |
890ddd |
T sample;
|
|
Toshihiro Shimizu |
890ddd |
for (int k = 0; k < channelCount; ++k) {
|
|
Toshihiro Shimizu |
890ddd |
double tot = (double)firstSample->getValue(k) + val[k];
|
|
Toshihiro Shimizu |
890ddd |
ChannelValueType value = (ChannelValueType)tot;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
sample.setValue(k, value);
|
|
Toshihiro Shimizu |
890ddd |
val[k] -= step[k];
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
*psample = sample;
|
|
Toshihiro Shimizu |
890ddd |
++psample;
|
|
Toshihiro Shimizu |
890ddd |
//++firstSample;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
return out;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//------------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
class TSoundTrackCrossFader : public TSoundTransform
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
public:
|
|
Toshihiro Shimizu |
890ddd |
TSoundTrackCrossFader(TSoundTrackP src, double crossFactor)
|
|
Toshihiro Shimizu |
890ddd |
: TSoundTransform(), m_st(src), m_crossFactor(crossFactor)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TSoundTrackP compute(const TSoundTrackMono8Signed &);
|
|
Toshihiro Shimizu |
890ddd |
TSoundTrackP compute(const TSoundTrackStereo8Signed &);
|
|
Toshihiro Shimizu |
890ddd |
TSoundTrackP compute(const TSoundTrackMono8Unsigned &);
|
|
Toshihiro Shimizu |
890ddd |
TSoundTrackP compute(const TSoundTrackStereo8Unsigned &);
|
|
Toshihiro Shimizu |
890ddd |
TSoundTrackP compute(const TSoundTrackMono16 &);
|
|
Toshihiro Shimizu |
890ddd |
TSoundTrackP compute(const TSoundTrackStereo16 &);
|
|
Toshihiro Shimizu |
890ddd |
TSoundTrackP compute(const TSoundTrackMono24 &);
|
|
Toshihiro Shimizu |
890ddd |
TSoundTrackP compute(const TSoundTrackStereo24 &);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TSoundTrackP m_st;
|
|
Toshihiro Shimizu |
890ddd |
double m_crossFactor;
|
|
Toshihiro Shimizu |
890ddd |
};
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//------------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TSoundTrackP TSoundTrackCrossFader::compute(const TSoundTrackMono8Signed &src)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
assert(src.getFormat() == m_st->getFormat());
|
|
Toshihiro Shimizu |
890ddd |
return doCrossFade(
|
|
Toshihiro Shimizu |
890ddd |
src, dynamic_cast<tsoundtrackmono8signed *="">(m_st.getPointer()), m_crossFactor);</tsoundtrackmono8signed>
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//------------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TSoundTrackP TSoundTrackCrossFader::compute(const TSoundTrackStereo8Signed &src)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
assert(src.getFormat() == m_st->getFormat());
|
|
Toshihiro Shimizu |
890ddd |
return doCrossFade(
|
|
Toshihiro Shimizu |
890ddd |
src, dynamic_cast<tsoundtrackstereo8signed *="">(m_st.getPointer()), m_crossFactor);</tsoundtrackstereo8signed>
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//------------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TSoundTrackP TSoundTrackCrossFader::compute(const TSoundTrackMono8Unsigned &src)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
assert(src.getFormat() == m_st->getFormat());
|
|
Toshihiro Shimizu |
890ddd |
return doCrossFade(
|
|
Toshihiro Shimizu |
890ddd |
src, dynamic_cast<tsoundtrackmono8unsigned *="">(m_st.getPointer()), m_crossFactor);</tsoundtrackmono8unsigned>
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//------------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TSoundTrackP TSoundTrackCrossFader::compute(const TSoundTrackStereo8Unsigned &src)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
assert(src.getFormat() == m_st->getFormat());
|
|
Toshihiro Shimizu |
890ddd |
return doCrossFade(
|
|
Toshihiro Shimizu |
890ddd |
src, dynamic_cast<tsoundtrackstereo8unsigned *="">(m_st.getPointer()), m_crossFactor);</tsoundtrackstereo8unsigned>
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//------------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TSoundTrackP TSoundTrackCrossFader::compute(const TSoundTrackMono16 &src)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
assert(src.getFormat() == m_st->getFormat());
|
|
Toshihiro Shimizu |
890ddd |
return doCrossFade(
|
|
Toshihiro Shimizu |
890ddd |
src, dynamic_cast<tsoundtrackmono16 *="">(m_st.getPointer()), m_crossFactor);</tsoundtrackmono16>
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//------------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TSoundTrackP TSoundTrackCrossFader::compute(const TSoundTrackStereo16 &src)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
assert(src.getFormat() == m_st->getFormat());
|
|
Toshihiro Shimizu |
890ddd |
return doCrossFade(
|
|
Toshihiro Shimizu |
890ddd |
src, dynamic_cast<tsoundtrackstereo16 *="">(m_st.getPointer()), m_crossFactor);</tsoundtrackstereo16>
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//------------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TSoundTrackP TSoundTrackCrossFader::compute(const TSoundTrackMono24 &src)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
assert(src.getFormat() == m_st->getFormat());
|
|
Toshihiro Shimizu |
890ddd |
return doCrossFade(
|
|
Toshihiro Shimizu |
890ddd |
src, dynamic_cast<tsoundtrackmono24 *="">(m_st.getPointer()), m_crossFactor);</tsoundtrackmono24>
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//------------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TSoundTrackP TSoundTrackCrossFader::compute(const TSoundTrackStereo24 &src)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
assert(src.getFormat() == m_st->getFormat());
|
|
Toshihiro Shimizu |
890ddd |
return doCrossFade(
|
|
Toshihiro Shimizu |
890ddd |
src, dynamic_cast<tsoundtrackstereo24 *="">(m_st.getPointer()), m_crossFactor);</tsoundtrackstereo24>
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//------------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TSoundTrackP TSop::crossFade(
|
|
Toshihiro Shimizu |
890ddd |
const TSoundTrackP src1, const TSoundTrackP src2, double crossFactor)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
TSoundTrackCrossFader *fader = new TSoundTrackCrossFader(src2, crossFactor);
|
|
Toshihiro Shimizu |
890ddd |
TSoundTrackP out = src1->apply(fader);
|
|
Toshihiro Shimizu |
890ddd |
delete fader;
|
|
Toshihiro Shimizu |
890ddd |
return out;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//
|
|
Toshihiro Shimizu |
890ddd |
//
|
|
Toshihiro Shimizu |
890ddd |
//
|
|
Toshihiro Shimizu |
890ddd |
//
|
|
Toshihiro Shimizu |
890ddd |
//==============================================================================
|
|
Toshihiro Shimizu |
890ddd |
//
|
|
Toshihiro Shimizu |
890ddd |
// TSop::CrossFadeOverWrite
|
|
Toshihiro Shimizu |
890ddd |
//
|
|
Toshihiro Shimizu |
890ddd |
//==============================================================================
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
template <class t=""></class>
|
|
Toshihiro Shimizu |
890ddd |
TSoundTrackP doCrossFadeOverWrite(
|
|
Toshihiro Shimizu |
890ddd |
const TSoundTrackT<t> &track1,</t>
|
|
Toshihiro Shimizu |
890ddd |
TSoundTrackT<t> *track2,</t>
|
|
Toshihiro Shimizu |
890ddd |
double crossFactor)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
typedef typename T::ChannelValueType ChannelValueType;
|
|
Toshihiro Shimizu |
890ddd |
int channelCount = track2->getChannelCount();
|
|
Toshihiro Shimizu |
890ddd |
int sampleCount = (int)((double)track2->getSampleCount() * crossFactor);
|
|
Toshihiro Shimizu |
890ddd |
int sampleCountT2 = track2->getSampleCount();
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
if (sampleCount == 0 && sampleCountT2 == 1)
|
|
Toshihiro Shimizu |
890ddd |
return track2;
|
|
Toshihiro Shimizu |
890ddd |
if (sampleCount == 0)
|
|
Toshihiro Shimizu |
890ddd |
sampleCount = 1;
|
|
Toshihiro Shimizu |
890ddd |
assert(sampleCount);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//ultimo campione di track1
|
|
Toshihiro Shimizu |
890ddd |
ChannelValueType chanTrack1[2];
|
|
Toshihiro Shimizu |
890ddd |
const T *lastSample = (track1.samples() + track1.getSampleCount() - 1);
|
|
Toshihiro Shimizu |
890ddd |
int k;
|
|
Toshihiro Shimizu |
890ddd |
for (k = 0; k < channelCount; ++k)
|
|
Toshihiro Shimizu |
890ddd |
chanTrack1[k] = lastSample->getValue(k);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
double val[2], step[2];
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//primo campione di track2
|
|
Toshihiro Shimizu |
890ddd |
ChannelValueType chanTrack2[2];
|
|
Toshihiro Shimizu |
890ddd |
const T *firstSample = track2->samples() + sampleCount;
|
|
Toshihiro Shimizu |
890ddd |
for (k = 0; k < channelCount; ++k) {
|
|
Toshihiro Shimizu |
890ddd |
chanTrack2[k] = firstSample->getValue(k);
|
|
Toshihiro Shimizu |
890ddd |
val[k] = chanTrack1[k] - chanTrack2[k];
|
|
Toshihiro Shimizu |
890ddd |
step[k] = val[k] / (double)sampleCount;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TSoundTrackT<t> *out =</t>
|
|
Toshihiro Shimizu |
890ddd |
new TSoundTrackT<t>(track2->getSampleRate(), channelCount, sampleCountT2);</t>
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
T *psample = out->samples();
|
|
Toshihiro Shimizu |
890ddd |
T *end = psample + sampleCount;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
while (psample < end) {
|
|
Toshihiro Shimizu |
890ddd |
T sample;
|
|
Toshihiro Shimizu |
890ddd |
for (int k = 0; k < channelCount; ++k) {
|
|
Toshihiro Shimizu |
890ddd |
double tot = (double)firstSample->getValue(k) + val[k];
|
|
Toshihiro Shimizu |
890ddd |
ChannelValueType value = (ChannelValueType)tot;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
sample.setValue(k, value);
|
|
Toshihiro Shimizu |
890ddd |
val[k] -= step[k];
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
*psample = sample;
|
|
Toshihiro Shimizu |
890ddd |
++psample;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
out->copy(track2->extract(sampleCount, sampleCountT2 - 1), sampleCount);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
return out;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//------------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
class TSoundTrackCrossFaderOverWrite : public TSoundTransform
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
public:
|
|
Toshihiro Shimizu |
890ddd |
TSoundTrackCrossFaderOverWrite(TSoundTrackP src, double crossFactor)
|
|
Toshihiro Shimizu |
890ddd |
: TSoundTransform(), m_st(src), m_crossFactor(crossFactor)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TSoundTrackP compute(const TSoundTrackMono8Signed &);
|
|
Toshihiro Shimizu |
890ddd |
TSoundTrackP compute(const TSoundTrackStereo8Signed &);
|
|
Toshihiro Shimizu |
890ddd |
TSoundTrackP compute(const TSoundTrackMono8Unsigned &);
|
|
Toshihiro Shimizu |
890ddd |
TSoundTrackP compute(const TSoundTrackStereo8Unsigned &);
|
|
Toshihiro Shimizu |
890ddd |
TSoundTrackP compute(const TSoundTrackMono16 &);
|
|
Toshihiro Shimizu |
890ddd |
TSoundTrackP compute(const TSoundTrackStereo16 &);
|
|
Toshihiro Shimizu |
890ddd |
TSoundTrackP compute(const TSoundTrackMono24 &);
|
|
Toshihiro Shimizu |
890ddd |
TSoundTrackP compute(const TSoundTrackStereo24 &);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TSoundTrackP m_st;
|
|
Toshihiro Shimizu |
890ddd |
double m_crossFactor;
|
|
Toshihiro Shimizu |
890ddd |
};
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//------------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TSoundTrackP TSoundTrackCrossFaderOverWrite::compute(const TSoundTrackMono8Signed &src)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
assert(src.getFormat() == m_st->getFormat());
|
|
Toshihiro Shimizu |
890ddd |
return doCrossFadeOverWrite(
|
|
Toshihiro Shimizu |
890ddd |
src, dynamic_cast<tsoundtrackmono8signed *="">(m_st.getPointer()), m_crossFactor);</tsoundtrackmono8signed>
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//------------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TSoundTrackP TSoundTrackCrossFaderOverWrite::compute(const TSoundTrackStereo8Signed &src)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
assert(src.getFormat() == m_st->getFormat());
|
|
Toshihiro Shimizu |
890ddd |
return doCrossFadeOverWrite(
|
|
Toshihiro Shimizu |
890ddd |
src, dynamic_cast<tsoundtrackstereo8signed *="">(m_st.getPointer()), m_crossFactor);</tsoundtrackstereo8signed>
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//------------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TSoundTrackP TSoundTrackCrossFaderOverWrite::compute(const TSoundTrackMono8Unsigned &src)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
assert(src.getFormat() == m_st->getFormat());
|
|
Toshihiro Shimizu |
890ddd |
return doCrossFadeOverWrite(
|
|
Toshihiro Shimizu |
890ddd |
src, dynamic_cast<tsoundtrackmono8unsigned *="">(m_st.getPointer()), m_crossFactor);</tsoundtrackmono8unsigned>
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//------------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TSoundTrackP TSoundTrackCrossFaderOverWrite::compute(const TSoundTrackStereo8Unsigned &src)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
assert(src.getFormat() == m_st->getFormat());
|
|
Toshihiro Shimizu |
890ddd |
return doCrossFadeOverWrite(
|
|
Toshihiro Shimizu |
890ddd |
src, dynamic_cast<tsoundtrackstereo8unsigned *="">(m_st.getPointer()), m_crossFactor);</tsoundtrackstereo8unsigned>
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//------------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TSoundTrackP TSoundTrackCrossFaderOverWrite::compute(const TSoundTrackMono16 &src)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
assert(src.getFormat() == m_st->getFormat());
|
|
Toshihiro Shimizu |
890ddd |
return doCrossFadeOverWrite(
|
|
Toshihiro Shimizu |
890ddd |
src, dynamic_cast<tsoundtrackmono16 *="">(m_st.getPointer()), m_crossFactor);</tsoundtrackmono16>
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//------------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TSoundTrackP TSoundTrackCrossFaderOverWrite::compute(const TSoundTrackStereo16 &src)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
assert(src.getFormat() == m_st->getFormat());
|
|
Toshihiro Shimizu |
890ddd |
return doCrossFadeOverWrite(
|
|
Toshihiro Shimizu |
890ddd |
src, dynamic_cast<tsoundtrackstereo16 *="">(m_st.getPointer()), m_crossFactor);</tsoundtrackstereo16>
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//------------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TSoundTrackP TSoundTrackCrossFaderOverWrite::compute(const TSoundTrackMono24 &src)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
assert(src.getFormat() == m_st->getFormat());
|
|
Toshihiro Shimizu |
890ddd |
return doCrossFadeOverWrite(
|
|
Toshihiro Shimizu |
890ddd |
src, dynamic_cast<tsoundtrackmono24 *="">(m_st.getPointer()), m_crossFactor);</tsoundtrackmono24>
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//------------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TSoundTrackP TSoundTrackCrossFaderOverWrite::compute(const TSoundTrackStereo24 &src)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
assert(src.getFormat() == m_st->getFormat());
|
|
Toshihiro Shimizu |
890ddd |
return doCrossFadeOverWrite(
|
|
Toshihiro Shimizu |
890ddd |
src, dynamic_cast<tsoundtrackstereo24 *="">(m_st.getPointer()), m_crossFactor);</tsoundtrackstereo24>
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//------------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TSoundTrackP TSop::crossFade(double crossFactor,
|
|
Toshihiro Shimizu |
890ddd |
const TSoundTrackP src1, const TSoundTrackP src2)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
TSoundTrackCrossFaderOverWrite *fader = new TSoundTrackCrossFaderOverWrite(src2, crossFactor);
|
|
Toshihiro Shimizu |
890ddd |
TSoundTrackP out = src1->apply(fader);
|
|
Toshihiro Shimizu |
890ddd |
delete fader;
|
|
Toshihiro Shimizu |
890ddd |
return out;
|
|
Toshihiro Shimizu |
890ddd |
}
|