If you think the Android project voicesmith listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
Java Source Code
/*
* Voicesmith <http://voicesmith.jurihock.de/>
*//www.java2s.com
* Copyright (c) 2011-2014 Juergen Hock
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/package de.jurihock.voicesmith.dsp.processors;
importstatic de.jurihock.voicesmith.dsp.Math.PI;
importstatic de.jurihock.voicesmith.dsp.Math.atan2;
importstatic de.jurihock.voicesmith.dsp.Math.cos;
importstatic de.jurihock.voicesmith.dsp.Math.princarg;
importstatic de.jurihock.voicesmith.dsp.Math.sin;
importstatic de.jurihock.voicesmith.dsp.Math.sqrt;
import de.jurihock.voicesmith.Disposable;
/**
* Replaced by the NativeTimescaleProcessor.
* */
@Deprecated
publicfinalclass TimescaleProcessor implements Disposable
{
privatefinalint fftSize;
privatefinalfloat timescaleRatio;
privatefinalfloat[] omegaA;
privatefinalfloat[] omegaS;
privatefinalfloat[] prevPhaseA;
privatefinalfloat[] prevPhaseS;
public TimescaleProcessor(int frameSize, int analysisHopSize, int synthesisHopSize)
{
fftSize = frameSize / 2;
timescaleRatio = (float) synthesisHopSize / (float) analysisHopSize;
omegaA = newfloat[fftSize];
omegaS = newfloat[fftSize];
prevPhaseA = newfloat[fftSize];
prevPhaseS = newfloat[fftSize];
for (int i = 0; i < fftSize; i++)
{
omegaA[i] = 2 * PI * (i / (float) frameSize) // not fftSize!
* (float) analysisHopSize;
omegaS[i] = 2 * PI * (i / (float) frameSize) // not fftSize!
* (float) synthesisHopSize;
}
}
publicvoid processFrame(float[] frame)
{
if (timescaleRatio == 1)
return;
float re, im, abs;
float nextPhaseA, nextPhaseS;
float phaseDeltaA, phaseDeltaS;
for (int i = 1; i < fftSize; i++)
{
// Get source Re and Im parts
re = frame[2 * i];
im = frame[2 * i + 1];
// Compute source phase
nextPhaseA = atan2(im, re);
if (timescaleRatio < 2)
{
// Compute phase deltas
phaseDeltaA = princarg(nextPhaseA - (prevPhaseA[i] + omegaA[i]));
phaseDeltaS = phaseDeltaA * timescaleRatio;
// Compute destination phase
nextPhaseS = princarg((prevPhaseS[i] + omegaS[i]) + phaseDeltaS);
// Save computed phase values
prevPhaseA[i] = nextPhaseA;
prevPhaseS[i] = nextPhaseS;
}
else
{
// Compute destination phase
nextPhaseS = princarg(nextPhaseA * 2);
}
// Compute destination Re and Im parts
abs = sqrt(re * re + im * im);
re = abs * cos(nextPhaseS);
im = abs * sin(nextPhaseS);
// Save new values
frame[2 * i] = re;
frame[2 * i + 1] = im;
}
}
publicvoid dispose()
{
}
}