コード例 #1
0
ファイル: Class1.cs プロジェクト: Sphynx2003/HBH.Audio.OpenAL
        public static void ReadChannelData(Stream file, FMTChunk fmt, out DATAChunk[] channels)
        {
            byte[] b = new byte[4];
            file.Read(b, 0, 4);
            char[] id = Encoding.ASCII.GetChars(b);
            file.Read(b, 0, 4);
            var Size = BitConverter.ToInt32(b, 0);

            channels = new DATAChunk[fmt.NumChannels];
            var buf = new byte[fmt.BitsPerSample / 8];

            for (int i = 0; i < fmt.NumChannels; i++)
            {
                channels[i].Data   = new byte[Size / fmt.NumChannels];
                channels[i].Handle =
                    System.Runtime.InteropServices.GCHandle.Alloc(channels[i].Data, System.Runtime.InteropServices.GCHandleType.Pinned);
                channels[i].Size = Size / fmt.NumChannels;
            }
            int index = 0;

            for (int j = 0; j < Size / fmt.NumChannels; j += 1)
            {
                if (j == 0)
                {
                    file.Read(channels[index].Data, j, fmt.BitsPerSample / 8);
                }
                file.Read(channels[index].Data, j - (1 * index), fmt.BitsPerSample / 8);
                index += 1;
                if (index == fmt.NumChannels)
                {
                    index = 0;
                }
            }
        }
コード例 #2
0
ファイル: Class1.cs プロジェクト: Sphynx2003/HBH.Audio.OpenAL
        public static DATAChunk ReadData(Stream file)
        {
            file.Position = 36;
            DATAChunk data = new DATAChunk();

            byte[] b = new byte[4];
            file.Read(b, 0, 4);
            char[] id = Encoding.ASCII.GetChars(b);
            if (Encoding.ASCII.GetString(b) != "data")
            {
                file.Read(b, 0, 4);
                id = Encoding.ASCII.GetChars(b);
            }
            data.ID = id;
            file.Read(b, 0, 4);
            data.Size = BitConverter.ToInt32(b, 0);
            b         = new byte[data.Size];
            file.Read(b, 0, data.Size);
            data.Data   = b;
            data.Handle = System.Runtime.InteropServices.GCHandle.Alloc(data.Data, System.Runtime.InteropServices.GCHandleType.Pinned);
            return(data);
        }