当前位置: 首页>>代码示例>>C#>>正文


C# BinaryReader.ReadUInt32方法代码示例

本文整理汇总了C#中BinaryReader.ReadUInt32方法的典型用法代码示例。如果您正苦于以下问题:C# BinaryReader.ReadUInt32方法的具体用法?C# BinaryReader.ReadUInt32怎么用?C# BinaryReader.ReadUInt32使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在BinaryReader的用法示例。


在下文中一共展示了BinaryReader.ReadUInt32方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: WaveAudio

            /// <summary>
            /// Initializes this WaveAudio object with Wave audio file.
            /// </summary>
            /// <param name="filepath">Path of Wave Audio file.</param>
            public WaveAudio(FileStream filepath)
            {
                this.fs = filepath;
                this.br = new BinaryReader(fs);

                this.riffID = br.ReadBytes(4);
                this.size = br.ReadUInt32();
                this.wavID = br.ReadBytes(4);
                this.fmtID = br.ReadBytes(4);
                this.fmtSize = br.ReadUInt32();
                this.format = br.ReadUInt16();
                this.channels = br.ReadUInt16();
                this.sampleRate = br.ReadUInt32();
                this.bytePerSec = br.ReadUInt32();
                this.blockSize = br.ReadUInt16();
                this.bit = br.ReadUInt16();
                this.dataID = br.ReadBytes(4);
                this.dataSize = br.ReadUInt32();

                this.leftStream = new List<short>();
                this.rightStream = new List<short>();
                for (int i = 0; i < this.dataSize / this.blockSize; i++)
                {
                    leftStream.Add((short)br.ReadUInt16());
                    rightStream.Add((short)br.ReadUInt16());
                }

                br.Close();
                fs.Close();
            }
开发者ID:kushalpandya,项目名称:WavStagno,代码行数:34,代码来源:WaveAudio.cs

示例2: ReadWavStreamReadHeaders

    public static CWavStreamReadHeaders ReadWavStreamReadHeaders(BinaryReader r)
    {
        CWavStreamReadHeaders info = new CWavStreamReadHeaders();
        info.bIsValid = false;
        string riff = new string(r.ReadChars(4));
        if (!riff.Equals("RIFF"))
            throw new WavCutException("No 'RIFF' Tag, probably not a valid wav file.");

        info.nCompleteLength = r.ReadUInt32(); // (length of file in bytes) - 8

        string wave = new string(r.ReadChars(4));
        if (!wave.Equals("WAVE"))
            throw new WavCutException("No 'WAVE' tag, probably not a valid wav file.");

        string format = new string(r.ReadChars(4)); // assume that fmt tag is first
        if (!format.Equals("fmt "))
            throw new WavCutException("No 'fmt ' tag");

        uint size = r.ReadUInt32(); // size of fmt header
        if (size != 16)
            throw new WavCutException("Size of fmt header != 16");

        info.nAudioFormat = r.ReadUInt16(); // audio format. 1 refers to uncompressed PCM
       
        // read the format header
        info.nChannels = r.ReadUInt16();
        info.nSampleRate = r.ReadUInt32();
        info.byteRate = r.ReadUInt32();
        info.blockAlign = r.ReadUInt16();
        info.nBitsPerSample = r.ReadUInt16();
        info.bIsValid = true;
        return info;
    }
开发者ID:kleopatra999,项目名称:downpoured_midi_audio,代码行数:33,代码来源:WavStreams.cs

示例3: VoxelData

 public VoxelData(string name, Material[] materials)
 {
     TextAsset asset = (TextAsset)Resources.Load("Meta/" + name);
     MemoryStream ms = new MemoryStream(asset.bytes);
     BinaryReader reader = new BinaryReader(ms);
     x_size = reader.ReadUInt32();
     z_size = reader.ReadUInt32();
     y_size = reader.ReadUInt32();
     x_offset = reader.ReadInt32();
     z_offset = reader.ReadInt32();
     y_offset = reader.ReadInt32();
     data = reader.ReadBytes((int)(x_size * y_size * z_size));
     byte[] raw_palette = reader.ReadBytes(256*3);
     palette = new Material[256];
     for (int i = 0; i < 256; i++) {
         float r = raw_palette[i*3] / 255.0f;
         float g = raw_palette[i*3+1] / 255.0f;
         float b = raw_palette[i*3+2] / 255.0f;
         Material result = null;
         foreach (Material mat in materials) {
             if (mat.color.r == r && mat.color.g == g && mat.color.b == b) {
                 result = mat;
                 break;
             }
         }
         palette[i] = result;
     }
 }
开发者ID:carriercomm,项目名称:voxie,代码行数:28,代码来源:AnimateScript.cs

示例4: GetFiles

    public static ZipDirHeader[] GetFiles(BinaryReader br, Func<ZipDirHeader, bool> f)
    {
        var list = new List<ZipDirHeader>();

        var fs = br.BaseStream;
        if (fs.Length < 22)
            throw new Exception("ファイルが小さ過ぎます。");

        fs.Position = fs.Length - 22;
        if (br.ReadInt32() != 0x06054b50)
            throw new Exception("ヘッダが見付かりません。");

        fs.Position += 6;
        int count = br.ReadUInt16();
        var dir_len = br.ReadUInt32();
        var dir_start = br.ReadUInt32();

        fs.Position = dir_start;
        for (int i = 0; i < count; i++)
        {
            if (br.ReadInt32() != 0x02014b50)
                throw new Exception("ファイルが壊れています。");
            var zipdh = new ZipDirHeader(br);
            if (f(zipdh)) list.Add(zipdh);
        }

        return list.ToArray();
    }
开发者ID:7shi,项目名称:JpegViewer,代码行数:28,代码来源:Zip.cs

示例5: LoadFromFile

    /// <summary>
    /// Attempts loading an audio file with a specified filename.
    /// Will throw an exception if the file could not be read for some reason.
    /// This function does only read 16-bit .wav files with no metadata. If the file is not valid then it could lead to corrupt data,
    /// or unhandled exceptions.
    /// </summary>
    /// <param name="filename">The path to the file to be read.</param>
    /// <returns>AudioData, or null.</returns>
    public static AudioData LoadFromFile(string filename)
    {
        AudioData audioData = null;

        using (BinaryReader reader = new BinaryReader(File.OpenRead(filename)))
        {
            Debug.Log("Reading wav: " + filename);

            reader.BaseStream.Seek(22, SeekOrigin.Begin);
            ushort channels = reader.ReadUInt16();
            //Debug.Log("Channels: " + channels);
            uint sampleRate = reader.ReadUInt32();
            //Debug.Log("Sample rate: " + sampleRate);
            reader.BaseStream.Seek(34, SeekOrigin.Begin);
            ushort bitsPerSample = reader.ReadUInt16();
            //Debug.Log("Bits per sample: " + bitsPerSample);
            reader.BaseStream.Seek(40, SeekOrigin.Begin);
            uint numberOfBytes = reader.ReadUInt32();
            //Debug.Log("Number of bytes: " + numberOfBytes);
            uint numberOfSamples = numberOfBytes * 8 / bitsPerSample;
            //Debug.Log("Number of samples: " + numberOfSamples);

            float maxAmplitude = 0.0f;
            float[] data = new float[numberOfSamples * channels];
            //short[] shortData = new short[numberOfSamples * channels];
            byte[] buffer = new byte[numberOfBytes];

            if (bitsPerSample / 8 == 2)
            {

                reader.BaseStream.Seek(44, SeekOrigin.Begin);
                buffer = reader.ReadBytes((int)numberOfBytes);

                int bufferStep = 0;
                for (int i = 0; i < numberOfSamples && bufferStep < buffer.Length; i++)
                {
                    float sample = (float)BitConverter.ToInt16(buffer, bufferStep) / Int16.MaxValue;

                    float abs = Mathf.Abs(sample);
                    if (abs > maxAmplitude)
                        maxAmplitude = abs;

                    data[i] = sample;
                    bufferStep += 2;
                }
            }
            else
                Debug.LogWarning(filename + "is not a 16-bit wav.");

            audioData = new AudioData(data, (int)channels, (int)sampleRate, maxAmplitude, (int)numberOfSamples / (int)channels);
        }

        return audioData;
    }
开发者ID:robinerd,项目名称:CallOfTheDepth,代码行数:62,代码来源:AudioBank.cs

示例6: ZipHeader

 public ZipHeader(BinaryReader br)
 {
     Version = br.ReadUInt16();
     Flags = br.ReadUInt16();
     Compression = br.ReadUInt16();
     DosTime = br.ReadUInt16();
     DosDate = br.ReadUInt16();
     Crc32 = br.ReadUInt32();
     CompressedSize = br.ReadUInt32();
     UncompressedSize = br.ReadUInt32();
     FilenameLength = br.ReadUInt16();
     ExtraFieldLength = br.ReadUInt16();
 }
开发者ID:7shi,项目名称:JpegViewer,代码行数:13,代码来源:Zip.cs

示例7: FromIco

	public static GroupIconResource FromIco(string FileName)
	{
		using(FileStream Stream = new FileStream(FileName, FileMode.Open, FileAccess.Read))
		{
			BinaryReader Reader = new BinaryReader(Stream);

			Reader.ReadUInt16(); // Reserved
			Reader.ReadUInt16(); // Type
			ushort Count = Reader.ReadUInt16();

			IconResource[] Icons = new IconResource[Count];
			uint[] Offsets = new uint[Count];

			for(int Idx = 0; Idx < Count; Idx++)
			{
				Icons[Idx] = ReadIconHeader(Reader);
				Offsets[Idx] = Reader.ReadUInt32();
			}

			for(int Idx = 0; Idx < Icons.Length; Idx++)
			{
				Stream.Seek(Offsets[Idx], SeekOrigin.Begin);
				Stream.Read(Icons[Idx].Data, 0, Icons[Idx].Data.Length);
			}

			return new GroupIconResource(Icons);
		}
	}
开发者ID:zhaoyizheng0930,项目名称:UnrealEngine,代码行数:28,代码来源:WinResources.cs

示例8: ReadMBR

 public static void ReadMBR(AtaPio dev)
 {
     BinaryReader binaryReader = new BinaryReader(ATA.a);
     for (int i = 0; i < 4; i++)
     {
         binaryReader.BaseStream.Position = 446 + i * 16 + 8;
         uint num = binaryReader.ReadUInt32();
         uint num2 = binaryReader.ReadUInt32();
         if (num2 != 0u)
         {
             Partition dev2 = new Partition(dev, (ulong)num, (ulong)num2);
             Devices.device device = new Devices.device();
             device.dev = dev2;
             device.name = "/dev/sd" + ATA.b.ToString() + (i + 1).ToString();
             Devices.dev.Add(device);
         }
     }
 }
开发者ID:Bargomer,项目名称:COSMOS-OS,代码行数:18,代码来源:ATA.cs

示例9: HandleHello

    public void HandleHello(BinaryReader reader)
    {
        string magic = reader.ReadCustomString();
        if (magic != "UnityRemote")
            throw new ApplicationException("Handshake failed");

        uint version = reader.ReadUInt32();
        if (version != 0)
            throw new ApplicationException("Unsupported protocol version: " + version);
    }
开发者ID:CenzyGames,项目名称:Save-your-date-new,代码行数:10,代码来源:DataReceiver.cs

示例10: ReadTooSmallUInt32Test

        public void ReadTooSmallUInt32Test()
        {
            System.IO.Stream stream = new SerializedStreamBuilder()
                .Int64(long.MinValue)
                .ToStream();

            BinaryReader reader = new BinaryReader(stream, DeserializationHelper.CannedVersion);

            TestHelper.ExpectException<TeslaDeserializationException>(
                () =>
                {
                    uint foo = reader.ReadUInt32(string.Empty);
                },
                "Bad format UInt32 value. The value was read is outside the range of the UInt32.");
        }
开发者ID:CoreylDagget,项目名称:tesla,代码行数:15,代码来源:UInt32DeserializationTest.cs

示例11: Start

    // Use this for initialization
    void Start()
    {
        Debug.Log("Starting Server");
        server = new NamedPipeServerStream("NPtest");

        //Console.WriteLine("Waiting for connection...");
        Debug.Log("Waiting for connection...");
        server.WaitForConnection();

        //Console.WriteLine("Connected.");
        Debug.Log("Connected.");

        br = new BinaryReader(server);
        bw = new BinaryWriter(server);

        while (true)
        {
            try
            {
                var len = (int)br.ReadUInt32();            // Read string length
                var str = new string(br.ReadChars(len));    // Read string

                //Console.WriteLine("Read: \"{0}\"", str);
                Debug.Log(String.Format("Read: {0}", str));
                str = new string(str.Reverse().ToArray());  // Just for fun

                var buf = Encoding.ASCII.GetBytes(str);     // Get ASCII byte array     
                bw.Write((uint)buf.Length);                // Write string length
                bw.Write(buf);                              // Write string
                //Console.WriteLine("Wrote: \"{0}\"", str);
                Debug.Log(String.Format("Wrote: {0}", str));
            }
            catch (EndOfStreamException)
            {
                break;                    // When client disconnects
            }
        }

        //Console.WriteLine("Client disconnected.");
        Debug.Log("Client disconnected.");
        server.Close();
        server.Dispose();


    }
开发者ID:ma581,项目名称:TestingPipes,代码行数:46,代码来源:PipeWork.cs

示例12: HasFullMessage

	private static bool HasFullMessage(Stream stream)
	{
		BinaryReader reader = new BinaryReader(stream);
		long oldPosition = stream.Position;
		bool result = true;

		if (stream.Length - stream.Position < 5)
			result = false;

		if (result)
		{
			reader.ReadByte();
			uint size = reader.ReadUInt32();
			if (stream.Length - stream.Position < size)
				result = false;
		}

		stream.Position = oldPosition;
		return result;
	}
开发者ID:dannybess,项目名称:0-Back-Project,代码行数:20,代码来源:DataReceiver.cs

示例13: Main

	public static void Main(string[] args) {
		TcpClient conn = new TcpClient("127.0.0.1", 10010);
		Console.WriteLine("client connect");

		Stream stream = conn.GetStream();
		BinaryReader reader = new BinaryReader(stream);
		BinaryWriter writer = ConnInit(reader);

		byte[] buffer = new byte[1024];
		for (;;) {
			int length = WriteRandomBytes(writer, buffer);
			uint n = reader.ReadUInt32();
			byte[] recv = reader.ReadBytes((int)n);
			if (!ByteArrayEquals(buffer, recv, length)) {
				Console.WriteLine("send != recv");
				Console.WriteLine("send: {0}", BitConverter.ToString(buffer, length));
				Console.WriteLine("recv: {0}", BitConverter.ToString(recv));
				return;
			}
		}
	}
开发者ID:miffa,项目名称:crypto,代码行数:21,代码来源:rc4_echo_client.cs

示例14: Read

 public void Read(BinaryReader br)
 {
     uint magic = br.ReadUInt32(); // +00
     if (magic != Util.FOURCC('P', 'S', 'Q', '\0')) {
         throw new Exception("invalid data (PSQ)");
     }
     dataSize = br.ReadUInt32();
     nodeNum = br.ReadUInt16();
     poseNum = br.ReadUInt16();
     vecNum = br.ReadUInt16();
     br.ReadUInt16(); // reserved
     nodeOffs = br.ReadUInt32();
     sizeOffs = br.ReadUInt32();
     vecOffs = br.ReadUInt32();
     nbits = br.ReadUInt32();
 }
开发者ID:schaban,项目名称:AnimTools,代码行数:16,代码来源:psqinfo.cs

示例15: StartWavAnalyze

    public static void StartWavAnalyze(BinaryReader r, long nActualLength)
    {
        CWavStreamReadHeaders info = CWavStreamReadHeaders.ReadWavStreamReadHeaders(r);

        // display header info
        Console.WriteLine("Audio format: " + info.nAudioFormat + " (1 is uncompressed PCM)");
        Console.WriteLine("Sample rate: " + info.nSampleRate);
        Console.WriteLine("BitsPerSample: " + info.nBitsPerSample);
        Console.WriteLine("Channels: " + info.nChannels);
        if (nActualLength != info.nCompleteLength+8)
            Console.WriteLine("Warning: length of file is "+nActualLength+" but expected "+info.nCompleteLength);

        while (true)
        {
            // are we at the end of the file? if so, exit loop
            byte[] arTest = r.ReadBytes(4);
            if (arTest.Length == 0)
                break;
            else
                r.BaseStream.Seek(-arTest.Length,SeekOrigin.Current);

            // read the next chunk
            string sDatatag = new string(r.ReadChars(4));
            uint nDataSize = r.ReadUInt32();
            Console.WriteLine("TYPE:" + sDatatag + " SIZE:" + nDataSize);
            if (sDatatag == "data")
            {
                long nLengthInSamples = nDataSize / (info.nChannels * (info.nBitsPerSample / 8));
                Console.WriteLine("\tlength in samples " + nLengthInSamples +
                    " length in secs " + (nLengthInSamples / ((double)info.nSampleRate)));
            }
            if (sDatatag != "data" && sDatatag != "LIST")
                Console.WriteLine("warning, datatag is not 'data' or 'LIST'.");
            r.BaseStream.Seek(nDataSize, SeekOrigin.Current);
        }
        Console.WriteLine("Looks ok.");
    }
开发者ID:kleopatra999,项目名称:downpoured_midi_audio,代码行数:37,代码来源:WavAnalyze.cs


注:本文中的BinaryReader.ReadUInt32方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。