그래서 내가 (날카로운 내 능력의 일부를 유지하기 위해) 대학 지정 작업을 즐길 정적 소음을 가지고 있으며, 나는이 하나 해결하기로 결정했습니다 : 나는 실행 해요내 다이렉트 사운드 버퍼는
http://introcs.cs.princeton.edu/java/assignments/dsp.html
MSVS2015을 C#/Console 응용 프로그램과 SharpDX 패키지를 사용하면 일부 기본 DirectSound 기능에 액세스 할 수 있습니다. 저는 첫 번째 예제에서 2 초 음표 'A'를 만들고 연주하려고합니다. 다음 코드를 실행하면 2 초가 걸리지 만 매우 정적입니다. 나는 내 계산으로 무언가가 있다고 가정하고 있지만 정확히 무엇이 있는지를 알 수는 없다. 누구나 자신의 디지털 사운드 버퍼를 작성하는 경험이 있습니까?
감사 - 제프
public class Execution : IDisposable
{
IntPtr Handle;
DirectSound Device;
SecondarySoundBuffer Buffer;
public Execution()
{
Handle = System.Diagnostics.Process.GetCurrentProcess().MainWindowHandle;
Device = new DirectSound();
Device.SetCooperativeLevel(Handle, CooperativeLevel.Priority);
var rate = 44100;
var bits = 16;
var channels = 1;
var waveFormat = new WaveFormat(rate, bits, channels);
// Create a buffer with 2 seconds of sample data
var seconds = 2;
var bufferDescription = new SoundBufferDescription() { Format = waveFormat, BufferBytes = waveFormat.AverageBytesPerSecond * seconds };
Buffer = new SecondarySoundBuffer(Device, bufferDescription);
var noteFrequency = 440f; // A
var bufferData = new float[bufferDescription.BufferBytes];
var count = 0;
for (var sample = 0; sample < bufferDescription.BufferBytes; sample++)
{
var sampleInSeconds = (float)sample/(float)bufferDescription.BufferBytes * (float)seconds;
var value = (float)Math.Sin(2f * Math.PI * noteFrequency * sampleInSeconds);
bufferData[sample] = value;
}
Buffer.Write(bufferData, 0, LockFlags.EntireBuffer);
}
public void Execute()
{
Buffer.Play(0, 0);
}
public void Dispose()
{
Buffer.Dispose();
Device.Dispose();
}
}