コード例 #1
0
        //dataChunk ReadDataHeader() - 2004 July 28
        //Again, not much to say.
        public dataChunk ReadDataHeader()
        {
            try
            {
                data = new dataChunk();

                data.Subchunk2ID   = new string(reader.ReadChars(4));
                data.Subchunk2Size = reader.ReadUInt32();
                data.lFilePosition = reader.BaseStream.Position;
                data.NumSamples    = Convert.ToUInt32(data.Subchunk2Size / (format.BitsPerSample / 8 * format.NumChannels));
                //The above could be written as data.dwChunkSize / format.wBlockAlign, but I want to emphasize what the frames look like.
                data.dwMinLength = (data.Subchunk2Size / format.ByteRate) / 60;
                data.dSecLength  = ((double)data.Subchunk2Size / (double)format.ByteRate) - (double)data.dwMinLength * 60;
                data.Samples     = new List <Sample>();
                for (int i = 0; i < data.NumSamples; i++)
                {
                    Sample temp = new Sample();
                    temp.Channels = new List <Channel>();
                    for (int j = 0; j < format.NumChannels; j++)
                    {
                        if (format.BitsPerSample / format.NumChannels == 8)
                        {
                            temp.Channels.Add(new Channel(Convert.ToInt32(reader.ReadByte())));
                        }
                        if (format.BitsPerSample / format.NumChannels == 16)
                        {
                            temp.Channels.Add(new Channel(Convert.ToInt32(reader.ReadInt16())));
                        }
                        if (format.BitsPerSample / format.NumChannels == 32)
                        {
                            temp.Channels.Add(new Channel(Convert.ToInt32(reader.ReadInt32())));
                        }
                    }
                    data.Samples.Add(temp);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            return(data);
        }
コード例 #2
0
ファイル: Form1.cs プロジェクト: NickKachko/WaveFileEditor
        //dataChunk ReadDataHeader() - 2004 July 28
        //Again, not much to say.
        public dataChunk ReadDataHeader()
        {
            try
            {
                data = new dataChunk();

                data.Subchunk2ID = new string(reader.ReadChars(4));
                data.Subchunk2Size = reader.ReadUInt32();
                data.lFilePosition = reader.BaseStream.Position;
                data.NumSamples = Convert.ToUInt32(data.Subchunk2Size / (format.BitsPerSample / 8 * format.NumChannels));
                //The above could be written as data.dwChunkSize / format.wBlockAlign, but I want to emphasize what the frames look like.
                data.dwMinLength = (data.Subchunk2Size / format.ByteRate) / 60;
                data.dSecLength = ((double)data.Subchunk2Size / (double)format.ByteRate) - (double)data.dwMinLength * 60;
                data.Samples = new List<Sample>();
                for(int i=0;i<data.NumSamples;i++)
                {
                    Sample temp = new Sample();
                    temp.Channels = new List<Channel>();
                    for (int j=0;j<format.NumChannels;j++)
                    {
                        if (format.BitsPerSample / format.NumChannels == 8)
                            temp.Channels.Add(new Channel(Convert.ToInt32(reader.ReadByte())));
                        if (format.BitsPerSample / format.NumChannels == 16)
                            temp.Channels.Add(new Channel(Convert.ToInt32(reader.ReadInt16())));
                        if (format.BitsPerSample / format.NumChannels == 32)
                            temp.Channels.Add(new Channel(Convert.ToInt32(reader.ReadInt32())));
                    }
                    data.Samples.Add(temp);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            return data;
        }