Esempio n. 1
0
 private void CreateList()
 {
     for (int i = 1; i <= _avsBatchSettings.NumberOfFiles; i++)
     {
         string       fileNameOnly  = string.Format("{0}{1}.avs", _avsBatchSettings.NamingConvention, HelperFunctions.PadNumberWithZeros(_avsBatchSettings.NumberOfFiles, i));
         string       directoryPath = String.Format("{0}\\{1}", _avsBatchSettings.AviSynthFilesOutputDirectoryPath, fileNameOnly);
         AviSynthFile avsFile       = new AviSynthFile()
         {
             FileNameOnly = fileNameOnly, FullPath = directoryPath
         };
         avsFile.Number = i;
         _avsFiles.Add(avsFile);
     }
 }
Esempio n. 2
0
        private void WriteHeader(AudioHeaderType headerType, Stream target, AviSynthFile avsFile, long totalSizeInBytes, int channelMask, int formatTypeTag)
        {
            const uint FAAD_MAGIC_VALUE = 0xFFFFFF00;

            bool Greater4GB = totalSizeInBytes >= (uint.MaxValue - 68);
            bool WExtHeader = channelMask >= 0;
            uint HeaderSize = (uint)(WExtHeader ? 60 : 36);

            int[] defmask = { 0, 4, 3, 7, 51, 55, 63, 319, 1599, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };

            if (headerType == AudioHeaderType.W64)
            {
                HeaderSize = (uint)(WExtHeader ? 128 : 112);
                target.Write(Encoding.ASCII.GetBytes("riff"), 0, 4);
                target.Write(BitConverter.GetBytes((uint)0x11CF912E), 0, 4);  // GUID
                target.Write(BitConverter.GetBytes((uint)0xDB28D6A5), 0, 4);
                target.Write(BitConverter.GetBytes((uint)0x0000C104), 0, 4);
                target.Write(BitConverter.GetBytes((totalSizeInBytes + HeaderSize)), 0, 8);
                target.Write(Encoding.ASCII.GetBytes("wave"), 0, 4);
                target.Write(BitConverter.GetBytes((uint)0x11D3ACF3), 0, 4);  // GUID
                target.Write(BitConverter.GetBytes((uint)0xC000D18C), 0, 4);
                target.Write(BitConverter.GetBytes((uint)0x8ADB8E4F), 0, 4);
                target.Write(Encoding.ASCII.GetBytes("fmt "), 0, 4);
                target.Write(BitConverter.GetBytes((uint)0x11D3ACF3), 0, 4);  // GUID
                target.Write(BitConverter.GetBytes((uint)0xC000D18C), 0, 4);
                target.Write(BitConverter.GetBytes((uint)0x8ADB8E4F), 0, 4);
                target.Write(BitConverter.GetBytes(WExtHeader ? (ulong)64 : (ulong)48), 0, 8);
            }
            else if (headerType == AudioHeaderType.RF64)
            {
                HeaderSize += 36;
                target.Write(Encoding.ASCII.GetBytes("RF64"), 0, 4);
                target.Write(BitConverter.GetBytes((uint)0xFFFFFFFF), 0, 4);
                target.Write(Encoding.ASCII.GetBytes("WAVE"), 0, 4);
                target.Write(Encoding.ASCII.GetBytes("ds64"), 0, 4);  // new ds64 chunk 36 bytes
                target.Write(BitConverter.GetBytes((uint)28), 0, 4);
                target.Write(BitConverter.GetBytes((totalSizeInBytes + HeaderSize)), 0, 8);
                target.Write(BitConverter.GetBytes((totalSizeInBytes)), 0, 8);
                target.Write(BitConverter.GetBytes((avsFile.Clip.AudioSamplesCount)), 0, 8);
                target.Write(BitConverter.GetBytes((uint)0x0000), 0, 4);
                target.Write(Encoding.ASCII.GetBytes("fmt "), 0, 4);
                target.Write(BitConverter.GetBytes(WExtHeader ? (uint)40 : (uint)16), 0, 4);
            }
            else
            {
                // Assume RIFF (WAV)
                target.Write(Encoding.ASCII.GetBytes("RIFF"), 0, 4);
                target.Write(BitConverter.GetBytes(Greater4GB ? (FAAD_MAGIC_VALUE + HeaderSize) : (uint)(totalSizeInBytes + HeaderSize)), 0, 4);
                target.Write(Encoding.ASCII.GetBytes("WAVE"), 0, 4);
                target.Write(Encoding.ASCII.GetBytes("fmt "), 0, 4);
                target.Write(BitConverter.GetBytes(WExtHeader ? (uint)40 : (uint)16), 0, 4);
            }

            // fmt chunk common
            target.Write(BitConverter.GetBytes(WExtHeader ? (uint)0xFFFE : (uint)formatTypeTag), 0, 2);
            target.Write(BitConverter.GetBytes(avsFile.Clip.AudioChannelsCount), 0, 2);
            target.Write(BitConverter.GetBytes(avsFile.Clip.AudioSampleRate), 0, 4);
            target.Write(BitConverter.GetBytes(avsFile.Clip.AudioBitsPerSample * avsFile.Clip.AudioSampleRate * avsFile.Clip.AudioChannelsCount / 8), 0, 4);
            target.Write(BitConverter.GetBytes(avsFile.Clip.AudioChannelsCount * avsFile.Clip.AudioBitsPerSample / 8), 0, 2);
            target.Write(BitConverter.GetBytes(avsFile.Clip.AudioBitsPerSample), 0, 2);

            // if WAVE_FORMAT_EXTENSIBLE continue fmt chunk
            if (WExtHeader)
            {
                int channelMaskForHeader = channelMask;
                if (channelMask == 0)
                {
                    channelMaskForHeader = defmask[avsFile.Clip.AudioChannelsCount];
                }

                target.Write(BitConverter.GetBytes((uint)0x16), 0, 2);
                target.Write(BitConverter.GetBytes(avsFile.Clip.AudioBitsPerSample), 0, 2);
                target.Write(BitConverter.GetBytes(channelMaskForHeader), 0, 4);
                target.Write(BitConverter.GetBytes(formatTypeTag), 0, 4);
                target.Write(BitConverter.GetBytes((uint)0x00100000), 0, 4); // GUID
                target.Write(BitConverter.GetBytes((uint)0xAA000080), 0, 4);
                target.Write(BitConverter.GetBytes((uint)0x719B3800), 0, 4);
            }

            // data chunk
            if (headerType == AudioHeaderType.W64)
            {
                if (!WExtHeader)
                {
                    target.Write(BitConverter.GetBytes((uint)0x0000D000), 0, 4); // pad
                    target.Write(BitConverter.GetBytes((uint)0x0000D000), 0, 4);
                }

                target.Write(Encoding.ASCII.GetBytes("data"), 0, 4);
                target.Write(BitConverter.GetBytes((uint)0x11D3ACF3), 0, 4);  // GUID
                target.Write(BitConverter.GetBytes((uint)0xC000D18C), 0, 4);
                target.Write(BitConverter.GetBytes((uint)0x8ADB8E4F), 0, 4);
                target.Write(BitConverter.GetBytes(totalSizeInBytes + 24), 0, 8);
            }
            else if (headerType == AudioHeaderType.RF64)
            {
                target.Write(Encoding.ASCII.GetBytes("data"), 0, 4);
                target.Write(BitConverter.GetBytes((uint)0xFFFFFFFF), 0, 4);
            }
            else
            {
                // Assume RIFF (WAV)
                target.Write(Encoding.ASCII.GetBytes("data"), 0, 4);
                target.Write(BitConverter.GetBytes(Greater4GB ? FAAD_MAGIC_VALUE : (uint)totalSizeInBytes), 0, 4);
            }
        }