windows - Lossless reading from mic -



windows - Lossless reading from mic -

i'm using naudio (but applies reading directly) capture microphone wave data. seems if app busy drops/skips input info mic.

i've set reading thread top priority, i'm doing heavy calculations in several other thread @ same time.

is there way read info lossless? (or lossless, , bug elsewhere?)

when making similar app , had similar problem, turned out needed buffer can hold @ to the lowest degree 3 seconds of data. seek increment buffer 10 seconds of info , if doesn't solve problem there more issues. if works seek decreasing buffer size until works properly

edit: here quick & dirty managed dx recording try.

public class bmsrecordingeventargs : eventargs { byte[] data; bool endrec; public bmsrecordingeventargs(byte[] data, bool endrec) { this.data = data; this.endrec = endrec; } public byte[] info { { homecoming data; } } public bool endrec { { homecoming endrec; } } } public class audiorecorder { public delegate void datareceivedhandler(object sender, bmsrecordingeventargs e); public event datareceivedhandler datareceivedhandle; public const int capture_buffer_size = 32000; dxs.capture dxscapdev; dxs.capturebuffer dxscapbuffer; dxs.capturebufferdescription dxscapbufferdesc; system.threading.thread thrdcapturingthread; dxs.bufferpositionnotify[] dxsbpna; private volatile bool stoprec; system.threading.manualresetevent mrestillrunning = new system.threading.manualresetevent(false); dxs.bufferpositionnotify dxsbpnhalf; dxs.bufferpositionnotify dxsbpnfull; dxs.notify notify; system.threading.autoresetevent are; public audiorecorder(guid deviceguid,dxs.waveformat wfwaveformat,dxs.captureeffectdescription[] dxscapeffectdesc) { dxscapdev = new microsoft.directx.directsound.capture(deviceguid); dxscapbufferdesc = new microsoft.directx.directsound.capturebufferdescription(); dxscapbufferdesc.bufferbytes = capture_buffer_size; dxscapbufferdesc.format = wfwaveformat; dxscapbufferdesc.wavemapped = true; dxscapbufferdesc.captureeffectdescription = dxscapeffectdesc; dxscapbufferdesc.controleffects = true; dxscapbuffer = new microsoft.directx.directsound.capturebuffer(dxscapbufferdesc, dxscapdev); = new system.threading.autoresetevent(false); dxsbpnhalf = new microsoft.directx.directsound.bufferpositionnotify(); dxsbpnfull = new microsoft.directx.directsound.bufferpositionnotify(); dxsbpnhalf.offset = capture_buffer_size / 2 - 1; dxsbpnfull.offset = capture_buffer_size-1; dxsbpnfull.eventnotifyhandle = are.safewaithandle.dangerousgethandle(); dxsbpnhalf.eventnotifyhandle = are.safewaithandle.dangerousgethandle(); dxsbpna = new microsoft.directx.directsound.bufferpositionnotify[2]; dxsbpna[0] = dxsbpnhalf; dxsbpna[1] = dxsbpnfull; notify = new microsoft.directx.directsound.notify(dxscapbuffer); notify.setnotificationpositions(dxsbpna); } public void startrecording() { if (thrdcapturingthread != null) throw new exception("already recording !"); stoprec = false; thrdcapturingthread = new system.threading.thread(record); thrdcapturingthread.start(); } private void record() { datareceivedhandler drh2 = datareceivedhandle; dxscapbuffer.start(true); byte[] tempbaf = new byte[capture_buffer_size / 2]; int startingoffset = 0; while (dxscapbuffer.capturing && !stoprec) { are.waitone(-1,false); startingoffset %= capture_buffer_size; tempbaf = (byte[])dxscapbuffer.read(startingoffset, typeof(byte), microsoft.directx.directsound.lockflag.fromwritecursor, capture_buffer_size / 2); startingoffset += tempbaf.length; if (drh2 != null) drh2(this, new bmsrecordingeventargs(tempbaf, false)); } dxscapbuffer.stop(); if (drh2 != null) drh2(this, new bmsrecordingeventargs(tempbaf, true)); mrestillrunning.set(); } public void stoprecording() { stoprec = true; mrestillrunning.waitone(-1,false); thrdcapturingthread = null; } }

windows audio naudio wave

Comments

Popular posts from this blog

iphone - Dismissing a UIAlertView -

intellij idea - Update external libraries with intelij and java -

javascript - send data from a new window to previous window in php -