Acord.NET - peace098beat/windows_applicaciton GitHub Wiki
信号処理
Signalクラス
http://accord-framework.net/docs/html/T_Accord_Audio_Signal.htm
// create an empty audio signal
Signal signal = new Signal( channels, length, sampleRate, format );
Copy
float[,] data =
{
{ 0.00f, 0.2f },
{ 0.32f, 0.1f },
{ 0.22f, 0.2f },
{ 0.12f, 0.42f },
{ -0.12f, 0.1f },
{ -0.22f, 0.2f },
};
// or create an audio signal from an array of audio frames
Signal target = Signal.FromArray(data, sampleRate: 8000);
WaveFileAudioSourceクラス
http://accord-framework.net/docs/html/T_Accord_DirectSound_WaveFileAudioSource.htm
// Create the Wave file audio source
WaveFileAudioSource source = new WaveFileAudioSource("audiofile.wav");
// Specify the callback function which will be
// called once a sample is completely available
source.NewFrame += source_NewFrame;
// Start capturing
source.Start();
// ...
// The callback function should determine what
// should be done with the samples being caught
private void source_NewFrame(object sender, NewFrameEventArgs eventArgs)
{
// Read current frame...
Signal s = eventArgs.Signal;
// Process/play/record it
// ...
}
WaveDecoder Classクラス
Complex Signal Class
http://accord-framework.net/docs/html/T_Accord_Audio_ComplexSignal.htm
// Create complex audio signal
ComplexSignal complexSignal = ComplexSignal.FromSignal( signal );
// Do forward Fourier transformation
complexSignal.ForwardFourierTransform( );
// Generate spectrogram
complexSignal.ToBitmap(512,512);
However, if your signal is too lengthy, or if your signal is not yet in a power of two size, you can use a temporal window to slice your signal into smaller cuts, as shown below. In the example, an audio file is being read and its contents are being decoded and stored into a Signal object. Afterwards, an audio window is being used to cut the signal into smaller, power-of-two size signals which can then be transformed into the frequency (Fourier) domain. Copy
string fileName = "audio.wav";
WaveDecoder sourceDecoder = new WaveDecoder(fileName);
// Decode the file and store into a signal
Signal sourceSignal = sourceDecoder.Decode();
// Create Hamming window so that signal will fit into power of 2:
RaisedCosineWindow window = RaisedCosineWindow.Hamming(1024);
// Splits the source signal by walking each 512 samples, then creating
// a 1024 sample window. Note that this will result in overlapped windows.
Signal[] windows = sourceSignal.Split(window, 512);
// You might need to import Accord.Math in order to call this:
ComplexSignal[] complex = windows.Apply(ComplexSignal.FromSignal);
// Forward to the Fourier domain
complex.ForwardFourierTransform();