Ejemplo n.º 1
0
        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];
                }
            }
        }
Ejemplo n.º 2
0
        public void Estimate(double[] x, int fs, double[] temporalPositions, double[] f0, int f0Length, int fftSize, double[][] aperiodicity)
        {
            aperiodicity.ForEach((a) => a.Fill(1.0 - SafeGuardMinimum));

            var fftSizeD4C = (int)Math.Pow(2.0, 1.0 + (int)MathUtil.Log2(4.0 * fs / FloorF0D4C + 1.0));

            var forwardRealFFT = ForwardRealFFT.Create(fftSizeD4C);

            var numberOfAperiodicities = (int)(Math.Min(UpperLimit, fs / 2.0 - FrequencyInterval) / FrequencyInterval);

            // Since the window function is common in D4CGeneralBody(),
            // it is designed here to speed up.
            var windowLength = (int)(FrequencyInterval * fftSizeD4C / fs) * 2 + 1;
            var window       = new double[windowLength];

            Common.NuttallWindow(windowLength, window);

            // D4C Love Train (Aperiodicity of 0 Hz is given by the different algorithm)
            var aperiodicity0 = new double[f0Length];

            D4CLoveTrain(x, fs, f0, f0Length, temporalPositions, aperiodicity0);

            var coarseAperiodicity = new double[numberOfAperiodicities + 2];

            coarseAperiodicity[0] = -60.0;
            coarseAperiodicity[numberOfAperiodicities + 1] = -SafeGuardMinimum;
            var coarseFrequencyAxis = Enumerable.Range(0, numberOfAperiodicities + 2).Select((i) => i * FrequencyInterval).ToArray();

            coarseFrequencyAxis[numberOfAperiodicities + 1] = fs / 2.0;

            var frequencyAxis = Enumerable.Range(0, fftSize / 2 + 1).Select((i) => (double)i * fs / fftSize).ToArray();

            for (var i = 0; i < f0Length; i++)
            {
                if (f0[i] == 0.0 || aperiodicity0[i] <= Threshold)
                {
                    continue;
                }

                D4CGeneralBody(x, fs, Math.Max(FloorF0D4C, f0[i]), fftSizeD4C, temporalPositions[i], numberOfAperiodicities, window, forwardRealFFT, coarseAperiodicity.SubSequence(1));

                // Linear interpolation to convert the coarse aperiodicity into its
                // spectral representation.
                GetAperiodicity(coarseFrequencyAxis, coarseAperiodicity, numberOfAperiodicities, frequencyAxis, fftSize, aperiodicity[i]);
            }
        }
Ejemplo n.º 3
0
        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);
        }
Ejemplo n.º 4
0
        public void Estimate(double[] x, int fs, double[] temporalPositions, double[] f0, double[][] spectrogram)
        {
            var f0Floor          = GetF0FloorForCheapTrick(fs, FFTSize);
            var spectralEnvelope = new double[FFTSize];

            var forwardRealFFT = ForwardRealFFT.Create(FFTSize);
            var inverseRealFFT = InverseRealFFT.Create(FFTSize);

            for (var i = 0; i < f0.Length; i++)
            {
                var currentF0 = f0[i] <= f0Floor ? DefaultF0 : f0[i];
                CheapTrickGeneralBody(x, fs, currentF0, temporalPositions[i], forwardRealFFT, inverseRealFFT, spectralEnvelope);

                for (int j = 0, limit = FFTSize / 2; j <= limit; j++)
                {
                    spectrogram[i][j] = spectralEnvelope[j];
                }
            }
        }
Ejemplo n.º 5
0
        //-----------------------------------------------------------------------------
        // D4CLoveTrain() determines the aperiodicity with VUV detection.
        // If a frame was determined as the unvoiced section, aperiodicity is set to
        // very high value as the safeguard.
        // If it was voiced section, the aperiodicity of 0 Hz is set to -60 dB.
        //-----------------------------------------------------------------------------
        void D4CLoveTrain(double[] x, int fs, double[] f0, int f0Length, double[] temporalPositions, double[] aperiodicity0)
        {
            var lowestF0       = 40.0;
            var fftSize        = (int)Math.Pow(2.0, 1.0 + (int)MathUtil.Log2(3.0 * fs / lowestF0 + 1));
            var forwardRealFFT = ForwardRealFFT.Create(fftSize);

            // Cumulative powers at 100, 4000, 7900 Hz are used for VUV identification.
            var boundary0 = (int)Math.Ceiling(100.0 * fftSize / fs);
            var boundary1 = (int)Math.Ceiling(4000.0 * fftSize / fs);
            var boundary2 = (int)Math.Ceiling(7900.0 * fftSize / fs);

            for (var i = 0; i < f0Length; i++)
            {
                if (f0[i] == 0.0)
                {
                    aperiodicity0[i] = 0.0;
                    continue;
                }

                aperiodicity0[i] = D4CLoveTrainSub(x, fs, Math.Max(f0[i], lowestF0), temporalPositions[i], f0Length, fftSize, boundary0, boundary1, boundary2, forwardRealFFT);
            }
        }