예제 #1
0
        private static void WriteArchive(string archiveFilename,
                                         List <FileStream> filesToPackReaders,
                                         List <IndexEntry> indexEntries,
                                         List <string> names,
                                         WaveFormatEx waveFormat)
        {
            // ClmFile cannot contain more than 32 bit size internal file count.
            ClmHeader header = ClmHeader.MakeHeader(waveFormat, (uint)names.Count);

            using (FileStream fs = new FileStream(archiveFilename, FileMode.Create, FileAccess.Write, FileShare.None))
                using (BinaryWriter clmFileWriter = new BinaryWriter(fs))
                {
                    header.Serialize(clmFileWriter);

                    // Prepare and write Archive Index
                    PrepareIndex(ClmHeader.SizeInBytes, names, indexEntries);
                    for (int i = 0; i < indexEntries.Count; ++i)
                    {
                        indexEntries[i].Serialize(clmFileWriter);
                    }

                    // Copy files into the archive
                    for (int i = 0; i < header.packedFilesCount; ++i)
                    {
                        using (BinaryReader reader = new BinaryReader(filesToPackReaders[i], System.Text.Encoding.ASCII, true))
                        {
                            reader.BaseStream.Seek(0, SeekOrigin.Begin);
                            clmFileWriter.Write(reader.ReadBytes((int)reader.BaseStream.Length));
                        }
                    }
                }
        }
예제 #2
0
 public ClmHeader(BinaryReader reader)
 {
     fileVersion      = reader.ReadBytes(32);
     waveFormat       = new WaveFormatEx(reader);
     unknown          = reader.ReadBytes(6);
     packedFilesCount = reader.ReadUInt32();
 }
예제 #3
0
 public ClmHeader(byte[] fileVersion, WaveFormatEx waveFormat, byte[] unknown, uint packedFilesCount)
 {
     this.fileVersion      = fileVersion;
     this.waveFormat       = waveFormat;
     this.unknown          = unknown;
     this.packedFilesCount = packedFilesCount;
 }
예제 #4
0
        public static WaveHeader Create(WaveFormatEx waveFormat, uint dataLength)
        {
            WaveHeader waveHeader = new WaveHeader();

            waveHeader.riffHeader.riffTag   = CommonTags.tagRIFF;
            waveHeader.riffHeader.waveTag   = CommonTags.tagWAVE;
            waveHeader.riffHeader.chunkSize = Tag.SizeInBytes + FormatChunk.SizeInBytes + ChunkHeader.SizeInBytes + dataLength;

            waveHeader.formatChunk.fmtTag            = CommonTags.tagFMT_;
            waveHeader.formatChunk.formatSize        = WaveFormatEx.SizeInBytes;
            waveHeader.formatChunk.waveFormat        = waveFormat;
            waveHeader.formatChunk.waveFormat.cbSize = 0;

            waveHeader.dataChunk.formatTag = CommonTags.tagDATA;
            waveHeader.dataChunk.length    = dataLength;

            return(waveHeader);
        }
예제 #5
0
        // Private functions for packing files

        // Reads the beginning of each file and verifies it is formatted as a WAVE file. Locates
        // the WaveFormatEx structure and start of data. The WaveFormat is stored in the waveFormats container.
        // The current stream position is set to the start of the data chunk.
        // Note: This function assumes that all stream positions are initially set to the beginning
        //  of the file. When reading the wave file header, it does not seek to the file start.
        private static void ReadAllWaveHeaders(List <FileStream> filesToPackReaders, List <WaveFormatEx> waveFormats, List <IndexEntry> indexEntries)
        {
            RiffHeader header;

            // Read in all the headers and find start of data
            for (int i = 0; i < filesToPackReaders.Count; ++i)
            {
                using (BinaryReader reader = new BinaryReader(filesToPackReaders[i], System.Text.Encoding.ASCII, true))
                {
                    // Read the file header
                    filesToPackReaders[i].Seek(0, SeekOrigin.Begin);
                    header = new RiffHeader(reader);
                    if (header.riffTag != CommonTags.tagRIFF || header.waveTag != CommonTags.tagWAVE)
                    {
                        throw new System.Exception("Error reading header from file " + filesToPackReaders[i].Name);
                    }

                    // Check that the file size makes sense (matches with header chunk length + 8)
                    if (header.chunkSize + 8 != filesToPackReaders[i].Length)
                    {
                        throw new System.Exception("Chunk size does not match file length in " + filesToPackReaders[i].Name);
                    }

                    // Find the format tag
                    FindChunk(CommonTags.tagFMT_, reader);
                    // Read in the wave format
                    WaveFormatEx waveFormat = new WaveFormatEx(reader);
                    waveFormat.cbSize = 0;
                    waveFormats.Add(waveFormat);

                    // Find the start of the data and record length
                    IndexEntry entry = new IndexEntry();
                    entry.dataLength = (int)FindChunk(CommonTags.tagDATA, reader);
                    indexEntries.Add(entry);
                    // Note: Current stream position is set to the start of the wave data
                }
            }
        }
예제 #6
0
        public override bool Equals(object obj)
        {
            WaveFormatEx rhs = obj as WaveFormatEx;

            return(this == rhs);
        }
예제 #7
0
 public FormatChunk(BinaryReader reader)
 {
     fmtTag     = new Tag(reader);
     formatSize = reader.ReadUInt32();
     waveFormat = new WaveFormatEx(reader);
 }
예제 #8
0
 public FormatChunk()
 {
     fmtTag     = new Tag();
     waveFormat = new WaveFormatEx();
 }
예제 #9
0
 public static ClmHeader MakeHeader(WaveFormatEx waveFormat, uint packedFilesCount)
 {
     return(new ClmHeader(standardFileVersion.ToArray(), waveFormat, standardUnknown.ToArray(), packedFilesCount));
 }