Пример #1
0
 static public void startrecoding()
 {
     try {
         WinMM.memStream  = new MemoryStream();
         WinMM.waveStream = new MemoryStream();
         WinMM.bytesread  = 0;
         WinMM.waveformat = new WaveFormat(44100, 16, 2);
         BE_CONFIG _mp3config = new BE_CONFIG(waveformat);
         WinMM._mp3writer        = new Mp3Writer(memStream, waveformat, _mp3config);
         WinMM.recording         = true;
         WinMM._trd              = new Thread(WinMM.wavtomp3);
         WinMM._trd.IsBackground = true;
         WinMM._trd.Start();
         WinMM.ThrowExceptionForError(WinMM.waveInOpen(out WinMM.phwi, 0, WinMM.waveformat, WinMM.callbackm, IntPtr.Zero, WinMM.WaveOpenFlags.Function));
         int buffsize = WinMM.waveformat.AverageBytesPerSecond / 100;
         for (int i = 0; i < WinMM.buffers.Length; i++)
         {
             WinMM.buffers[i]                = new WinMM.WaveHdr();
             WinMM.buffers[i].lpData         = Marshal.AllocHGlobal(buffsize);
             WinMM.buffers[i].dwBufferLength = buffsize;
             WinMM.buffers[i].dwUser         = IntPtr.Zero;
             WinMM.buffers[i].dwFlags        = WinMM.WHDR.None;
             WinMM.buffers[i].dwLoops        = 0;
             WinMM.buffers[i].lpNext         = IntPtr.Zero;
             WinMM.buffers[i].reserved       = IntPtr.Zero;
             WinMM.unmanagedHeaders[i]       = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(WinMM.WaveHdr)));
             Marshal.StructureToPtr(WinMM.buffers[i], WinMM.unmanagedHeaders[i], false);
             WinMM.ThrowExceptionForError(WinMM.waveInPrepareHeader(WinMM.phwi, WinMM.unmanagedHeaders[i], Marshal.SizeOf(typeof(WinMM.WaveHdr))));
             WinMM.ThrowExceptionForError(WinMM.waveInAddBuffer(WinMM.phwi, WinMM.unmanagedHeaders[i], Marshal.SizeOf(typeof(WinMM.WaveHdr))));
         }
         WinMM.ThrowExceptionForError(WinMM.waveInStart(WinMM.phwi));
     }
     catch (Exception e)
     {
         throw e;
     }
 }
Пример #2
0
 public void Dispose()
 {
     WinMM.stoprecording();
     Thread.Sleep(50);
     WinMM._trd.Abort();
 }
Пример #3
0
 public WinMM(bool microphone = false)
 {
     WinMM.startrecoding();
 }