Exemplo n.º 1
0
        public void DIVAWriter(string file)
        {
            if (!File.Exists(file + ".wav"))
            {
                return;
            }

            Stream reader = File.OpenReader(file + ".wav");

            Data = new DIVAFile();
            WAV.Header Header = reader.ReadWAVHeader();
            if (!Header.IsSupported)
            {
                reader.Close(); return;
            }

            Stream writer = File.OpenWriter(file + ".diva", true);

            Data.Channels       = Header.Channels;
            Data.SampleRate     = Header.SampleRate;
            writer.LongPosition = 0x40;

            byte value = 0;

            int[]   sample       = new int[Data.Channels];
            int[]   current      = new int[Data.Channels];
            int[]   currentclamp = new int[Data.Channels];
            sbyte[] stepindex    = new sbyte[Data.Channels];

            int *  samplePtr       = sample.GetPtr();
            int *  currentPtr      = current.GetPtr();
            int *  currentclampPtr = currentclamp.GetPtr();
            sbyte *stepindexPtr    = stepindex.GetPtr();

            Data.SamplesCount = Header.Size / Header.Channels / Header.Bytes;

            for (i = 0; i < Data.SamplesCount; i++)
            {
                for (c = 0; c < Header.Channels; c++)
                {
                    samplePtr[c] = (reader.ReadWAVSample(Header.Bytes, Header.Format) * 0x8000).CFTI();
                    value        = IMAEncoder(samplePtr[c], ref currentPtr[c],
                                              ref currentclampPtr[c], ref stepindexPtr[c]);
                    writer.Write(value, 4);
                }
            }
            writer.CheckWrited();

            writer.LongPosition = 0x00;
            writer.Write("DIVA");
            writer.Write(0x00);
            writer.Write((Data.SamplesCount * Data.Channels).Align(2, 2));
            writer.Write(Data.SampleRate);
            writer.Write(Data.SamplesCount);
            writer.Write(0x00);
            writer.Write(0x00);
            writer.Write(Data.Channels);
            writer.Close();
            reader.Close();
        }
Exemplo n.º 2
0
        private byte[] BuildWavHeader(WAV.Header Header, short Bytes)
        {
            Stream writer = File.OpenWriter();

            writer.Write(Header);
            byte[] Data = writer.ToArray();
            writer.Close();
            return(Data);
        }
Exemplo n.º 3
0
        public void WAVWriterStraight()
        {
            byte Flag = VAGData.Flags[0];

            if (Flag == 7)
            {
                return;
            }
            WAV.Header Header = new WAV.Header();
            Stream     writer = File.OpenWriter(file + ".wav", true);

            writer.LongPosition = 0x2C;

            for (i = 0; i < BS; i++)
            {
                for (c = 0; c < ch; c++)
                {
                    f = (float)(VAGData.DataPtr[i * ch + c] / 8388608.0);
                    writer.Write(f);
                }
            }

            for (i1 = 0, i2 = 0; i1 < VAGData.Size; i1++, VAGData.DataPtr += VBS)
            {
                Flag = VAGData.Flags[i1];
                if (Flag == 5 || Flag > 6)
                {
                    break;
                }
                for (i = 0; i < BS; i++)
                {
                    for (c = 0; c < ch; c++)
                    {
                        f = (float)(VAGData.DataPtr[i * ch + c] / 8388608.0);
                        writer.Write(f);
                    }
                }

                if (Flag == 1)
                {
                    break;
                }
            }
            VAGData.DataPtr = VAGData.OriginDataPtr;

            Header = new WAV.Header {
                Bytes = 4, Channels = ch, Format = 3, SampleRate =
                    VAGData.SampleRate, Size = writer.UIntPosition - 0x2C
            };
            writer.Write(Header, 0);
            writer.Close();
        }
Exemplo n.º 4
0
        public static void W(this Stream _IO, WAV.Header Header)
        {
            _IO.W("RIFF");
            if (Header.Format != 0xFFFE)
            {
                _IO.W(Header.Size + 0x24);
            }
            else
            {
                _IO.W(Header.Size + 0x3C);
            }
            _IO.W("WAVE");
            _IO.W("fmt ");
            if (Header.Format != 0xFFFE)
            {
                _IO.W(0x10);
            }
            else
            {
                _IO.W(0x28);
            }

            _IO.W(Header.Format);
            _IO.W((short)Header.Channels);
            _IO.W(Header.SampleRate);
            _IO.W(Header.SampleRate * Header.Channels * Header.Bytes);
            _IO.W((short)(Header.Channels * Header.Bytes));
            _IO.W((short)(Header.Bytes << 3));
            if (Header.Format == 0xFFFE)
            {
                _IO.W((short)0x16);
                _IO.W((short)(Header.Bytes << 3));
                _IO.W(Header.ChannelMask);
                _IO.W(Header.Bytes == 2 ? 0x01 : 0x03);
                _IO.W(0x00100000);
                _IO.W(0xAA000080);
                _IO.W(0x719B3800);
            }
            _IO.W("data");
            _IO.W(Header.Size);
        }
Exemplo n.º 5
0
        public void WAVWriterStraight(string file, bool IgnoreEndFlags = false)
        {
            if (!Success)
            {
                return;
            }
            byte Flag = VAGData.Flags[0];

            if (Flag == 7)
            {
                return;
            }
            WAV.Header Header = new WAV.Header();
            Stream     writer = File.OpenWriter(file + ".wav", true);

            writer.I64P = 0x2C;

            VAGData.DataPtr       = VAGData.Data.GetPtr();
            VAGData.OriginDataPtr = VAGData.DataPtr;
            if (Flag < 8)
            {
                for (i = 0; i < BS; i++)
                {
                    for (c = 0; c < ch; c++)
                    {
                        f = (float)(VAGData.DataPtr[i * ch + c] / 8388608.0);
                        writer.W(f);
                    }
                }
            }
            else
            {
                for (i = 0; i < BS; i++)
                {
                    for (c = 0; c < ch; c++)
                    {
                        writer.W(0f);
                    }
                }
            }

            for (i1 = 0, i2 = 0; i1 < VAGData.Size; i1++, VAGData.DataPtr += VBS)
            {
                Flag = VAGData.Flags[i1];
                if (!IgnoreEndFlags && (Flag == 5 || Flag == 7))
                {
                    break;
                }
                if (Flag < 8)
                {
                    for (i = 0; i < BS; i++)
                    {
                        for (c = 0; c < ch; c++)
                        {
                            f = (float)(VAGData.DataPtr[i * ch + c] / 8388608.0);
                            writer.W(f);
                        }
                    }
                }
                else
                {
                    for (i = 0; i < BS; i++)
                    {
                        for (c = 0; c < ch; c++)
                        {
                            writer.W(0f);
                        }
                    }
                }

                if (!IgnoreEndFlags && Flag == 1)
                {
                    break;
                }
            }

            Header = new WAV.Header {
                Bytes = 4, Channels = ch, Format = 3, SampleRate =
                    VAGData.SampleRate, Size = writer.U32P - 0x2C
            };
            writer.W(Header, 0);
            writer.C();
        }
Exemplo n.º 6
0
        public static WAV.Header ReadWAVHeader(this Stream _IO)
        {
            WAV.Header Header = new WAV.Header();
            if (_IO.RS(4) != "RIFF")
            {
                return(Header);
            }
            _IO.RU32();
            if (_IO.RS(4) != "WAVE")
            {
                return(Header);
            }
            if (_IO.RS(4) != "fmt ")
            {
                return(Header);
            }
            int Offset = _IO.RI32();

            Header.Format = _IO.RU16();
            if (Header.Format == 0x01 || Header.Format == 0x03 || Header.Format == 0xFFFE)
            {
                Header.Channels   = _IO.RU16();
                Header.SampleRate = _IO.RU32();
                _IO.RI32(); _IO.RI16();
                Header.Bytes = _IO.RU16();
                if (Header.Bytes % 8 != 0)
                {
                    return(Header);
                }
                Header.Bytes >>= 3;
                if (Header.Bytes == 0)
                {
                    return(Header);
                }
                if (Header.Format == 0xFFFE)
                {
                    _IO.RI32();
                    Header.ChannelMask = _IO.RU32();
                    Header.Format      = _IO.RU16();
                }
                if (Header.Bytes < 1 || (Header.Bytes > 4 && Header.Bytes != 8))
                {
                    return(Header);
                }
                if (Header.Bytes > 0 && Header.Bytes < 4 && Header.Format == 3)
                {
                    return(Header);
                }
                if (Header.Bytes == 8 && Header.Format == 1)
                {
                    return(Header);
                }
                _IO.S(Offset + 0x14, 0);
                if (_IO.RS(4) != "data")
                {
                    return(Header);
                }
                Header.Size        = _IO.RU32();
                Header.HeaderSize  = _IO.PU32;
                Header.IsSupported = true;
                return(Header);
            }
            return(Header);
        }
Exemplo n.º 7
0
 public static void W(this Stream _IO, WAV.Header Header, long Seek, SeekOrigin Origin)
 {
     _IO.S(Seek, Origin); _IO.W(Header);
 }
Exemplo n.º 8
0
 public static void W(this Stream _IO, WAV.Header Header, long Seek) => _IO.W(Header, Seek, 0);
Exemplo n.º 9
0
        public static WAV.Header ReadWAVHeader(this Stream IO)
        {
            WAV.Header Header = new WAV.Header();
            if (IO.ReadString(4) != "RIFF")
            {
                return(Header);
            }
            IO.ReadUInt32();
            if (IO.ReadString(4) != "WAVE")
            {
                return(Header);
            }
            if (IO.ReadString(4) != "fmt ")
            {
                return(Header);
            }
            int Offset = IO.ReadInt32();

            Header.Format = IO.ReadUInt16();
            if (Header.Format == 0x01 || Header.Format == 0x03 || Header.Format == 0xFFFE)
            {
                Header.Channels   = IO.ReadUInt16();
                Header.SampleRate = IO.ReadUInt32();
                IO.ReadInt32(); IO.ReadInt16();
                Header.Bytes = IO.ReadUInt16();
                if (Header.Bytes % 8 != 0)
                {
                    return(Header);
                }
                Header.Bytes >>= 3;
                if (Header.Bytes == 0)
                {
                    return(Header);
                }
                if (Header.Format == 0xFFFE)
                {
                    IO.ReadInt32();
                    Header.ChannelMask = IO.ReadUInt32();
                    Header.Format      = IO.ReadUInt16();
                }
                if (Header.Bytes < 1 || (Header.Bytes > 4 && Header.Bytes != 8))
                {
                    return(Header);
                }
                if (Header.Bytes > 0 && Header.Bytes < 4 && Header.Format == 3)
                {
                    return(Header);
                }
                if (Header.Bytes == 8 && Header.Format == 1)
                {
                    return(Header);
                }
                IO.Seek(Offset + 0x14, 0);
                if (IO.ReadString(4) != "data")
                {
                    return(Header);
                }
                Header.Size        = IO.ReadUInt32();
                Header.HeaderSize  = IO.UIntPosition;
                Header.IsSupported = true;
                return(Header);
            }
            return(Header);
        }
Exemplo n.º 10
0
        public int WAVReaderStraight(bool ExtendedFlagging = false)
        {
            VAGData = new VAGFile();
            Stream reader = File.OpenReader(file + ".wav");

            WAV.Header Header = reader.ReadWAVHeader();
            if (!Header.IsSupported)
            {
                reader.Close(); return(1);
            }
            ch  = Header.Channels;
            VBS = BS * ch;

            VAGData.Size          = Header.Size / Header.Bytes;
            VAGData.Data          = new int[VAGData.Size.Align(VBS)];
            VAGData.DataPtr       = VAGData.Data.GetPtr();
            VAGData.OriginDataPtr = VAGData.DataPtr;

            if (Header.Bytes == 1 && Header.Format == 0x01)
            {
                for (int i1 = 0; i1 < VAGData.Size; i1++, VAGData.DataPtr++)
                {
                    *VAGData.DataPtr = (reader.ReadByte() - 0x80) << 16;
                }
            }
            else if (Header.Bytes == 2 && Header.Format == 0x01)
            {
                for (int i1 = 0; i1 < VAGData.Size; i1++, VAGData.DataPtr++)
                {
                    *VAGData.DataPtr = reader.ReadInt16() << 8;
                }
            }
            else if (Header.Bytes == 3 && Header.Format == 0x01)
            {
                for (int i1 = 0; i1 < VAGData.Size; i1++, VAGData.DataPtr++)
                {
                    *VAGData.DataPtr = reader.ReadByte() | (reader.ReadInt16() << 8);
                }
            }
            else if (Header.Bytes == 4 && Header.Format == 0x01)
            {
                for (int i1 = 0; i1 < VAGData.Size; i1++, VAGData.DataPtr++)
                {
                    *VAGData.DataPtr = reader.ReadInt32() >> 8;
                }
            }
            else if (Header.Bytes == 4 && Header.Format == 0x03)
            {
                for (int i1 = 0; i1 < VAGData.Size; i1++, VAGData.DataPtr++)
                {
                    *VAGData.DataPtr = (int)(reader.ReadSingle() * 8388608.0);
                }
            }
            else if (Header.Bytes == 8 && Header.Format == 0x03)
            {
                for (int i1 = 0; i1 < VAGData.Size; i1++, VAGData.DataPtr++)
                {
                    *VAGData.DataPtr = (int)(reader.ReadDouble() * 8388608.0);
                }
            }

            VAGData.Size       = VAGData.Size.Align(VBS, VBS);
            VAGData.DataPtr    = VAGData.OriginDataPtr;
            VAGData.Channels   = ch;
            VAGData.SampleRate = Header.SampleRate;
            VAGData.Flags      = new byte[VAGData.Size];
            if (ExtendedFlagging)
            {
                VAGData.Flags[0] = 0x4;
            }
            VAGData.Flags[VAGData.Size - 1] = 0x1;

            reader.Close();
            return(0);
        }
Exemplo n.º 11
0
 public static void Write(this Stream IO, WAV.Header Header, long Seek) => IO.Write(Header, Seek, 0);
Exemplo n.º 12
0
        public void DIVAReader(bool ToArray = false)
        {
            if (File.Exists(file + ".diva"))
            {
                Data = new DIVAFile();
                Stream reader = File.OpenReader(file + ".diva");

                if (reader.ReadString(0x04) == "DIVA")
                {
                    reader.ReadInt32();
                    Data.Size         = reader.ReadUInt32();
                    Data.SampleRate   = reader.ReadUInt32();
                    Data.SamplesCount = reader.ReadUInt32();
                    reader.ReadInt64();
                    Data.Channels = reader.ReadUInt16();
                    reader.ReadUInt16();
                    Data.Name = reader.ReadString(0x20);

                    Stream writer = File.OpenWriter();
                    if (!ToArray)
                    {
                        writer = File.OpenWriter(file + ".wav", true);
                    }
                    writer.LongPosition = 0x2C;

                    byte    value        = 0;
                    int[]   current      = new int[Data.Channels];
                    int[]   currentclamp = new int[Data.Channels];
                    sbyte[] stepindex    = new sbyte[Data.Channels];
                    float   f;

                    int *  currentPtr      = current.GetPtr();
                    int *  currentclampPtr = currentclamp.GetPtr();
                    sbyte *stepindexPtr    = stepindex.GetPtr();

                    for (i = 0; i < Data.SamplesCount; i++)
                    {
                        for (c = 0; c < Data.Channels; c++)
                        {
                            value = reader.ReadHalfByte();
                            IMADecoder(value, ref currentPtr[c], ref currentclampPtr[c], ref stepindexPtr[c]);
                            f = (float)(currentPtr[c] / 32768.0);
                            writer.Write(f);
                        }
                    }

                    WAV.Header Header = new WAV.Header
                    {
                        Bytes      = 4, Channels = Data.Channels, Format = 3,
                        SampleRate = Data.SampleRate, Size = Data.SamplesCount * Data.Channels * 4
                    };
                    writer.Write(Header, 0);
                    if (ToArray)
                    {
                        Data.Data = writer.ToArray();
                    }
                    writer.Close();
                }
                reader.Close();
            }
        }
        public void DIVAReader(string file, bool ToArray = false)
        {
            if (!File.Exists(file + ".diva"))
            {
                return;
            }

            Data = new DIVAFile();
            Stream reader = File.OpenReader(file + ".diva");

            if (reader.RS(0x04) != "DIVA")
            {
                reader.C(); return;
            }

            reader.RI32();
            Data.Size         = reader.RU32();
            Data.SampleRate   = reader.RU32();
            Data.SamplesCount = reader.RU32();
            reader.RI64();
            Data.Channels = reader.RU16();
            reader.RU16();
            Data.Name = reader.RS(0x20);

            byte value = 0;

            byte[]  data         = new byte[Data.SamplesCount * Data.Channels * 4];
            int[]   current      = new int[Data.Channels];
            int[]   currentclamp = new int[Data.Channels];
            sbyte[] stepindex    = new sbyte[Data.Channels];

            fixed(int *currentPtr = current)
            fixed(int *currentclampPtr = currentclamp)
            fixed(sbyte *stepindexPtr  = stepindex)
            fixed(byte *ptr            = data)
            {
                float *dataPtr = (float *)ptr;

                for (i = 0; i < Data.SamplesCount; i++)
                {
                    for (c = 0; c < Data.Channels; c++, dataPtr++)
                    {
                        value = reader.RHB();
                        IMADecoder(value, ref currentPtr[c], ref currentclampPtr[c], ref stepindexPtr[c]);
                        *dataPtr = (float)(currentPtr[c] / 32768.0);
                    }
                }
            }
            reader.CR();


            if (ToArray)
            {
                Data.Data = data;
            }
            else
            {
                Stream     writer = File.OpenWriter(file + ".wav", true);
                WAV.Header Header = new WAV.Header {
                    Bytes      = 4, Channels = Data.Channels, Format = 3,
                    SampleRate = Data.SampleRate, Size = Data.SamplesCount * Data.Channels * 4
                };
                writer.W(Header, 0);
                writer.W(data);
                writer.C();
            }

            reader.C();
        }
Exemplo n.º 14
0
        public void WAVWriter(string file, bool IgnoreEndFlags = false)
        {
            if (!Success)
            {
                return;
            }
            byte Flag = VAGData.Flags[0];

            if (Flag == 7)
            {
                return;
            }
            WAV.Header Header = new WAV.Header();
            Stream     writer;

            if (!IgnoreEndFlags && Flag == 6)
            {
                writer = File.OpenWriter(file + ".loop.0.wav", true);
            }
            else
            {
                writer = File.OpenWriter(file + ".0.wav", true);
            }
            writer.LongPosition = 0x2C;

            if (Flag < 8)
            {
                for (i = 0; i < BS; i++)
                {
                    for (c = 0; c < ch; c++)
                    {
                        f = (float)(VAGData.DataPtr[i * ch + c] / 8388608.0);
                        writer.Write(f);
                    }
                }
            }
            else
            {
                for (i = 0; i < BS; i++)
                {
                    for (c = 0; c < ch; c++)
                    {
                        writer.Write(0f);
                    }
                }
            }

            VAGData.DataPtr += VBS;

            for (i1 = 1, i2 = 0; i1 < VAGData.Size; i1++, VAGData.DataPtr += VBS)
            {
                Flag = VAGData.Flags[i1];
                if (!IgnoreEndFlags && Flag == 5 || Flag == 7)
                {
                    break;
                }
                else if (!IgnoreEndFlags && Flag == 6)
                {
                    Header = new WAV.Header {
                        Bytes = 4, Channels = ch, Format = 3, SampleRate =
                            VAGData.SampleRate, Size = writer.UIntPosition - 0x2C
                    };
                    writer.Write(Header, 0);
                    writer.Close();
                    i2++;

                    writer = File.OpenWriter(file + "." + i2 + ".loop.wav", true);
                    writer.LongPosition = 0x2C;
                }

                if (!IgnoreEndFlags && Flag < 8)
                {
                    for (i = 0; i < BS; i++)
                    {
                        for (c = 0; c < ch; c++)
                        {
                            f = (float)(VAGData.DataPtr[i * ch + c] / 8388608.0);
                            writer.Write(f);
                        }
                    }
                }
                else
                {
                    for (i = 0; i < BS; i++)
                    {
                        for (c = 0; c < ch; c++)
                        {
                            writer.Write(0f);
                        }
                    }
                }

                if (!IgnoreEndFlags && Flag == 1)
                {
                    break;
                }
                else if (!IgnoreEndFlags && Flag == 3)
                {
                    Header = new WAV.Header {
                        Bytes = 4, Channels = ch, Format = 3, SampleRate =
                            VAGData.SampleRate, Size = writer.UIntPosition - 0x2C
                    };
                    writer.Write(Header, 0);
                    writer.Close();
                    i2++;

                    if (VAGData.Size == i1 + 1)
                    {
                        writer = File.OpenWriter();
                    }
                    else
                    {
                        writer = File.OpenWriter(file + "." + i2 + ".wav", true);
                    }
                    writer.LongPosition = 0x2C;
                }
            }
            VAGData.DataPtr = VAGData.OriginDataPtr;

            Header = new WAV.Header {
                Bytes = 4, Channels = ch, Format = 3, SampleRate =
                    VAGData.SampleRate, Size = writer.UIntPosition - 0x2C
            };
            writer.Write(Header, 0);
            writer.Close();
        }
Exemplo n.º 15
0
        public int WAVReaderStraight(string file, bool ExtendedFlagging = false)
        {
            Success = false;
            VAGData = new VAGFile();
            Stream reader = File.OpenReader(file + ".wav");

            WAV.Header Header = reader.ReadWAVHeader();
            if (!Header.IsSupported)
            {
                reader.C(); return(1);
            }
            ch  = Header.Channels;
            VBS = BS * ch;

            VAGData.Size = Header.Size / Header.Bytes;
            VAGData.Data = new int[VAGData.Size.A(VBS)];
            fixed(int *dataPtr = VAGData.Data)
            {
                int *localDataPtr = dataPtr;

                if (Header.Bytes == 1 && Header.Format == 0x01)
                {
                    for (int i1 = 0; i1 < VAGData.Size; i1++, localDataPtr++)
                    {
                        *localDataPtr = (reader.RU8() - 0x80) << 16;
                    }
                }
                else if (Header.Bytes == 2 && Header.Format == 0x01)
                {
                    for (int i1 = 0; i1 < VAGData.Size; i1++, localDataPtr++)
                    {
                        *localDataPtr = reader.RI16() << 8;
                    }
                }
                else if (Header.Bytes == 3 && Header.Format == 0x01)
                {
                    for (int i1 = 0; i1 < VAGData.Size; i1++, localDataPtr++)
                    {
                        *localDataPtr = reader.RU8() | (reader.RI16() << 8);
                    }
                }
                else if (Header.Bytes == 4 && Header.Format == 0x01)
                {
                    for (int i1 = 0; i1 < VAGData.Size; i1++, localDataPtr++)
                    {
                        *localDataPtr = reader.RI32() >> 8;
                    }
                }
                else if (Header.Bytes == 4 && Header.Format == 0x03)
                {
                    for (int i1 = 0; i1 < VAGData.Size; i1++, localDataPtr++)
                    {
                        *localDataPtr = (int)(reader.RF32() * 8388608.0);
                    }
                }
                else if (Header.Bytes == 8 && Header.Format == 0x03)
                {
                    for (int i1 = 0; i1 < VAGData.Size; i1++, localDataPtr++)
                    {
                        *localDataPtr = (int)(reader.RF64() * 8388608.0);
                    }
                }
            }

            VAGData.Size       = VAGData.Size.A(VBS, VBS);
            VAGData.Channels   = ch;
            VAGData.SampleRate = Header.SampleRate;
            VAGData.Flags      = new byte[VAGData.Size];
            if (ExtendedFlagging)
            {
                VAGData.Flags[0] = 0x4;
            }
            VAGData.Flags[VAGData.Size - 1] = 0x1;

            reader.C();
            Success = true;
            return(0);
        }
Exemplo n.º 16
0
        public void WAVWriter(string file, bool IgnoreEndFlags = false)
        {
            if (!Success)
            {
                return;
            }
            byte Flag = VAGData.Flags[0];

            if (Flag == 7)
            {
                return;
            }
            WAV.Header Header = new WAV.Header();
            Stream     writer;

            if (!IgnoreEndFlags && Flag == 6)
            {
                writer = File.OpenWriter(file + ".loop.0.wav", true);
            }
            else
            {
                writer = File.OpenWriter(file + ".0.wav", true);
            }
            writer.PI64 = 0x2C;

            fixed(int *dataPtr = VAGData.Data)
            {
                int *localDataPtr = dataPtr;

                if (Flag < 8)
                {
                    for (i = 0; i < BS; i++)
                    {
                        for (c = 0; c < ch; c++)
                        {
                            f = (float)(localDataPtr[i * ch + c] / 8388608.0);
                            writer.W(f);
                        }
                    }
                }
                else
                {
                    for (i = 0; i < BS; i++)
                    {
                        for (c = 0; c < ch; c++)
                        {
                            writer.W(0f);
                        }
                    }
                }

                localDataPtr += VBS;

                for (i1 = 1, i2 = 0; i1 < VAGData.Size; i1++, localDataPtr += VBS)
                {
                    Flag = VAGData.Flags[i1];
                    if (!IgnoreEndFlags && (Flag == 5 || Flag == 7))
                    {
                        break;
                    }
                    else if (!IgnoreEndFlags && Flag == 6)
                    {
                        Header = new WAV.Header {
                            Bytes      = 4, Channels = ch, Format = 3,
                            SampleRate = VAGData.SampleRate, Size = writer.P - 0x2C
                        };
                        writer.W(Header, 0);
                        writer.C();
                        i2++;

                        writer      = File.OpenWriter(file + "." + i2 + ".loop.wav", true);
                        writer.PI64 = 0x2C;
                    }

                    if (!IgnoreEndFlags && Flag < 8)
                    {
                        for (i = 0; i < BS; i++)
                        {
                            for (c = 0; c < ch; c++)
                            {
                                f = (float)(localDataPtr[i * ch + c] / 8388608.0);
                                writer.W(f);
                            }
                        }
                    }
                    else
                    {
                        for (i = 0; i < BS; i++)
                        {
                            for (c = 0; c < ch; c++)
                            {
                                writer.W(0f);
                            }
                        }
                    }

                    if (!IgnoreEndFlags && Flag == 1)
                    {
                        break;
                    }
                    else if (!IgnoreEndFlags && Flag == 3)
                    {
                        Header = new WAV.Header {
                            Bytes      = 4, Channels = ch, Format = 3,
                            SampleRate = VAGData.SampleRate, Size = writer.P - 0x2C
                        };
                        writer.W(Header, 0);
                        writer.C();
                        i2++;

                        writer = VAGData.Size == i1 + 1 ? File.OpenWriter()
                            : File.OpenWriter(file + "." + i2 + ".wav", true);
                        writer.PI64 = 0x2C;
                    }
                }
            }

            Header = new WAV.Header {
                Bytes      = 4, Channels = ch, Format = 3,
                SampleRate = VAGData.SampleRate, Size = writer.P - 0x2C
            };
            writer.W(Header, 0);
            writer.C();
        }
Exemplo n.º 17
0
 public static void Write(this Stream IO, WAV.Header Header, long Seek, SeekOrigin Origin)
 {
     IO.Seek(Seek, Origin); IO.Write(Header);
 }