Exemple #1
0
        /// <summary>
        /// Plays the next available sound.
        /// </summary>
        /// <returns>Returns true if this thread has one or more sounds that it can play.</returns>
        public bool PlayNextSound()
        {
            if (m_Sounds.Count == 0)
            {
                return(false);
            }

            StopLastSound();

            string Sound = m_Sounds[0];

            m_Sounds.RemoveAt(0);
            m_Sounds.Insert(m_Sounds.Count + (new Random()).Next(1), Sound);

            if (m_IsMusic)
            {
                m_MusicInstance = new SoundPlayer(Sound);
                m_MusicInstance.PlaySound(false, true);
            }
            else
            {
                XAFile XA = new XAFile(Sound);
                m_SoundInstance = new SoundPlayer(XA.DecompressedStream.ToArray(), XA.GetSampleRate());
                m_SoundInstance.PlaySound();
            }

            return(true);
        }
Exemple #2
0
        static void Main(string[] args)
        {
            string[] XAFiles  = Directory.GetFiles(Directory.GetCurrentDirectory(), "*.xa");
            string[] UTKFiles = Directory.GetFiles(Directory.GetCurrentDirectory(), "*.utk");

            for (int i = 0; i < XAFiles.Length; i++)
            {
                XAFile XA = new XAFile();
                XA.LoadFile(XAFiles[i]);
                XA.DecompressFile();

                BinaryWriter Writer = new BinaryWriter(File.Create(XAFiles[i].Replace(".xa", ".wav")));
                Writer.Write(XA.DecompressedData);
                Writer.Close();
            }

            /*
             * UTKFunctions.UTKGenerateTables();
             *
             * UTKWrapper UTK = new UTKWrapper();
             *
             * unsafe
             * {
             *  for (int i = 0; i < UTKFiles.Length; i++)
             *  {
             *      UTK.LoadUTK(UTKFiles[i]);
             *      BinaryWriter Writer = new BinaryWriter(File.Create(UTKFiles[i].Replace(".utk", ".wav")));
             *      Writer.Write(UTK.Wav);
             *      Writer.Close();
             *  }
             * }
             */
        }
Exemple #3
0
    private WaveOut LoadAudioFromData(XAFile data, WaveOut device)
    {
        try
        {
            if (started)
            {
                device.Stop();
                //device.Dispose();
                // device = new WaveOut();
            }
            MemoryStream tmpStr = null;
            //MemoryStream

            if (data.XA)
            {
                tmpStr            = new MemoryStream(data.DecompressedData);
                mMainOutputStream = new WaveFileReader(tmpStr);
            }
            else
            {
                tmpStr            = new MemoryStream(data.inputBytes);
                mMainOutputStream = new Mp3FileReader(tmpStr);
            }
            mVolumeStream = new WaveChannel32(mMainOutputStream);
            device.Init(mVolumeStream);
            started = true;
            return(device);
        }
        catch (System.Exception ex)
        {
            Debug.LogWarning("Error! " + ex.Message);
        }

        return(null);
    }
Exemple #4
0
    public static XAFile GetAudio(byte[] audio)
    {
        var xafil = new XAFile(audio);

        if (xafil.XA)
        {
            xafil.DecompressFile();
        }
        return(xafil);
    }
        private GCHandle LoadSound(string filename)
        {
            if (SoundCache.ContainsKey(filename))
            {
                return(SoundCache[filename]);
            }
            byte[] data = new XAFile(BaseDir + filename).DecompressedData;

            GCHandle pinnedArray = GCHandle.Alloc(data, GCHandleType.Pinned);

            SoundCache.Add(filename, pinnedArray);
            return(pinnedArray);
        }
Exemple #6
0
        private SoundEffect LoadSound(string filename)
        {
            if (SoundCache.ContainsKey(filename))
            {
                return(SoundCache[filename]);
            }
            byte[] data = new XAFile(BaseDir + filename).DecompressedData;

            var stream = new MemoryStream(data);
            var sfx    = SoundEffect.FromStream(stream);

            stream.Close();
            SoundCache.Add(filename, sfx);
            return(sfx);
        }
        public void TestCorrectXAParsing()
        {
            string GameDir   = CommonMethods.GetInstallDir();
            string Delimiter = (CommonMethods.IsLinux) ? "//" : "\\";

            try
            {
                XAFile Snd = new XAFile(File.Open(GameDir + "sounddata" + Delimiter + "tvstations" + Delimiter +
                                                  "tv_romance" + Delimiter + "tv_r1.xa", FileMode.Open, FileAccess.ReadWrite));
            }
            catch (Exception E)
            {
                Debug.WriteLine(E.ToString());
                Assert.Fail();
            }
        }
        public AmbiencePlayer(Ambience amb)
        {
            if (amb.Loop)
            {
                byte[] data   = new XAFile(FSO.Content.Content.Get().GetPath(amb.Path)).DecompressedData;
                var    stream = new MemoryStream(data);
                sfx = SoundEffect.FromStream(stream);
                stream.Close();

                inst          = sfx.CreateInstance();
                inst.IsLooped = true;
                inst.Play();
                fscMode = false;
            }
            else
            {
                fsc = HITVM.Get().PlayFSC(FSO.Content.Content.Get().GetPath(amb.Path));
                fsc.SetVolume(0.33f); //may need tweaking
                fscMode = true;
            }
        }
Exemple #9
0
        public AmbiencePlayer(Ambience amb)
        {
            if (amb.Loop)
            {
                byte[] data = new XAFile(TSO.Content.Content.Get().GetPath(amb.Path)).DecompressedData;

                LoopSound = GCHandle.Alloc(data, GCHandleType.Pinned);

                IntPtr pointer = LoopSound.AddrOfPinnedObject();
                Channel = Bass.BASS_StreamCreateFile(pointer, 0, data.Length, BASSFlag.BASS_DEFAULT | BASSFlag.BASS_STREAM_AUTOFREE);
                //Bass.BASS_ChannelSetAttribute(Channel, BASSAttribute.BASS_ATTRIB_VOL, 0.33f);
                Bass.BASS_ChannelFlags(Channel, BASSFlag.BASS_MUSIC_LOOP, BASSFlag.BASS_MUSIC_LOOP);
                Bass.BASS_ChannelPlay(Channel, false);
                fscMode = false;
            }
            else
            {
                fsc = HITVM.Get().PlayFSC(TSO.Content.Content.Get().GetPath(amb.Path));
                fsc.SetVolume(0.33f); //may need tweaking
                fscMode = true;
            }
        }
 private void button3_Click(object sender, EventArgs e)
 {
     var test = new XAFile(textBox1.Text);
 }
Exemple #11
0
        /// <summary>
        /// Gets a sound effect from the sound effects cache.
        /// </summary>
        /// <param name="Patch">A Patch instance containing the file location or ID.</param>
        /// <returns>The sound effect.</returns>
        public SoundEffect GetSFX(Patch patch)
        {
            if (patch == null)
            {
                return(null);
            }
            var InstanceID = patch.FileID;

            if (SFXCache.ContainsKey(InstanceID))
            {
                return(SFXCache[InstanceID]);
            }
            byte filetype = 0;

            byte[] data = GetAudioFrom(InstanceID, TSOAudio, out filetype);
            if (data == null)
            {
                data = GetAudioFrom(InstanceID, tsov2, out filetype);
            }
            if (data == null)
            {
                data = GetAudioFrom(InstanceID, Stings, out filetype);
            }
            if (data == null)
            {
                data = GetAudioFrom(InstanceID, EP5Samps, out filetype);
            }
            if (data == null)
            {
                data = GetAudioFrom(InstanceID, EP2, out filetype);
            }
            if (data == null)
            {
                string source;
                if (NightclubSounds.TryGetValue(InstanceID, out source))
                {
                    data = new XAFile(source).DecompressedData;
                }
            }

            if (data != null)
            {
                var stream = new MemoryStream(data);

                var sfx = SoundEffect.FromStream(stream);
                stream.Close();
                SFXCache.Add(InstanceID, sfx);
                switch (filetype)
                {
                case 2:
                    sfx.Name = "VOX";
                    break;

                case 3:
                    sfx.Name = "MUSIC";
                    break;

                default:
                    sfx.Name = "FX";
                    break;
                }
                return(sfx); //remember to clear the sfx cache between lots!
            }
            else
            {
                //GCHandle pinnedArray = GCHandle.Alloc(new byte[1], GCHandleType.Weak);
                return(null);// pinnedArray; //we couldn't find anything! can't return null so do this... not the best idea tbh
            }
        }