예제 #1
0
        //To B_wav.
        public b_wav toGameWav()
        {
            Process p = new Process();

            Directory.SetCurrentDirectory(path + "\\Data\\Tools");
            p.StartInfo.FileName       = "WavConvCafe.exe";
            p.StartInfo.Arguments      = "-o tmp.bfwav tmp.wav";
            p.StartInfo.CreateNoWindow = true;
            p.StartInfo.WindowStyle    = ProcessWindowStyle.Hidden;

            File.WriteAllBytes("tmp.wav", this.toBytes());

            p.Start();
            p.WaitForExit();

            b_wav b = new b_wav();

            b.load(File.ReadAllBytes("tmp.bfwav"));

            File.Delete("tmp.bfwav");
            File.Delete("tmp.wav");

            Directory.SetCurrentDirectory(path);

            return(b);
        }
예제 #2
0
        /// <summary>
        /// Convert to Game Wav in a very cheap way.
        /// </summary>
        /// <returns></returns>
        public b_wav toB_wav()
        {
            this.update();
            b_wav b = new b_wav();

            b = this.toRIFF().toGameWav();

            b.info.loop      = stream.loop;
            b.info.loopStart = stream.loopStart;
            b.info.loopEnd   = stream.loopEnd;

            return(b);
        }
예제 #3
0
        /// <summary>
        /// Get the wave data from a file path.
        /// </summary>
        /// <returns>Wave data.</returns>
        public Wave GetWave()
        {
            string wavePath = GetWavePath();

            if (wavePath == "")
            {
                return(null);
            }

            //Extension.
            string ext = Path.GetExtension(wavePath).ToLower();

            //RIFF.
            if (ext.StartsWith(".w"))
            {
                RiffWave r = new RiffWave();
                r.Load(System.IO.File.ReadAllBytes(wavePath));
                return(new Wave()
                {
                    Wav = WaveFactory.CreateWave(r, true, forceWavMaj, forceWavMin, forceWavRev)
                });
            }

            //Wave.
            else if (ext.EndsWith("wav"))
            {
                b_wav b = new b_wav();
                b.Load(System.IO.File.ReadAllBytes(wavePath));
                return(new Wave()
                {
                    Wav = b
                });
            }

            //Stream.
            else if (ext.EndsWith("stm"))
            {
                b_stm s = new b_stm();
                s.Load(System.IO.File.ReadAllBytes(wavePath));
                return(new Wave()
                {
                    Wav = WaveFactory.CreateWave(s, forceWavMaj, forceWavMin, forceWavRev)
                });
            }

            //Null.
            return(null);
        }
예제 #4
0
        /// <summary>
        /// From a b_wav.
        /// </summary>
        /// <param name="b"></param>
        public FISP(b_wav b)
        {
            regions = new List <RegionInfo>();
            tracks  = new List <TrackInfo>();
            data    = new DataInfo();
            stream  = new StreamInfo();

            //Stream info.
            stream.sampleRate        = b.info.sampleRate;
            stream.encoding          = b.info.encoding;
            stream.isLoop            = b.info.isLoop;
            stream.loopEnd           = b.info.loopEnd;
            stream.loopStart         = b.info.loopStart;
            stream.originalLoopEnd   = b.info.loopEnd;
            stream.originalLoopStart = b.info.originalLoopStart;
            stream.vMajor            = b.fileHeader.vMajor;
            stream.vMinor            = b.fileHeader.vMinor;
            stream.vRevision         = b.fileHeader.vRevision;

            //Data.
            switch (b.info.encoding)
            {
            //PCM8.
            case EncodingTypes.PCM8:
                data.data = EncoderFactory.SignedPcm8ToPcm16(b.data.pcm8).ToList();
                break;

            //PCM16.
            case EncodingTypes.PCM16:
                data.data = b.data.pcm16.ToList();
                break;

            //DSP-ADPCM.
            case EncodingTypes.DSP_ADPCM:
                data.data = (b.data.GetDataWAV(b.info) as short[][]).ToList();
                break;
            }
        }
예제 #5
0
        //To B_wav PCM.
        public b_wav toGameWavPCM()
        {
            //Update first.
            fixOffsets();

            //Make new b_wav.
            b_wav b = new b_wav();

            //Take care of data first.
            b.data.samples = new List <byte[]>();
            b.data.pcm16   = new List <ushort[]>();

            if (fmt.bitsPerSample == 8)
            {
                b.info.soundEncoding = 0;

                List <byte>[] soundData = new List <byte> [fmt.numChannels];
                for (int i = 0; i < soundData.Count(); i++)
                {
                    soundData[i] = new List <byte>();

                    MemoryStream     src = new MemoryStream(data.data);
                    BinaryDataReader br  = new BinaryDataReader(src);

                    br.Position = i;

                    while (br.Position < data.chunkSize)
                    {
                        soundData[i].Add(br.ReadByte());
                        try { for (int j = 1; j < fmt.numChannels; j++)
                              {
                                  br.ReadByte();
                              }
                        } catch { }
                    }
                }

                //Now convert the corrected data per channel to the samples.
                b.data.samples = new List <byte[]>();
                foreach (List <byte> x in soundData)
                {
                    b.data.samples.Add(x.ToArray());
                }

                b.info.loopEnd = (UInt32)b.data.samples[0].Count();
            }
            else if (fmt.bitsPerSample == 16)
            {
                b.info.soundEncoding = 1;

                List <UInt16>[] soundData = new List <UInt16> [fmt.numChannels];
                for (int i = 0; i < soundData.Count(); i++)
                {
                    soundData[i] = new List <UInt16>();

                    MemoryStream     src = new MemoryStream(data.data);
                    BinaryDataReader br  = new BinaryDataReader(src);

                    br.Position = i * 2;

                    while (br.Position < data.chunkSize)
                    {
                        soundData[i].Add(br.ReadUInt16());
                        try { for (int j = 1; j < fmt.numChannels; j++)
                              {
                                  br.ReadUInt16();
                              }
                        } catch { }
                    }
                }

                //Now convert the corrected data per channel to the samples.
                b.data.samples = new List <byte[]>();
                foreach (List <UInt16> x in soundData)
                {
                    b.data.pcm16.Add(x.ToArray());
                }

                b.info.loopEnd = (UInt32)b.data.pcm16[0].Count();
            }

            //Info.
            b.info.channels = new List <b_wav.channelInfo>();
            for (int i = 0; i < fmt.numChannels; i++)
            {
                b_wav.channelInfo x = new b_wav.channelInfo();
                b.info.channels.Add(x);
            }

            b.info.loop         = 0;
            b.info.loopStart    = 0;
            b.info.samplingRate = fmt.sampleRate;

            //Return the new b_wav.
            return(b);
        }