I am working on speech synthesis with LPC and I originally implemented a pre-emphasis filter:
+(void)processBuffer:(Buffer *)buffer {
float alpha = -0.9375f;
for (int i = 1; i < buffer.size; i++) {
buffer.samples[i] += buffer.samples[i - 1] * alpha;
}
}
And found that my output audio was distorting, so I adding some code to scale the values, and so now it looks like this:
+(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;
}
I am finding that the speech I am generating still doesn't sound very good, and so I am just wondering if my implementation for this filter is ok? Does anyone see anything I am doing wrong or does this look ok?