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

📄 wave.cs

📁 本人觉得C#的软件是不需要源代码的
💻 CS
字号:
using System;
using System.IO;
using System.Runtime.InteropServices;
namespace SmartAnswerCall.处理类
{


    public class Wave
    {
        public const uint CALLBACK_WINDOW = 0x10000;
        private const int MMSYSERR_BASE = 0;
        public const uint WAVE_FORMAT_1M08 = 1;
        public const uint WAVE_FORMAT_1M16 = 4;
        public const uint WAVE_FORMAT_1S08 = 2;
        public const uint WAVE_FORMAT_1S16 = 8;
        public const uint WAVE_FORMAT_2M08 = 0x10;
        public const uint WAVE_FORMAT_2M16 = 0x40;
        public const uint WAVE_FORMAT_2S08 = 0x20;
        public const uint WAVE_FORMAT_2S16 = 0x80;
        public const uint WAVE_FORMAT_4M08 = 0x100;
        public const uint WAVE_FORMAT_4M16 = 0x400;
        public const uint WAVE_FORMAT_4S08 = 0x200;
        public const uint WAVE_FORMAT_4S16 = 0x800;
        public const uint WAVE_INVALIDFORMAT = 0;
        public const uint WAVE_MAPPER = uint.MaxValue;
        private const int WAVERR_BASE = 0x20;

        public enum MMSYSERR
        {
            ALLOCATED = 4,
            BADDB = 14,
            BADDEVICEID = 2,
            BADERRNUM = 9,
            DELETEERROR = 0x12,
            ERROR = 1,
            HANDLEBUSY = 12,
            INVALFLAG = 10,
            INVALHANDLE = 5,
            INVALIDALIAS = 13,
            INVALPARAM = 11,
            KEYNOTFOUND = 15,
            LASTERROR = 20,
            NODRIVER = 6,
            NODRIVERCB = 20,
            NOERROR = 0,
            NOMEM = 7,
            NOTENABLED = 3,
            NOTSUPPORTED = 8,
            READERROR = 0x10,
            VALNOTFOUND = 0x13,
            WRITEERROR = 0x11
        }

        public class WAVEFORMATEX
        {
            public uint nAvgBytesPerSec = 0;
            public ushort nBlockAlign = 0;
            public ushort nChannels = 0;
            public uint nSamplesPerSec = 0;
            public ushort wBitsPerSample = 0;
            protected const int WF_OFFSET_AVGBYTESPERSEC = 0x1c;
            protected const int WF_OFFSET_BITSPERSAMPLE = 0x22;
            protected const int WF_OFFSET_BLOCKALIGN = 0x20;
            protected const int WF_OFFSET_CHANNELS = 0x16;
            public const int WF_OFFSET_DATA = 0x2c;
            protected const int WF_OFFSET_FORMATTAG = 20;
            protected const int WF_OFFSET_SAMPLESPERSEC = 0x18;
            public ushort wFormatTag = 0;

            public void Read(BinaryReader rdr)
            {
                this.wFormatTag = rdr.ReadUInt16();
                this.nChannels = rdr.ReadUInt16();
                this.nSamplesPerSec = rdr.ReadUInt32();
                this.nAvgBytesPerSec = rdr.ReadUInt32();
                this.nBlockAlign = rdr.ReadUInt16();
                this.wBitsPerSample = rdr.ReadUInt16();
                rdr.ReadUInt32();
                rdr.ReadUInt32();
            }

            public void SeekTo(Stream fs)
            {
                fs.Seek(20L, SeekOrigin.Begin);
            }

            public void Skip(Stream fs)
            {
                fs.Seek(0x2cL, SeekOrigin.Begin);
            }

            public void Write(BinaryWriter wrtr)
            {
                wrtr.Write(this.wFormatTag);
                wrtr.Write(this.nChannels);
                wrtr.Write(this.nSamplesPerSec);
                wrtr.Write(this.nAvgBytesPerSec);
                wrtr.Write(this.nBlockAlign);
                wrtr.Write(this.wBitsPerSample);
            }
        }

        public class WAVEHDR : IDisposable
        {
            public uint dwBufferLength = 0;
            public uint dwBytesRecorded = 0;
            public uint dwFlags = 0;
            public uint dwLoops = 0;
            public uint dwUser = 0;
            public IntPtr lpData = IntPtr.Zero;
            public IntPtr lpNext = IntPtr.Zero;
            public uint reserved = 0;
            public const int WAVE_FORMAT_PCM = 1;
            public const int WHDR_BEGINLOOP = 4;
            public const int WHDR_DONE = 1;
            public const int WHDR_ENDLOOP = 8;
            public const int WHDR_INQUEUE = 0x10;
            public const int WHDR_PREPARED = 2;

            public void Dispose()
            {
                if (this.lpData != IntPtr.Zero)
                {
                    Memory.LocalFree(this.lpData);
                }
            }

            public Wave.MMSYSERR Init(uint bufferLength, bool init)
            {
                if ((this.lpData != IntPtr.Zero) && (this.dwBufferLength < bufferLength))
                {
                    Memory.LocalFree(this.lpData);
                    this.lpData = IntPtr.Zero;
                }
                if (this.lpData == IntPtr.Zero)
                {
                    this.lpData = Memory.LocalAlloc(0, bufferLength);
                }
                this.dwBufferLength = bufferLength;
                if (this.lpData == IntPtr.Zero)
                {
                    return Wave.MMSYSERR.NOMEM;
                }
                if (init)
                {
                    for (int i = 0; i < bufferLength; i++)
                    {
                        Marshal.WriteByte(this.lpData, i, 0);
                    }
                }
                return Wave.MMSYSERR.NOERROR;
            }

            public Wave.MMSYSERR Read(BinaryReader rdr, uint readLength, int align)
            {
                uint uBytes = readLength;
                if ((((ulong)uBytes) % ((ulong)align)) != 0L)
                {
                    uBytes += (uint)(align - (((long)uBytes) % ((long)align)));
                }
                this.dwBufferLength = uBytes;
                byte[] buffer = new byte[readLength];
                rdr.Read(buffer, 0, buffer.Length);
                if (this.lpData == IntPtr.Zero)
                {
                    this.lpData = Memory.LocalAlloc(0, uBytes);
                }
                if (this.lpData == IntPtr.Zero)
                {
                    return Wave.MMSYSERR.NOMEM;
                }
                Marshal.Copy(buffer, 0, this.lpData, buffer.Length);
                return Wave.MMSYSERR.NOERROR;
            }

            public Wave.MMSYSERR Write(BinaryWriter wrtr)
            {
                if (this.lpData == IntPtr.Zero)
                {
                    return Wave.MMSYSERR.NOMEM;
                }
                byte[] destination = new byte[this.dwBytesRecorded];
                Marshal.Copy(this.lpData, destination, 0, destination.Length);
                wrtr.Write(destination);
                return Wave.MMSYSERR.NOERROR;
            }
        }

        private enum WAVERR
        {
            BADFORMAT = 0x20,
            LASTERROR = 0x23,
            NONE = 0,
            STILLPLAYING = 0x21,
            SYNC = 0x23,
            UNPREPARED = 0x22
        }
    }
}

⌨️ 快捷键说明

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