Пример #1
0
    public double[] synt_noise(Bitmap image, int samplerate)
    {
        int samples = (int)image.Width * samplerate / pixpersec;

        Complex[] noise = GlobalMembersSpectrogram.get_pink_noise(samplerate * 10);        // 10 sec loop

        double     filterscale = ((double)noise.Length * 2) / samplerate;
        Filterbank filterbank  = Filterbank.get_filterbank(frequency_axis, filterscale, basefreq, bandwidth, overlap);

        int top_index = (int)(maxfreq * filterscale);

        double[] @out = new double[samples];

        for (int bandidx = 0; bandidx < image.Height; ++bandidx)
        {
            //if (cancelled())
            //	return List<int>();
            band_progress(bandidx, image.Height - 1);

            // filter noise
            Pair <int, int> range = filterbank.get_band(bandidx);
            //std::cout << bandidx << "/"<<image.height()<<"\n";
            Console.Out.WriteLine("(noise) sample: {0}", range.Second - range.First);

            double[] filtered_noise = new double[noise.Length];
            //std.copy(noise.begin()+range.first, noise.begin()+Math.Min(range.second, top_index), filtered_noise.begin()+range.first);

            // ifft noise
            double[] noise_mod = GlobalMembersSpectrogram.padded_IFFT(filtered_noise);

            // resample spectrogram band
            double[] envelope = GlobalMembersSpectrogram.resample(envelope_from_spectrogram(image, bandidx), samples);

            // modulate with looped noise
            for (uint i = 0; i < samples; ++i)
            {
                @out[i] += envelope[i] * noise_mod[i % noise_mod.Length];
            }
        }

        GlobalMembersSpectrogram.normalize_signal(ref @out);
        return(@out);
    }
Пример #2
0
    public double[] synt_sine(Bitmap image, int samplerate)
    {
        int samples = image.Width * samplerate / pixpersec;

        Complex[] spectrum = new Complex[samples / 2 + 1];

        double filterscale = ((double)spectrum.Length * 2) / samplerate;

        Filterbank filterbank = Filterbank.get_filterbank(frequency_axis, filterscale, basefreq, bandwidth, overlap);

        for (int bandidx = 0; bandidx < image.Height; ++bandidx)
        {
            //if (cancelled())
            //	return List<int>();
            band_progress(bandidx, image.Height - 1);

            double[] envelope = envelope_from_spectrogram(image, bandidx);

            // random phase between +-pi
            double phase = (2 * GlobalMembersSpectrogram.random_double() - 1) * Math.PI;

            double[] bandsignal = new double[envelope.Length * 2];
            for (int j = 0; j < 4; ++j)
            {
                double sine = Math.Cos(j * Math.PI / 2 + phase);
                for (int i = j; i < bandsignal.Length; i += 4)
                {
                    bandsignal[i] = envelope[i / 2] * sine;
                }
            }

            Complex[] filterband = GlobalMembersSpectrogram.padded_FFT(bandsignal);

            for (int i = 0; i < filterband.Length; ++i)
            {
                double x = (double)i / filterband.Length;

                // normalized blackman window antiderivative
                filterband[i] *= x - ((0.5 / (2.0 * Math.PI)) * Math.Sin(2.0 * Math.PI * x) + (0.08 / (4.0 * Math.PI)) * Math.Sin(4.0 * Math.PI * x) / 0.42);
            }

            Console.Out.WriteLine("spectrum size: {0}", spectrum.Length);
            //std::cout << bandidx << ". filterband size: " << filterband.Length << "; start: " << filterbank->get_band(bandidx).first <<"; end: " << filterbank->get_band(bandidx).second << "\n";

            double center = filterbank.get_center(bandidx);
            double offset = Math.Max((uint)0, center - filterband.Length / 2);

            Console.Out.WriteLine("offset: {0} = {1} hz", offset, offset / filterscale);

            for (uint i = 0; i < filterband.Length; ++i)
            {
                if (offset + i > 0 && offset + i < spectrum.Length)
                {
                    spectrum[(int)(offset + i)] += filterband[i];
                }
            }
        }

        double[] @out = GlobalMembersSpectrogram.padded_IFFT(spectrum);

        Console.Out.WriteLine("samples: {0} -> {1}", @out.Length, samples);

        GlobalMembersSpectrogram.normalize_signal(ref @out);
        return(@out);
    }