⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 wavein.cs

📁 本人觉得C#的软件是不需要源代码的
💻 CS
📖 第 1 页 / 共 2 页
字号:
                }
                if (this.m_inited)
                {
                    this.Stop();
                    this.FreeWaveBuffers();
                }
                WaveIn.WAVEINCAPS waveincaps = new WaveIn.WAVEINCAPS();
                WaveIn.waveInGetDevCaps(0, (byte[])waveincaps, waveincaps.Size);
                if ((waveincaps.dwFormats & 2) == 0)
                {
                    return Wave.MMSYSERR.NOTSUPPORTED;
                }
                this.m_wfmt = new Wave.WAVEFORMATEX();
                this.m_wfmt.wFormatTag = 1;
                this.m_wfmt.wBitsPerSample = 8;
                this.m_wfmt.nChannels = 1;
                this.m_wfmt.nSamplesPerSec = 0x2b11;
                this.m_wfmt.nAvgBytesPerSec = (uint)((this.m_wfmt.nSamplesPerSec * this.m_wfmt.nChannels) * (this.m_wfmt.wBitsPerSample / 8));
                this.m_wfmt.nBlockAlign = (ushort)((this.m_wfmt.wBitsPerSample * this.m_wfmt.nChannels) / 8);
                Wave.MMSYSERR mmsyserr = WaveIn.waveInOpen(ref this.m_hwi, curDevice, this.m_wfmt, hwnd, 0, 0x10000);
                if (mmsyserr != Wave.MMSYSERR.NOERROR)
                {
                    return mmsyserr;
                }
                if (bufferSize == 0)
                {
                    return Wave.MMSYSERR.ERROR;
                }
                this.m_bufferSize = (uint)bufferSize;
                if ((this.m_bufferSize % this.m_wfmt.nBlockAlign) != 0)
                {
                    this.m_bufferSize += this.m_wfmt.nBlockAlign - (this.m_bufferSize % this.m_wfmt.nBlockAlign);
                }
                this.m_maxDataLength = (uint)((this.m_wfmt.nAvgBytesPerSec * maxRecordLength_ms) / ((long)0x3e8L));
              
                this.m_numBlocks = (int)(this.m_maxDataLength / this.m_bufferSize);
                if ((this.m_numBlocks * this.m_bufferSize) < this.m_maxDataLength)
                {
                    this.m_numBlocks++;
                }
                this.m_whdr = new Wave.WAVEHDR[this.m_numBlocks + 1];
                this.m_whdr[0] = new Wave.WAVEHDR();
                this.m_whdr[1] = new Wave.WAVEHDR();
                mmsyserr = this.InitBuffer(0);
                if (mmsyserr != Wave.MMSYSERR.NOERROR)
                {
                    return mmsyserr;
                }
                mmsyserr = this.InitBuffer(1);
                if (mmsyserr != Wave.MMSYSERR.NOERROR)
                {
                    return mmsyserr;
                }
                this.m_curBlock = 0;
                this.m_inited = true;
                return Wave.MMSYSERR.NOERROR;
            }

 

 

            public Wave.MMSYSERR Save(string fileName)
            {
                Wave.MMSYSERR nOERROR;
                if (!this.m_inited)
                {
                    return Wave.MMSYSERR.ERROR;
                }
                if (this.m_recording)
                {
                    this.Stop();
                }
                FileStream output = null;
                BinaryWriter wrtr = null;
                try
                {
                    if (File.Exists(fileName))
                    {
                        FileInfo info = new FileInfo(fileName);
                        if ((info.Attributes & FileAttributes.ReadOnly) != 0)
                        {
                            info.Attributes -= 1;
                        }
                        output = new FileStream(fileName, FileMode.Truncate);
                    }
                    else
                    {
                        output = new FileStream(fileName, FileMode.Create);
                    }
                    if (output == null)
                    {
                        return Wave.MMSYSERR.ERROR;
                    }
                    wrtr = new BinaryWriter(output);
                    if (wrtr == null)
                    {
                        return Wave.MMSYSERR.ERROR;
                    }
                    uint num = 0;
                    for (int i = 0; i < this.m_numBlocks; i++)
                    {
                        if (this.m_whdr[i] != null)
                        {
                            num += this.m_whdr[i].dwBytesRecorded;
                        }
                    }
                    int num3 = 0x24 + ((int)num);
                    this.WriteChars(wrtr, "RIFF");
                    wrtr.Write(num3);
                    this.WriteChars(wrtr, "WAVEfmt ");
                    wrtr.Write(0x10);
                    this.m_wfmt.Write(wrtr);
                    this.WriteChars(wrtr, "data");
                    wrtr.Write((int)num);
                    for (int j = 0; j < this.m_numBlocks; j++)
                    {
                        if (this.m_whdr[j] != null)
                        {
                            Wave.MMSYSERR mmsyserr = this.m_whdr[j].Write(wrtr);
                            if (mmsyserr != Wave.MMSYSERR.NOERROR)
                            {
                                return mmsyserr;
                            }
                        }
                    }
                    nOERROR = Wave.MMSYSERR.NOERROR;
                }
                finally
                {
                    this.FreeWaveBuffers();
                    if (output != null)
                    {
                        output.Close();
                    }
                    if (wrtr != null)
                    {
                        wrtr.Close();
                    }
                }
                return nOERROR;
            }

            public Wave.MMSYSERR Start()
            {
                if (!this.m_inited || this.m_recording)
                {
                    return Wave.MMSYSERR.ERROR;
                }
                Wave.MMSYSERR mmsyserr = WaveIn.waveInStart(this.m_hwi);
                if (mmsyserr != Wave.MMSYSERR.NOERROR)
                {
                    return mmsyserr;
                }
                this.m_recording = true;
                return Wave.MMSYSERR.NOERROR;
            }

            public void Stop()
            {
                WaveIn.waveInReset(this.m_hwi);
                this.m_recording = false;
            }

            private void WriteChars(BinaryWriter wrtr, string text)
            {
                for (int i = 0; i < text.Length; i++)
                {
                    char ch = text[i];
                    wrtr.Write(ch);
                }
            }

            public bool Done
            {
                get
                {
                    return !this.m_recording;
                }
            }
        }

        protected class WAVEINCAPS
        {
            private byte[] m_data = null;
            private const uint WAVEINCAPS_SIZE = 80;

            public WAVEINCAPS()
            {
                this.m_data = new byte[80];
            }

            public static implicit operator byte[](WaveIn.WAVEINCAPS caps)
            {
                return caps.m_data;
            }

            public uint dwFormats
            {
                get
                {
                    return BitConverter.ToUInt32(this.m_data, 0x48);
                }
            }

            public uint Size
            {
                get
                {
                    return 80;
                }
            }

            public string szPname
            {
                get
                {
                    char[] chArray = new char[0x20];
                    for (int i = 0; i < 0x20; i++)
                    {
                        chArray[i] = (char)BitConverter.ToUInt16(this.m_data, (i * 2) + 8);
                    }
                    return new string(chArray);
                }
            }

            public uint vDriverVersion
            {
                get
                {
                    return BitConverter.ToUInt32(this.m_data, 4);
                }
            }

            public ushort wChannels
            {
                get
                {
                    return BitConverter.ToUInt16(this.m_data, 0x4c);
                }
            }

            public ushort wMid
            {
                get
                {
                    return BitConverter.ToUInt16(this.m_data, 0);
                }
            }

            public ushort wPid
            {
                get
                {
                    return BitConverter.ToUInt16(this.m_data, 2);
                }
            }

            public ushort wReserved1
            {
                get
                {
                    return BitConverter.ToUInt16(this.m_data, 0x4e);
                }
            }
        }
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -