本文整理汇总了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[][]
{
//.........这里部分代码省略.........
示例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;
}