Exemplo n.º 1
0
        public void ThreadRun()
        {
            try
            {
                m_stream.Start(Convert.ToInt32(wavDataProvider.SampleRate));
                int nSamples = Convert.ToInt32(wavDataProvider.SampleRate / 50);
                do
                {
                    System.Runtime.InteropServices.ComTypes.IStream strm = wavDataProvider.GetNextAudioChunk(nSamples);
                    if (null == strm)
                    {
                        break;
                    }
                    while (false == PushSamples(strm))
                    {
                        Thread.Sleep(20);
                    }

                    System.Runtime.InteropServices.Marshal.FinalReleaseComObject(strm);
                    strm = null;
                } while (wavDataProvider.HasMoreData);
            }
            catch (COMException)
            {
            }
            m_stream.Stop();
            AllDataWritten.Invoke(this, null);
        }
        private void WriteTotal()
        {
            if (Valid)
            {
                Valid = false;
                bw.Seek(4, System.IO.SeekOrigin.Begin);
                bw.Write(BitConverter.GetBytes(m_totalsamplecount * 2 + 36), 0, 4);
                bw.Seek(32, System.IO.SeekOrigin.Current);
                bw.Write(BitConverter.GetBytes(m_totalsamplecount * 2), 0, 4);
                bw.Flush();
                bw.Close();
                if (AllDataWritten != null)
                {
                    System.Diagnostics.Debug.WriteLine("Audio msg saved to file in thread " + System.Threading.Thread.CurrentThread.ManagedThreadId.ToString());

                    AllDataWritten.Invoke(this, null);
                }
            }
        }