private void waveOutProc(IntPtr hwi, int uMsg, int dwInstance, ref WAVEHDR hdr, int dwParam2) { switch (uMsg) { case WOM_OPEN: break; case WOM_DONE: try { this.CheckError(waveOutUnprepareHeader(m_out, ref hdr, Marshal.SizeOf(typeof(WAVEHDR)))); m_pos = hdr.dwUser; hdr.dwBytesRecorded = 0; } catch (AVException e) { m_running = false; if (this.WaveOutError != null) { this.WaveOutError(this, e); } } break; case WOM_CLOSE: break; } }
private void AddBuffer(ref WAVEHDR hdr) { hdr.dwBytesRecorded = 0; hdr.dwFlags = 0; hdr.lpNext = 0; hdr.reserved = 0; CheckError(waveInPrepareHeader(m_in, ref hdr, Marshal.SizeOf(hdr))); CheckError(waveInAddBuffer(m_in, ref hdr, System.Runtime.InteropServices.Marshal.SizeOf(typeof(WAVEHDR)))); }
public WaveOut(int index, WAVEFORMATEX format, int buffersize, int buffer_count) //波形输出 { this.m_fmt = format; this.m_outdex = index; m_buffersize = buffersize; m_outcb = new waveProc(this.waveOutProc); Debug.Assert(buffer_count > 0 && buffer_count < 65535); this.m_hs = new WAVEHDR[buffer_count]; this.gchs = new GCHandle[buffer_count]; for (int i = 0; i < buffer_count; i++) { gchs[i] = GCHandle.Alloc(new byte[buffersize], GCHandleType.Pinned); WAVEHDR hdr = new WAVEHDR(); hdr.dwBufferLength = buffersize; hdr.lpData = this.gchs[i].AddrOfPinnedObject(); hdr.dwUser = i; this.m_hs[i] = hdr; } CheckError(waveOutOpen(ref m_out, m_outdex, ref m_fmt, m_outcb, 0, 0x00030000)); }
public WaveOut(int index,WAVEFORMATEX format,int buffersize,int buffer_count)//波形输出 { this.m_fmt=format; this.m_outdex=index; m_buffersize=buffersize; m_outcb=new waveProc(this.waveOutProc); Debug.Assert(buffer_count>0 && buffer_count<65535); this.m_hs=new WAVEHDR[buffer_count]; this.gchs=new GCHandle[buffer_count]; for(int i=0;i<buffer_count;i++) { gchs[i]=GCHandle.Alloc(new byte[buffersize],GCHandleType.Pinned); WAVEHDR hdr=new WAVEHDR(); hdr.dwBufferLength=buffersize; hdr.lpData=this.gchs[i].AddrOfPinnedObject(); hdr.dwUser=i; this.m_hs[i]=hdr; } CheckError(waveOutOpen(ref m_out,m_outdex,ref m_fmt,m_outcb,0,0x00030000)); }
private void waveInProc(IntPtr hwi, int uMsg, int dwInstance, ref WAVEHDR hdr, int dwParam2) { switch (uMsg) { case WIM_OPEN: break; case WIM_DATA: try { CheckError(waveInUnprepareHeader(m_in, ref hdr, Marshal.SizeOf(typeof(WAVEHDR)))); // AddBuffer(ref hdr); if (this.m_running) { if (this.WaveCaptured != null) { this.WaveCaptured(this, hdr); } this.AddBuffer(ref hdr); } } catch (AVException e) { m_running = false; if (this.WaveInError != null) { this.WaveInError(this, e); } } catch (System.Exception ex) { System.Windows.Forms.MessageBox.Show(ex.Message + ":" + ex.StackTrace); this.m_running = false; } break; case WIM_CLOSE: break; } }
public WaveIn(int index,WAVEFORMATEX format,int buffersize,int buffer_count) { this.m_fmt=format; this.m_index=index; m_incb=new waveProc(this.waveInProc); Debug.Assert(buffer_count>0 && buffer_count<65535); this.m_hs=new WAVEHDR[buffer_count]; this.gchs=new GCHandle[buffer_count]; // this.datas=new IntPtr[buffer_count]; for(int i=0;i<buffer_count;i++) { gchs[i]=GCHandle.Alloc(new byte[buffersize],GCHandleType.Pinned); // this.datas[i]=Marshal.AllocCoTaskMem(buffer_count); WAVEHDR hdr=new WAVEHDR(); hdr.dwBufferLength=buffersize; hdr.lpData=this.gchs[i].AddrOfPinnedObject(); hdr.dwUser=i; this.m_hs[i]=hdr; } CheckError(waveInOpen(ref m_in,m_index,ref m_fmt,m_incb,0,0x00030000)); CheckError(waveInStart(m_in)); }
public WaveIn(int index, WAVEFORMATEX format, int buffersize, int buffer_count) { this.m_fmt = format; this.m_index = index; m_incb = new waveProc(this.waveInProc); Debug.Assert(buffer_count > 0 && buffer_count < 65535); this.m_hs = new WAVEHDR[buffer_count]; this.gchs = new GCHandle[buffer_count]; // this.datas=new IntPtr[buffer_count]; for (int i = 0; i < buffer_count; i++) { gchs[i] = GCHandle.Alloc(new byte[buffersize], GCHandleType.Pinned); // this.datas[i]=Marshal.AllocCoTaskMem(buffer_count); WAVEHDR hdr = new WAVEHDR(); hdr.dwBufferLength = buffersize; hdr.lpData = this.gchs[i].AddrOfPinnedObject(); hdr.dwUser = i; this.m_hs[i] = hdr; } CheckError(waveInOpen(ref m_in, m_index, ref m_fmt, m_incb, 0, 0x00030000)); CheckError(waveInStart(m_in)); }
private void AddBuffer(ref WAVEHDR hdr) { hdr.dwBytesRecorded=0; hdr.dwFlags=0; hdr.lpNext=0; hdr.reserved=0; CheckError(waveInPrepareHeader(m_in,ref hdr,Marshal.SizeOf(hdr))); CheckError(waveInAddBuffer(m_in,ref hdr,System.Runtime.InteropServices.Marshal.SizeOf(typeof(WAVEHDR)))); }
private extern static int waveOutWrite(IntPtr hwo,ref WAVEHDR pwh,int cbwh);
private extern static int waveOutUnprepareHeader(IntPtr hwo,ref WAVEHDR pwh,int cbwh);
private void waveOutProc(IntPtr hwi,int uMsg,int dwInstance,ref WAVEHDR hdr,int dwParam2) { switch(uMsg) { case WOM_OPEN: break; case WOM_DONE: try { this.CheckError(waveOutUnprepareHeader(m_out,ref hdr,Marshal.SizeOf(typeof(WAVEHDR)))); m_pos=hdr.dwUser; hdr.dwBytesRecorded=0; } catch(AVException e) { m_running=false; if(this.WaveOutError!=null)this.WaveOutError(this,e); } break; case WOM_CLOSE: break; } }
private void waveInProc(IntPtr hwi,int uMsg,int dwInstance,ref WAVEHDR hdr,int dwParam2) { switch(uMsg) { case WIM_OPEN: break; case WIM_DATA: try { CheckError(waveInUnprepareHeader(m_in,ref hdr,Marshal.SizeOf(typeof(WAVEHDR)))); // AddBuffer(ref hdr); if(this.m_running) { if(this.WaveCaptured!=null)this.WaveCaptured(this,hdr); this.AddBuffer(ref hdr); } } catch(AVException e) { m_running=false; if(this.WaveInError!=null)this.WaveInError(this,e); } catch(System.Exception ex) { System.Windows.Forms.MessageBox.Show(ex.Message+":"+ex.StackTrace); this.m_running=false; } break; case WIM_CLOSE: break; } }
private extern static int waveInAddBuffer( IntPtr hwi,ref WAVEHDR pwh, int cbwh);
private extern static int waveInPrepareHeader( IntPtr hwi,ref WAVEHDR pwh, int cbwh);
private extern static int waveInPrepareHeader(IntPtr hwi, ref WAVEHDR pwh, int cbwh);
private extern static int waveOutWrite(IntPtr hwo, ref WAVEHDR pwh, int cbwh);
private extern static int waveOutUnprepareHeader(IntPtr hwo, ref WAVEHDR pwh, int cbwh);
private extern static int waveInAddBuffer(IntPtr hwi, ref WAVEHDR pwh, int cbwh);