當前位置: 首頁>>代碼示例>>C#>>正文


C# Complex.Select方法代碼示例

本文整理匯總了C#中System.Complex.Select方法的典型用法代碼示例。如果您正苦於以下問題:C# Complex.Select方法的具體用法?C# Complex.Select怎麽用?C# Complex.Select使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在System.Complex的用法示例。


在下文中一共展示了Complex.Select方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: DownSample

        public static IEnumerable<float[]> DownSample(IEnumerable<float[]> samplesEnumerator, int numChannels, int windowSize, Action<float[]> highSampleCallback)
        {
            var fft = new MathNet.Numerics.Transformations.ComplexFourierTransformation ();

            var determineVolumeSource = new Complex[windowSize];
            for (var sampleCtr = 0; sampleCtr < windowSize; sampleCtr++)
                determineVolumeSource[sampleCtr] = new Complex(1, 0);

            fft.TransformForward(determineVolumeSource);

            var determineVolumeDestination = new Complex[]
            {
                determineVolumeSource[0],
                Complex.FromModulusArgument(0,0),
                Complex.FromModulusArgument(0,0),
                Complex.FromModulusArgument(0,0)
            };

            fft.TransformBackward(determineVolumeDestination);

            var dcMultiplier = determineVolumeDestination[0].Modulus;

            var ratio = (1d / Convert.ToDouble(windowSize)) * 2d * Math.PI;
            for (var sampleCtr = 0; sampleCtr < windowSize; sampleCtr++)
            {
                var sampleCtrDouble = Convert.ToDouble(sampleCtr);
                determineVolumeSource[sampleCtr] = new Complex(Math.Cos(sampleCtrDouble * ratio), 0);
            }

            fft.TransformForward(determineVolumeSource);

            determineVolumeDestination = new Complex[]
            {
                Complex.FromModulusArgument(0,0),
                determineVolumeSource[1],
                Complex.FromModulusArgument(0,0),
                determineVolumeSource[determineVolumeSource.Length - 1],
            };

            fft.TransformBackward(determineVolumeDestination);

            var midMultiplier = determineVolumeDestination.Select(s => s.Modulus).Max();

            /*// This only works when windowsize is 8
            for (var sampleCtr = 0; sampleCtr < windowSize; sampleCtr++)
            {
                var abs = sampleCtr % 2 == 1 ? 1 : 0;
                var sign = sampleCtr % 4 > 1 ? 1 : -1;
                determineVolumeSource[sampleCtr] = new Complex(abs * sign, 0);
            }*/

            ratio = (1d / Convert.ToDouble(windowSize)) * 4d * Math.PI;
            for (var sampleCtr = 0; sampleCtr < windowSize; sampleCtr++)
            {
                var sampleCtrDouble = Convert.ToDouble(sampleCtr);
                determineVolumeSource[sampleCtr] = new Complex(Math.Cos(sampleCtrDouble * ratio), 0);
            }

            fft.TransformForward(determineVolumeSource);

            determineVolumeDestination = new Complex[]
            {
                Complex.FromModulusArgument(0,0),
                Complex.FromModulusArgument(0,0),
                determineVolumeSource[2],
                Complex.FromModulusArgument(0,0),
            };

            fft.TransformBackward(determineVolumeDestination);

            var highMultiplier = determineVolumeDestination.Select(s => s.Modulus).Max();

            var sampleQueue = new Queue<float[]>();
            for (var sampleCtr = 0; sampleCtr < windowSize / 4; sampleCtr++)
                sampleQueue.Enqueue(new float[numChannels]);

            var maxOriginalSample = 0.0;
            var maxLowFrequencySample = 0.0;

            using (var sampleEnumerator = samplesEnumerator.GetEnumerator())
            {
                int samplesFromSource;

                do
                {
                    samplesFromSource = 0;

                    while (sampleQueue.Count < windowSize)
                    {
                        if (sampleEnumerator.MoveNext())
                        {
                            sampleQueue.Enqueue(sampleEnumerator.Current.ToArray());
                            samplesFromSource++;
                        }
                        else
                            sampleQueue.Enqueue(new float[numChannels]);
                    }

                    var simplified = new float[][]
                    {
//.........這裏部分代碼省略.........
開發者ID:GWBasic,項目名稱:MeasureDegredation,代碼行數:101,代碼來源:SampleRateAdjustor.cs

示例2: ConvertTable

        private static TableInfo ConvertTable(float[][] wavetable, Dictionary<int, int> noteToPartials)
        {
            var partials = noteToPartials.Select(x => x.Value).Distinct().OrderByDescending(x => x).ToList();
            var transform = new Transform(wavetable.First().Length);

            var output = new TableInfo();
            output.MidiToTable = new int[128];
            output.RenderedTable = new float[partials.Count][][];

            Action<int, Complex[]> LimitPartials = (max, data) =>
            {
                for (int i = 0; i < data.Length; i++)
                {
                    if (i > max && (data.Length - i) > max)
                    {
                        data[i].Real = 0;
                        data[i].Imag = 0;
                    }
                }
            };

            for (int partialIndex = 0; partialIndex < partials.Count; partialIndex++)
            {
                var partial = partials[partialIndex];
                noteToPartials.Where(x => x.Value == partial).Select(x => x.Key).Foreach(x => output.MidiToTable[x] = partialIndex);
                output.RenderedTable[partialIndex] = new float[wavetable.Length][];

                for (int tableIndex = 0; tableIndex < wavetable.Length; tableIndex++)
                {
                    var table = wavetable[tableIndex];
                    var input = table.Select(x => new Complex(x, 0)).ToArray();
                    var fft = new Complex[input.Length];
                    var ifft = new Complex[input.Length];
                    transform.FFT(input, fft);
                    LimitPartials(partial, fft);

                    transform.IFFT(fft, ifft);
                    var signal = ifft.Select(x => (float)x.Real).ToArray();

                    output.RenderedTable[partialIndex][tableIndex] = signal;
                }
            }

            return output;
        }
開發者ID:ValdemarOrn,項目名稱:Polyhedrus,代碼行數:45,代碼來源:TableConvert.cs


注:本文中的System.Complex.Select方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。