我正在编写一些以不同速度播放WAV文件的代码,因此波浪要么慢,要么低音,要么更快,音高更高.我目前正在使用简单的线性插值,如下所示:
int newlength = (int)Math.Round(rawdata.Length * lengthMultiplier);
float[] output = new float[newlength];
for (int i = 0; i < newlength; i++)
{
float realPos = i / lengthMultiplier;
int iLow = (int)realPos;
int iHigh = iLow + 1;
float remainder = realPos - (float)iLow;
float lowval = 0;
float highval = 0;
if ((iLow >= 0) && (iLow < rawdata.Length))
{
lowval = rawdata[iLow];
}
if ((iHigh >= 0) && (iHigh < rawdata.Length))
{
highval = rawdata[iHigh];
}
output[i] = …Run Code Online (Sandbox Code Playgroud) 我目前已经获得了关于如何重新采样音频数据以增加音调的赏金。
人们已经提出了许多解决方案,但我不得不承认,我对这些选择和信息感到有点不知所措。
我被引导到这个解决方案并找到了这段代码:
public static float InterpolateCubic(float x0, float x1, float x2, float x3, float t)
{
float a0, a1, a2, a3;
a0 = x3 - x2 - x0 + x1;
a1 = x0 - x1 - a0;
a2 = x2 - x0;
a3 = x1;
return (a0 * (t * t * t)) + (a1 * (t * t)) + (a2 * t) + (a3);
}
public static float InterpolateHermite4pt3oX(float x0, float x1, float x2, …Run Code Online (Sandbox Code Playgroud)