public void Synthesize(double[] f0, int f0Length, double[][] spectrogram, double[][] aperiodicity, int fftSize, double framePeriod, int fs, double[] y) { var minimumPhase = MinimumPhaseAnalysis.Create(fftSize); var inverseRealFFT = InverseRealFFT.Create(fftSize); var forwardRealFFT = ForwardRealFFT.Create(fftSize); var pulseLocations = new double[y.Length]; var pulseLocationsIndex = new int[y.Length]; var pulseLocationsTimeShift = new double[y.Length]; var interpolatedVUV = new double[y.Length]; var numberOfPulses = GetTimeBase(f0, f0Length, fs, framePeriod / 1000.0, y.Length, fs / fftSize + 1.0, pulseLocations, pulseLocationsIndex, pulseLocationsTimeShift, interpolatedVUV); var dcRemover = GetDCRemover(fftSize); framePeriod /= 1000.0; var impulseResponse = new double[fftSize]; for (var i = 0; i < numberOfPulses; i++) { var noiseSize = pulseLocationsIndex[Math.Min(numberOfPulses - 1, i + 1)] - pulseLocationsIndex[i]; GetOneFrameSegment(interpolatedVUV[pulseLocationsIndex[i]], noiseSize, spectrogram, fftSize, aperiodicity, f0Length, framePeriod, pulseLocations[i], pulseLocationsTimeShift[i], fs, forwardRealFFT, inverseRealFFT, minimumPhase, dcRemover, impulseResponse); for (var j = 0; j < fftSize; j++) { var index = j + pulseLocationsIndex[i] - fftSize / 2 + 1; if (index < 0 || index > y.Length - 1) { continue; } y[index] += impulseResponse[j]; } } }
public SynthesisRealTime(int sampleRate, double framePeriod, int fftSize, int bufferSize, int ringBufferCapacity) { SampleRate = sampleRate; FramePeriod = framePeriod * 0.001; AudioBufferSize = bufferSize; AudioBuffer = new double[bufferSize * 2 + fftSize]; Buffer = new RingBuffer(ringBufferCapacity); FFTSize = fftSize; ImpulseResponse = new double[fftSize]; DCRemover = GetDCRemover(fftSize / 2); RefreshSynthesizer(); MinimumPhase = MinimumPhaseAnalysis.Create(fftSize); InverseRealFFT = InverseRealFFT.Create(fftSize); ForwardRealFFT = ForwardRealFFT.Create(fftSize); }