Esempio n. 1
0
        public Stream GetWavStream()
        {
            byte[] dataPCM       = null;
            int    bitsPerSample = BitsPerSample;

            switch (Format.Codec)
            {
            case AwcFormatChunk.CodecFormat.PCM:
                dataPCM = Data;
                break;

            case AwcFormatChunk.CodecFormat.ADPCM:
                dataPCM = new byte[Data.Length];
                Buffer.BlockCopy(Data, 0, dataPCM, 0, Data.Length);
                AwcFile.Decrypt_RSXXTEA(dataPCM, GTA5Keys.PC_AWC_KEY);
                dataPCM       = DecodeADPCM(dataPCM, SampleCount);
                bitsPerSample = 16;
                break;
            }

            int   byteRate   = SamplesPerSecond * Channels * bitsPerSample / 8;
            short blockAlign = (short)(Channels * bitsPerSample / 8);

            MemoryStream stream    = new MemoryStream();
            BinaryWriter w         = new BinaryWriter(stream);
            int          wavLength = 12 + 24 + 8 + Data.Length;

            // RIFF chunk
            w.Write("RIFF".ToCharArray());
            w.Write((int)(wavLength - 8));
            w.Write("WAVE".ToCharArray());

            // fmt sub-chunk
            w.Write("fmt ".ToCharArray());
            w.Write((int)16);  // fmt size
            w.Write((short)1); // 1 = WAVE_FORMAT_PCM
            w.Write((short)Channels);
            w.Write((int)SamplesPerSecond);
            w.Write((int)byteRate);
            w.Write((short)blockAlign);
            w.Write((short)bitsPerSample);

            // data sub-chunk
            w.Write("data".ToCharArray());
            w.Write((int)dataPCM.Length);
            w.Write(dataPCM);

            w.Flush();
            stream.Position = 0;
            return(stream);
        }