本文整理汇总了C#中Frame.ToArray方法的典型用法代码示例。如果您正苦于以下问题:C# Frame.ToArray方法的具体用法?C# Frame.ToArray怎么用?C# Frame.ToArray使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Frame
的用法示例。
在下文中一共展示了Frame.ToArray方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Fft
/**
* Calculates FFT of a signal frame using radix-2 algorithm.
*
* Input data is given as a pointer to Frame object.
* Output spectrum is written to the spectrum vector, which must be
* initialized prior to the call to fft(). The spectrum is
* normalized by N/2, wher N is input frame length (zero-padded).
* The method returns maximum magnitude of the calculated spectrum,
* which can be used for example to scale a frequency plot.
*
* @param frame pointer to Frame object
* @param spectrum initialized complex vector of the same length as data
* @return maximum magnitude of the spectrum
* @since 2.0.1
*/
public double Fft(Frame frame, ref Complex[] spectrum)
{
// the vector is initialized to zero padded length,
// what means that it contains default values of contained type
// (0.0 in case of double); that allows us to loop
// only to frame length without padding and
// automatically have zeros at the end of data
double[] data = new double[zeroPaddedLength];
int length = frame.GetLength();
short[] frameArray = frame.ToArray();
// first sample does not need preemphasis
data[0] = frameArray[0];
double current = 0.0;
double previous = data[0];
// iterate over all samples of the frame
// filter the data through preemphasis
// and apply a chosen window function
// The goal of pre-emphasis is to compensate the high-frequency part
// that was suppressed during the sound production mechanism of humans.
// Moreover, it can also amplify the importance of high-frequency formants.
// It's not neccesary for only music, but important for speech
// (Set to 0 if no pre-emphasis should be performed)
for (int n = 1; n < length; n++)
{
current = frameArray[n];
data[n] = (current - preemphasisFactor * previous) * Window.Apply(winType, n, length);
previous = current;
}
return Fft(data, ref spectrum);
}