/// <summary> /// Pequeno teste conceitual utilizando a placa de som padrao /// </summary> public void teste() { Capture cap = new Capture(new DeviceInformation().DriverGuid); CaptureBufferDescription desc = new CaptureBufferDescription(); CaptureBuffer buffer; WaveFormat wf = new WaveFormat(); wf.BitsPerSample = 16; wf.SamplesPerSecond = 44100; wf.Channels = 2; wf.BlockAlign = (short)(wf.Channels * wf.BitsPerSample / 8); wf.AverageBytesPerSecond = wf.BlockAlign * wf.SamplesPerSecond; wf.FormatTag = WaveFormatTag.Pcm; desc.Format = wf; desc.BufferBytes = SAMPLES * wf.BlockAlign; buffer = new Microsoft.DirectX.DirectSound.CaptureBuffer(desc, cap); buffer.Start(true); zed: Array samples = buffer.Read(0, typeof(Int16), LockFlag.FromWriteCursor, SAMPLE_FORMAT_ARRAY); System.Console.WriteLine(samples.GetValue(0, 0, 0).ToString()); goto zed; }
private void UpdateSignal() { while (true) { int TempFrameDelay = mFrameDelay; int TempSampleDelay = mSampleDelay; int LevelMax = 0; try { Array SampleArray = mAudioBuffer.Read(0, typeof(Int16), LockFlag.FromWriteCursor, mSampleFormatArray); for (int i = 0; i < mSamples; i++) { LevelMax += (int)Math.Abs((Int16)SampleArray.GetValue(i, 0, 0)); LevelMax += (int)Math.Abs((Int16)SampleArray.GetValue(i, 1, 0)); } } catch { LevelMax = 0; } Console.WriteLine(LevelMax); LevelMax = LevelMax / (2 * mSamples); double dbl = Int16.MaxValue / 100; double preciselvl = LevelMax / dbl; int level = (int)preciselvl; // Console.WriteLine(" >> "+level ); if (level > 100) { level = 100; } if (OnVolumeChanged != null) { OnVolumeChanged(level); } /*double LedIncrement = Int16.MaxValue / totalLeds; * * //double AbsLeftStepSize = Math.Abs(LeftStepSize); * //double AbsRightStepSize = Math.Abs(RightStepSize); * * double preciseLeftLevel = LeftMax / LedIncrement; * double preciseRightLevel = RightMax / LedIncrement; * * leftLevel = (int)preciseLeftLevel; * rightLevel = (int)preciseRightLevel; * * UpdateLevel(leftLevel, rightLevel);*/ System.Threading.Thread.Sleep(mSampleDelay); } }