Пример #1
0
        /// <summary>
        /// Write for BFWAV.
        /// </summary>
        /// <param name="bw">The writer.</param>
        /// <param name="wavInfo"></param>
        public void WriteWAV(ref BinaryDataWriter bw, b_wav.InfoBlock wavInfo, Int32 paddingAmount = 0x20)
        {
            bw.Write("DATA".ToCharArray());
            bw.Write(GetSize(wavInfo.encoding, ref wavInfo, paddingAmount));
            bw.Write(new byte[paddingAmount - 8]);

            //Write data.
            for (int i = 0; i < wavInfo.channelInfo.Count(); i++)
            {
                switch (wavInfo.encoding)
                {
                //PCM8.
                case EncodingTypes.PCM8:
                    foreach (sbyte s in pcm8[i])
                    {
                        bw.Write(s);
                    }
                    break;

                //PCM16.
                case EncodingTypes.PCM16:
                    bw.Write(pcm16[i]);
                    break;

                //DSP-ADPCM.
                case EncodingTypes.DSP_ADPCM:
                    bw.Write(dspAdpcm[i]);
                    break;
                }

                //Padding.
                if (i != wavInfo.channelInfo.Count() - 1)
                {
                    while ((bw.Position % paddingAmount) != 0)
                    {
                        bw.Write((byte)0);
                    }
                }
            }
        }
Пример #2
0
        /// <summary>
        /// Get data from a b_wav.
        /// </summary>
        /// <param name="wavInfo"></param>
        /// <returns></returns>
        public object GetDataWAV(b_wav.InfoBlock wavInfo)
        {
            object returnValue = null;

            //See encoding.
            switch (wavInfo.encoding)
            {
            case EncodingTypes.PCM8:
                return(EncoderFactory.SignedPcm8ToPcm8(pcm8));

            case EncodingTypes.PCM16:
                return(pcm16);

            case EncodingTypes.DSP_ADPCM:
                List <DspAdpcmInfo> context = new List <DspAdpcmInfo>();
                foreach (b_wav.InfoBlock.ChannelInfo c in wavInfo.channelInfo)
                {
                    context.Add(c.dspAdpcmInfo);
                }
                return(EncoderFactory.DspApcmToPcm16(dspAdpcm, wavInfo.loopEnd, context.ToArray()));
            }

            return(returnValue);
        }
Пример #3
0
        /// <summary>
        /// Get the size of the data block.
        /// </summary>
        /// <returns></returns>
        public UInt32 GetSize(byte encoding, ref b_wav.InfoBlock wavInfo, Int32 paddingAmount = 0x20)
        {
            UInt32 size = (uint)paddingAmount;

            switch (encoding)
            {
            case EncodingTypes.PCM8:
                size += (UInt32)(pcm8.Length * pcm8[0].Length);
                int padd0 = pcm8[0].Length;
                while ((padd0) % paddingAmount != 0)
                {
                    padd0 += 1;
                }
                padd0 -= pcm8[0].Length;
                size  += (UInt32)(padd0 * (pcm8.Length - 1));
                break;

            case EncodingTypes.PCM16:
                size += (UInt32)(pcm16.Length * pcm16[0].Length * 2);
                int padd1 = pcm16[0].Length * 2;
                while ((padd1) % paddingAmount != 0)
                {
                    padd1 += 1;
                }
                padd1 -= (pcm16[0].Length * 2);
                size  += (UInt32)(padd1 * (pcm16.Length - 1));
                break;

            case EncodingTypes.DSP_ADPCM:
                size += (UInt32)(dspAdpcm.Length * dspAdpcm[0].Length);
                int padd2 = dspAdpcm[0].Length;
                while ((padd2) % paddingAmount != 0)
                {
                    padd2 += 1;
                }
                padd2 -= dspAdpcm[0].Length;
                size  += (UInt32)(padd2 * (dspAdpcm.Length - 1));
                break;
            }


            //Update offsets in b_wav file.
            if (wavInfo != null)
            {
                wavInfo.channelInfoRefTable       = new ReferenceTable(new List <Reference>());
                wavInfo.channelInfoRefTable.count = (UInt32)wavInfo.channelInfo.Count();
                int wavOffset = paddingAmount - 8;
                switch (encoding)
                {
                //PCM8.
                case EncodingTypes.PCM8:

                    for (int i = 0; i < wavInfo.channelInfo.Count(); i++)
                    {
                        //New reference.
                        wavInfo.channelInfo[i].samplesRef = new Reference(ReferenceTypes.General, wavOffset);
                        wavOffset += pcm8[i].Length;
                        while (wavOffset % paddingAmount != 0)
                        {
                            wavOffset += 1;
                        }
                    }

                    break;

                //PCM16.
                case EncodingTypes.PCM16:

                    for (int i = 0; i < wavInfo.channelInfo.Count(); i++)
                    {
                        //New reference.
                        wavInfo.channelInfo[i].samplesRef = new Reference(ReferenceTypes.General, wavOffset);
                        wavOffset += pcm16[i].Length * 2;
                        while ((wavOffset + 8) % paddingAmount != 0)
                        {
                            wavOffset += 1;
                        }
                    }

                    break;

                //DSP-ADPCM.
                case EncodingTypes.DSP_ADPCM:

                    for (int i = 0; i < wavInfo.channelInfo.Count(); i++)
                    {
                        //New reference.
                        wavInfo.channelInfo[i].samplesRef = new Reference(ReferenceTypes.General, wavOffset);
                        wavOffset += dspAdpcm[i].Length;
                        while ((wavOffset + 8) % paddingAmount != 0)
                        {
                            wavOffset += 1;
                        }
                    }

                    break;
                }
            }


            return(size);
        }
Пример #4
0
        /// <summary>
        /// Read a soundN'Stream block from a b_wav.
        /// </summary>
        /// <param name="br">The reader.</param>
        /// <param name="wavInfo"></param>
        public SoundNStreamDataBlock(ref BinaryDataReader br, b_wav.InfoBlock wavInfo)
        {
            //Read magic.
            br.ReadUInt32();
            UInt32 size = br.ReadUInt32();

            //Set data base postion.
            long dataBasePosition = br.Position;

            //Read the channels.
            switch (wavInfo.encoding)
            {
            //PCM8.
            case EncodingTypes.PCM8:

                //Make new data array.
                pcm8 = new sbyte[wavInfo.channelInfo.Count()][];

                //See how big the length of each channel is.
                int channelSize8 = (int)(size - wavInfo.channelInfo[pcm8.Length - 1].samplesRef.offset) - 8;

                //Read channels.
                for (int i = 0; i < pcm8.Count(); i++)
                {
                    //Set postion.
                    br.Position = wavInfo.channelInfo[i].samplesRef.offset + dataBasePosition;

                    //Read data.
                    pcm8[i] = br.ReadSBytes(channelSize8);
                }
                break;


            //PCM16.
            case EncodingTypes.PCM16:

                //Make new data array.
                pcm16 = new short[wavInfo.channelInfo.Count()][];

                //See how big the length of each channel is.
                int channelSize16 = (int)((size - wavInfo.channelInfo[pcm16.Length - 1].samplesRef.offset) - 8) / 2;

                //Read channels.
                for (int i = 0; i < pcm16.Count(); i++)
                {
                    //Set postion.
                    br.Position = wavInfo.channelInfo[i].samplesRef.offset + dataBasePosition;

                    //Read data.
                    pcm16[i] = br.ReadInt16s(channelSize16);
                }
                break;


            //DSP-ADPCM.
            case EncodingTypes.DSP_ADPCM:

                //Make new data array.
                dspAdpcm = new byte[wavInfo.channelInfo.Count()][];

                //See how big the length of each channel is.
                int channelSize4 = (int)(size - wavInfo.channelInfo[dspAdpcm.Length - 1].samplesRef.offset) - 8;

                //Read channels.
                for (int i = 0; i < dspAdpcm.Count(); i++)
                {
                    //Set postion.
                    br.Position = wavInfo.channelInfo[i].samplesRef.offset + dataBasePosition;

                    //Read data.
                    dspAdpcm[i] = br.ReadBytes(channelSize4);
                }
                break;
            }
        }