我正在使用 LPC 进行语音合成,我最初实现了一个预加重滤波器:
+(void)processBuffer:(Buffer *)buffer {
float alpha = -0.9375f;
for (int i = 1; i < buffer.size; i++) {
buffer.samples[i] += buffer.samples[i - 1] * alpha;
}
}
发现我的输出音频失真了,所以我添加了一些代码来缩放值,所以现在看起来像这样:
+(void)processBuffer:(Buffer *)buffer {
float preEnergy = [self energyFor:buffer];
float alpha = -0.9375f;
for (int i = 1; i < buffer.size; i++) {
buffer.samples[i] += buffer.samples[i - 1] * alpha;
}
[self scaleBuffer:buffer preEnergy:preEnergy postEnergy:[self energyFor:buffer]];
}
+(void)scaleBuffer:(Buffer *)buffer preEnergy:(double)preEnergy postEnergy:(double)postEnergy {
float scale = sqrt(preEnergy / postEnergy);
for (int i = 0; i < buffer.size; i++) {
buffer.samples[i] *= scale;
}
}
+(float)energyFor:(Buffer *)buffer {
double sum = 0.0;
for (int i = 0; i < buffer.size; i++) {
sum += buffer.samples[i] * buffer.samples[i];
}
return sum;
}
我发现我正在生成的语音听起来仍然不是很好,所以我只是想知道我对这个过滤器的实现是否可以?有没有人看到我做错了什么或者这看起来不错?