potom som si k nim spravil triedu
Kód: Vybrať všetko
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Collections.Specialized;
using System.Linq;
using System.Text;
using System.Threading;
using Microsoft.DirectX.DirectSound;
namespace zvuk
{
class CaptureCis
{
protected static CaptureCis instancia = null;
public static CaptureCis GetInstance() // vzor Singlton
{
if (instancia == null) instancia = new CaptureCis();
return instancia;
}
const int Samples = 8;
WaveFormat wfr;
Capture cap;
CaptureBufferDescription desc;
CaptureBuffer buff;
private CaptureCis()
{
this.wfr = new Microsoft.DirectX.DirectSound.WaveFormat();
this.wfr.SamplesPerSecond = 95000;
this.wfr.BitsPerSample = 16;
this.wfr.Channels = 2;
this.wfr.FormatTag = WaveFormatTag.Pcm;
// toto je vzdy
const int NUM_BUFERS=2;
this.wfr.BlockAlign=(short) (this.wfr.Channels* (this.wfr.BitsPerSample/8));
this.wfr.AverageBytesPerSecond = this.wfr.SamplesPerSecond * this.wfr.BlockAlign;
// ale
var CDC = new CaptureDevicesCollection();
this.cap = new Capture(CDC[0].DriverGuid);
this.desc = new Microsoft.DirectX.DirectSound.CaptureBufferDescription();
this.desc.Format = this.wfr;
this.desc.BufferBytes = Samples * this.wfr.BlockAlign;
this.buff = new CaptureBuffer(this.desc, this.cap);
this.buff.Start(true);
}
public void Stop()
{
if (this.buff.Capturing)
{
this.buff.Stop();
this.buff.Dispose();
this.buff = null;
}
}
public int getValue()
{
int[] SAMPLE_FORMAT_ARRAY = { Samples, 2, 1 };
Array pole = this.buff.Read(0, typeof(Int16), LockFlag.FromWriteCursor, SAMPLE_FORMAT_ARRAY);
int vzorkaL = 0;
int vzorkaP = 0;
for (int i = 0; i < Samples; i++)
{
vzorkaL += (Int16)pole.GetValue(i, 0, 0);
vzorkaP += (Int16)pole.GetValue(i, 1, 0);
}
return (vzorkaL + vzorkaP) / (2*Samples);
}
}
}
Kód: Vybrať všetko
DLL 'C:\Documents and Settings\-\My Documents\Visual Studio 2008\Projects\_WinSSH\zvuk\zvuk\bin\Debug\Microsoft.DirectX.DirectSound.dll' is attempting managed execution inside OS Loader lock. Do not attempt to run managed code inside a DllMain or image initialization function since doing so can cause the application to hang.