Exemplo n.º 1
0
        public override bool Probe(float x, float y)
        {
            if (base.Probe(x, y))
            {
                var data  = Singleton.Get <DataManager>();
                var sound = Singleton.Get <SoundManager>();

                if (!data.Player.HasBucket)
                {
                    data.CurrentRoom.AddFloatingMessage("I am thirsty, are you Baba yaga..?", x, y - 100, 2500);
                }
                if (data.Player.HasBucket && !data.Player.isBucketFilled)
                {
                    data.CurrentRoom.AddFloatingMessage("Wow! this bucket is getting heavy", x, y - 100, 2500);
                    data.Player.isBucketFilled = true;
                }
                if (data.Player.isBucketFilled && data.Player.HasBucket)
                {
                    data.CurrentRoom.AddFloatingMessage("What could I do with a bucket filled with water...", x, y - 100, 2500);
                }

                //TODO: add bucket/water sound
                SoundBuffer faucet = new SoundBuffer(File.ReadAllBytes(AppDomain.CurrentDomain.BaseDirectory + sound.saucepan));
                Sound       m      = new Sound(faucet);

                sound.PlaySound(m, 20f);

                sound.StopSound(m, 1000);

                return(true);
            }
            return(false);
        }
Exemplo n.º 2
0
        private void CleanupResources()
        {
            if (_directSoundNotify != null)
            {
                _directSoundNotify.Dispose();
                _directSoundNotify = null;
            }
            if (_secondaryBuffer != null)
            {
                _secondaryBuffer.Stop();
                _secondaryBuffer.Dispose();
                _secondaryBuffer = null;
            }
            if (_primaryBuffer != null)
            {
                _primaryBuffer.Stop();
                _primaryBuffer.Dispose();
                _primaryBuffer = null;
            }

            if (_directSound != null)
            {
                _directSound.Dispose();
                _directSound = null;
            }

            _isInitialized = false;
        }
Exemplo n.º 3
0
        public override bool Probe(float x, float y)
        {
            if (base.Probe(x, y))
            {
                var data  = Singleton.Get <DataManager>();
                var sound = Singleton.Get <SoundManager>();

                if (data.Player.HasBucket && data.Player.isBucketFilled)
                {
                    data.CurrentRoom.AddFloatingMessage("The boiler is working again...", x - 100, y - 100, 2500);
                    data.CurrentRoom.BackgroundImage = "graphics/Room2_with light.png";
                    data.Player.isBoilerOn           = true;
                    //TODO: add boiler sound
                    SoundBuffer boiler = new SoundBuffer(File.ReadAllBytes(AppDomain.CurrentDomain.BaseDirectory + sound.windStrong));
                    Sound       m      = new Sound(boiler);
                    sound.PlaySound(m, 20f);
                    sound.StopSound(m, 2000);
                }
                else
                {
                    data.CurrentRoom.AddFloatingMessage("This house feel so cold...", x - 100, y - 100, 2500);
                }
                return(true);
            }
            return(false);
        }
Exemplo n.º 4
0
        public void PlaySound(string path)
        {
            SoundBuffer buffer = new SoundBuffer(File.ReadAllBytes(AppDomain.CurrentDomain.BaseDirectory + path));
            Sound       sound  = new Sound(buffer);

            PlaySound(sound, 20f);
        }
Exemplo n.º 5
0
 internal void Update(double tb, double tf)
 {
     if (baseTrain.CurrentSpeed > -0.277777777777778 & baseTrain.CurrentSpeed < 0.277777777777778)
     {
         // correct stop position
         if (!Lit & (baseTrain.StationDistanceToStopPoint > tb | baseTrain.StationDistanceToStopPoint < -tf))
         {
             SoundBuffer buffer = AdjustAlarm.Buffer;
             if (buffer != null)
             {
                 OpenBveApi.Math.Vector3 pos = AdjustAlarm.Position;
                 Program.Sounds.PlaySound(buffer, 1.0, 1.0, pos, baseTrain.Cars[baseTrain.DriverCar], false);
             }
             if (baseTrain.IsPlayerTrain)
             {
                 MessageManager.AddMessage(Translations.GetInterfaceString("message_station_correct"), MessageDependency.None, GameMode.Normal, MessageColor.Orange, Program.CurrentRoute.SecondsSinceMidnight + 5.0, null);
             }
             Lit = true;
         }
     }
     else
     {
         Lit = false;
     }
 }
Exemplo n.º 6
0
        public static void PlayWeatherSound(string FileName, bool Looped = false)
        {
            if (!(E_Types.Options.Sound == 1) || !File.Exists(Application.StartupPath + E_Globals.SOUND_PATH + FileName))
            {
                return;
            }
            if (CurWeatherMusic == FileName)
            {
                return;
            }

            SoundBuffer buffer = default(SoundBuffer);

            if (ReferenceEquals(WeatherSoundPlayer, null))
            {
                WeatherSoundPlayer = new Sound();
            }
            else
            {
                WeatherSoundPlayer.Stop();
            }

            buffer = new SoundBuffer(Application.StartupPath + E_Globals.SOUND_PATH + FileName);
            WeatherSoundPlayer.SoundBuffer = buffer;
            WeatherSoundPlayer.Loop        = Looped;
            WeatherSoundPlayer.Volume      = E_Sound.MaxVolume;
            WeatherSoundPlayer.Play();

            CurWeatherMusic = FileName;
        }
Exemplo n.º 7
0
        public Sound Play(SoundBuffer buffer, Vector3f position, float volume = 1f, float pitch = 1f, bool loop = false, bool relativeToListener = false, int category = 0)
        {
            Sound source = RequestFreeSource(category);

            if (source == null)
            {
                Log.Debug("Sound play ignored (cat=" + category + ")");
                return(null);
            }

            if (!relativeToListener && buffer.ChannelCount != 1)
            {
                Log.Warn("Stereo sound will not be spatialized");
            }

            source.SoundBuffer        = buffer;
            source.Pitch              = pitch;
            source.Volume             = volume * 100f;
            source.RelativeToListener = relativeToListener;
            source.Position           = position;
            source.Attenuation        = 0.5f;
            source.MinDistance        = 1f;
            source.Loop = loop;
            source.Play();
            return(source);
        }
Exemplo n.º 8
0
        public unsafe override IAudioSource Load(ContentStream stream, LoaderContext ctx)
        {
            uint frameCount = stream.ReadUInt32();
            uint sampleRate = stream.ReadUInt32();
            bool isStereo   = stream.ReadBoolean();
            bool isLossy    = stream.ReadBoolean();

            if (ctx.ContentType == SOUNDEFFECT_TYPE)
            {
                uint fullLen = frameCount * 2 * (isStereo ? 2u : 1u);
                var  data    = Marshal.AllocHGlobal((int)fullLen);

                try
                {
                    RLADStream.DecodeAll(stream, (short *)data.ToPointer(), isStereo, frameCount);

                    var sb = new SoundBuffer();
                    sb.SetData(data, isStereo ? AudioFormat.Stereo16 : AudioFormat.Mono16, sampleRate, fullLen);
                    return(new SoundEffect(sb));
                }
                finally
                {
                    Marshal.FreeHGlobal(data);
                }
            }
            else             // Song
            {
                var astream = new RLADStream(stream.Duplicate(), isStereo, frameCount);
                return(new Song(astream, sampleRate));
            }
        }
Exemplo n.º 9
0
        public override bool Probe(float x, float y)
        {
            if (base.Probe(x, y))
            {
                var data  = Singleton.Get <DataManager>();
                var sound = Singleton.Get <SoundManager>();

                if (!data.Player.HasBucket)
                {
                    data.CurrentRoom.AddFloatingMessage("Interesting...", x - 115, y - 100, 2500);
                }
                if (data.Player.HasBucket && !data.Player.isBucketFilled)
                {
                    data.CurrentRoom.AddFloatingMessage("What can I do with this bucket...", x - 115, y - 100, 2500);
                }

                data.Player.HasBucket = true;

                data.CurrentRoom.Objects[this.ItemID] = null;

                //TODO: add bucket sound
                SoundBuffer bucket = new SoundBuffer(File.ReadAllBytes(AppDomain.CurrentDomain.BaseDirectory + sound.saucepan));
                Sound       m      = new Sound(bucket);
                this.SurfaceName = "graphics/bucket_used.png";

                sound.PlaySound(m, 20f);

                sound.StopSound(m, 1000);
                return(true);
            }
            return(false);
        }
Exemplo n.º 10
0
 /// <summary>Triggers the playback of a sound</summary>
 /// <param name="Direction">The direction of travel- 1 for forwards, and -1 for backwards</param>
 /// <param name="TriggerType">They type of event which triggered this sound</param>
 /// <param name="Train">The root train which triggered this sound</param>
 /// <param name="Car">The car which triggered this sound</param>
 public override void Trigger(int Direction, EventTriggerType TriggerType, AbstractTrain Train, AbstractCar Car)
 {
     if (SuppressSoundEvents)
     {
         return;
     }
     if (TriggerType == EventTriggerType.FrontCarFrontAxle | TriggerType == EventTriggerType.OtherCarFrontAxle | TriggerType == EventTriggerType.OtherCarRearAxle | TriggerType == EventTriggerType.RearCarRearAxle)
     {
         if (!PlayerTrainOnly | Train.IsPlayerTrain)
         {
             double      pitch  = 1.0;
             double      gain   = 1.0;
             SoundBuffer buffer = SoundBuffer;
             if (buffer != null)
             {
                 if (this.Dynamic)
                 {
                     double spd = Math.Abs(Train.CurrentSpeed);
                     pitch = spd / this.Speed;
                     gain  = pitch < 0.5 ? 2.0 * pitch : 1.0;
                     if (pitch < 0.2 | gain < 0.2)
                     {
                         buffer = null;
                     }
                 }
                 if (buffer != null)
                 {
                     Program.Sounds.PlaySound(buffer, pitch, gain, Position, Car, false);
                 }
             }
             this.DontTriggerAnymore = this.Once;
         }
     }
 }
Exemplo n.º 11
0
        /// <summary>
        /// Loads a sound file from hard drive.
        /// </summary>
        /// <param name="fileName">Full path name of the file with datatype ending, e.g. "C\:sound.ogg". A path can be absolute or relative.</param>
        /// <param name="streaming">if set to <c>true</c> [streaming].</param>
        /// <returns>An IAudioStream instance is returned if the file path was correctly resolved.</returns>
        public IAudioStream LoadFile(string fileName, bool streaming)
        {
            if (Path.GetExtension(fileName) == ".mp3")
            {
                throw new Exception("MP3 files are not supported. Please consider using OGG files instead.");
            }

            // sound already loaded?
            SoundBuffer tmpSndBuffer = null;

            if (!streaming)
            {
                foreach (
                    var audioStream in
                    _allStreams.Where(audioStream => !audioStream.IsStream && audioStream.FileName == fileName))
                {
                    tmpSndBuffer = audioStream.OutputBuffer;
                    break;
                }
            }

            IAudioStream tmpAudioStream = tmpSndBuffer == null
                                 ? new AudioStream(fileName, streaming)
                                 : new AudioStream(fileName, tmpSndBuffer);

            _allStreams.Add((AudioStream)tmpAudioStream);

            return(tmpAudioStream);
        }
Exemplo n.º 12
0
        public static void LoadSoundBuffer(string path)
        {
            Log.Info("Loading " + path + "...");
            SoundBuffer sound = new SoundBuffer(path);

            soundBuffers.Add(GetNameFromPath(path), sound);
        }
Exemplo n.º 13
0
        private void LoadAllMusic()
        {
            DirectoryInfo audioFolder        = new DirectoryInfo("audio/");
            Dictionary <string, Sound> audio = new Dictionary <string, Sound>();

            foreach (FileInfo file in audioFolder.GetFiles())
            {
                SoundBuffer buffer = new SoundBuffer("audio/" + file.Name);
                Sound       sound  = new Sound(buffer);

                StringBuilder soundName   = new StringBuilder();
                string[]      periodSplit = file.Name.Split('.');
                for (int i = 0; i < periodSplit.Length - 1; i++)
                {
                    if (i > 0)
                    {
                        soundName.Append('.');
                    }
                    soundName.Append(periodSplit[i]);
                }

                audio.Add(soundName.ToString(), sound);
            }

            Audio = audio;
        }
Exemplo n.º 14
0
        /// <summary>
        /// Initializes a new instance of the <see cref="AudioStreamImp"/> class.
        /// </summary>
        /// <param name="fileName">Name of the file.</param>
        /// <param name="sndBuffer">The SND buffer.</param>
        public AudioStreamImp(string fileName, SoundBuffer sndBuffer)
        {
            OutputBuffer = sndBuffer;
            _outputSound = new SFML.Audio.Sound(sndBuffer);

            Init(fileName, false);
        }
Exemplo n.º 15
0
            /// <summary>Releases the emergency brake</summary>
            internal void UnapplyEmergencyBrake()
            {
                if (Handles.EmergencyBrake.Driver)
                {
                    // sound
                    SoundBuffer buffer = Cars[DriverCar].Sounds.BrakeHandleRelease.Buffer;
                    if (buffer != null)
                    {
                        Vector3 pos = Cars[DriverCar].Sounds.BrakeHandleRelease.Position;
                        Program.Sounds.PlaySound(buffer, 1.0, 1.0, pos, Cars[DriverCar], false);
                    }

                    // apply

                    if (Handles.Brake is AirBrakeHandle)
                    {
                        ApplyAirBrakeHandle(AirBrakeHandleState.Service);
                    }
                    else
                    {
                        ApplyNotch(0, !Handles.SingleHandle, Handles.Brake.MaximumNotch, true);
                    }
                    Handles.EmergencyBrake.Driver = false;
                    // plugin
                    if (Plugin == null)
                    {
                        return;
                    }
                    Plugin.UpdatePower();
                    Plugin.UpdateBrake();
                }
            }
Exemplo n.º 16
0
        // --- loading buffers ---

        /// <summary>Loads the specified sound buffer.</summary>
        /// <param name="buffer">The sound buffer.</param>
        /// <returns>Whether loading the buffer was successful.</returns>
        internal static bool LoadBuffer(SoundBuffer buffer)
        {
            if (buffer.Loaded)
            {
                return(true);
            }
            if (buffer.Ignore)
            {
                return(false);
            }
            OpenBveApi.Sounds.Sound sound;
            if (buffer.Origin.GetSound(out sound))
            {
                if (sound.BitsPerSample == 8 | sound.BitsPerSample == 16)
                {
                    byte[] bytes = GetMonoMix(sound);
                    AL.GenBuffers(1, out buffer.OpenAlBufferName);
                    ALFormat format = sound.BitsPerSample == 8 ? ALFormat.Mono8 : ALFormat.Mono16;
                    AL.BufferData(buffer.OpenAlBufferName, format, bytes, bytes.Length, sound.SampleRate);
                    buffer.Duration = sound.Duration;
                    buffer.Loaded   = true;
                    return(true);
                }
            }
            buffer.Ignore = true;
            return(false);
        }
Exemplo n.º 17
0
 /// <summary>
 /// Load a new sound from a filepath. If this file has been used before it will be loaded from the cache.
 /// </summary>
 /// <param name="source">The path to the sound file.</param>
 /// <param name="loop">Determines if the sound should loop.</param>
 public Sound(string source, bool loop = false)
 {
     buffer = Sounds.Load(source);
     sound  = new SFML.Audio.Sound(buffer);
     Loop   = loop;
     sound.RelativeToListener = false;
 }
Exemplo n.º 18
0
 /// <summary>The default constructor</summary>
 internal Horn()
 {
     this.StartSound = null;
     this.LoopSound  = null;
     this.EndSound   = null;
     this.Loop       = false;
 }
Exemplo n.º 19
0
 private void NotifySoundLoaded(string path, SoundBuffer sound)
 {
     if (this.SoundLoaded != null)
     {
         this.SoundLoaded(path, sound);
     }
 }
Exemplo n.º 20
0
        /// <summary>
        /// Load a content from a asset file name
        /// </summary>
        /// <param name="assetFileName">Asset name, relative to the loader root directory, and including the file extension.</param>
        /// <returns>Return a SoundBuffer instance corresponding to the asset file name</returns>
        public override object Load(string assetFileName)
        {
            SoundBuffer sound = null;

            if (assetFileName.Length > 4 && assetFileName[assetFileName.Length - 4] == '.') // need to have 5 char mini x.xxx and a point before the format suffix.
            {
                //get the 4 last char
                string fileFormat = assetFileName.Substring(assetFileName.Length - 3, 3).ToUpper();

                if (this._supportFormat.Contains(fileFormat))
                {
                    try
                    {
                        sound = new SoundBuffer(assetFileName);
                    }
                    catch
                    {
                        throw;
                    }
                }
                else
                {
                    throw new ContentLoadException(typeof(SoundContentResolver).FullName, string.Format(Pulsar.Resources.Exceptions.ContentManager.FormatNotSupportByResolver, assetFileName, typeof(SoundContentResolver).FullName));
                }
            }
            else
            {
                throw new ContentLoadException(typeof(SoundContentResolver).FullName, string.Format(Pulsar.Resources.Exceptions.ContentManager.FileNameIncorrect, assetFileName));
            }

            return(sound);
        }
Exemplo n.º 21
0
 // --- constructors ---
 /// <summary>Creates a new sound source.</summary>
 /// <param name="buffer">The sound buffer.</param>
 /// <param name="radius">The effective sound radius.</param>
 /// <param name="pitch">The pitch change factor.</param>
 /// <param name="volume">The volume change factor.</param>
 /// <param name="position">The position. If a train and car are specified, the position is relative to the car, otherwise absolute.</param>
 /// <param name="parent">The parent object this sound source is attached to, or a null reference.</param>
 /// <param name="car">The car this sound source is attached to, or a null reference.</param>
 /// <param name="looped">Whether this sound source plays in a loop.</param>
 internal SoundSource(SoundBuffer buffer, double radius, double pitch, double volume, OpenBveApi.Math.Vector3 position, object parent, int car, bool looped)
 {
     this.Buffer           = buffer;
     this.Radius           = radius;
     this.Pitch            = pitch;
     this.Volume           = volume;
     this.Position         = position;
     this.Parent           = parent;
     this.Car              = car;
     this.Looped           = looped;
     this.State            = SoundSourceState.PlayPending;
     this.OpenAlSourceName = 0;
     //Set the sound type to undefined to use Michelle's original processing
     if (parent is TrainManager.Train)
     {
         this.Type = SoundType.TrainCar;
     }
     else if (parent is ObjectManager.WorldSound)
     {
         this.Type = SoundType.AnimatedObject;
     }
     else
     {
         this.Type = SoundType.Undefined;
     }
 }
Exemplo n.º 22
0
        /// <summary>
        /// Play a sound
        /// </summary>
        private static void PlaySound()
        {
            // Load a sound buffer from a wav file
            SoundBuffer buffer = new SoundBuffer("resources/canary.wav");

            // Display sound informations
            Console.WriteLine("canary.wav :");
            Console.WriteLine(" " + buffer.Duration + " sec");
            Console.WriteLine(" " + buffer.SampleRate + " samples / sec");
            Console.WriteLine(" " + buffer.ChannelsCount + " channels");

            // Create a sound instance and play it
            Sound sound = new Sound(buffer);

            sound.Play();

            // Loop while the sound is playing
            while (sound.Status == SoundStatus.Playing)
            {
                // Display the playing position
                Console.CursorLeft = 0;
                Console.Write("Playing... " + sound.PlayingOffset + " sec     ");

                // Leave some CPU time for other processes
                Thread.Sleep(100);
            }
        }
Exemplo n.º 23
0
        /// <summary>
        /// Play a sound
        /// </summary>
        private static void PlaySound()
        {
            var appPath  = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);
            var eatApple = string.Format(@"{0}\Assets\Sounds\drink_straw.wav", appPath);

            eatApple = "C:/OceanAirdrop/SFMLGame/Assets/Sounds/drink_straw.wav";

            // Load a sound buffer from a wav file
            SoundBuffer buffer = new SoundBuffer(eatApple);

            // Display sound informations
            Console.WriteLine("canary.wav :");
            Console.WriteLine(" " + buffer.Duration + " sec");
            Console.WriteLine(" " + buffer.SampleRate + " samples / sec");
            Console.WriteLine(" " + buffer.ChannelCount + " channels");

            // Create a sound instance and play it
            Sound sound = new Sound(buffer);

            sound.Play();

            // Loop while the sound is playing
            while (sound.Status == SoundStatus.Playing)
            {
                // Display the playing position
                Console.CursorLeft = 0;
                Console.Write("Playing... " + sound.PlayingOffset + " sec     ");

                // Leave some CPU time for other processes
            }
        }
Exemplo n.º 24
0
        /// <summary>
        /// Loads all available Texture, SoundBuffers and Fonts to make them usable.
        /// </summary>
        public static void LoadContent()
        {
            //FONTS:
            fontArial = new Font("C:/Windows/Fonts/Arial.ttf");

            //TEXTURES:
            textureTileSheet        = new Texture("Content/TileSheet.png");
            textureTileSheet.Smooth = true;

            textureTriangleCivil          = new Texture("Content/TriangleCivil.png");
            textureTriangleCivil.Smooth   = true;
            textureTriangleBandit1        = new Texture("Content/TriangleBandit1.png");
            textureTriangleBandit1.Smooth = true;
            textureTriangleBandit2        = new Texture("Content/TriangleBandit2.png");
            textureTriangleBandit2.Smooth = true;
            textureTriangleBandit3        = new Texture("Content/TriangleBandit3.png");
            textureTriangleBandit3.Smooth = true;
            textureTriangleBrute          = new Texture("Content/TriangleBrute.png");
            textureTriangleBrute.Smooth   = true;
            textureTriangleBomber         = new Texture("Content/TriangleBomber.png");
            textureTriangleBomber.Smooth  = true;
            textureTriangleLord           = new Texture("Content/TriangleLord.png");
            textureTriangleLord.Smooth    = true;

            textureSquareCivil            = new Texture("Content/SquareCivil.png");
            textureSquareCivil.Smooth     = true;
            textureSquareSoldier1         = new Texture("Content/SquareSoldier1.png");
            textureSquareSoldier1.Smooth  = true;
            textureSquareSoldier2         = new Texture("Content/SquareSoldier2.png");
            textureSquareSoldier2.Smooth  = true;
            textureSquareSoldier3         = new Texture("Content/SquareSoldier3.png");
            textureSquareSoldier3.Smooth  = true;
            textureSquareCommander        = new Texture("Content/SquareCommander.png");
            textureSquareCommander.Smooth = true;
            textureSquareGeneral          = new Texture("Content/SquareGeneral.png");
            textureSquareGeneral.Smooth   = true;

            texturePentagonCivil           = new Texture("Content/PentagonCivil.png");
            texturePentagonCivil.Smooth    = true;
            texturePentagonCenturio        = new Texture("Content/PentagonCenturio.png");
            texturePentagonCenturio.Smooth = true;

            textureProjectileVector        = new Texture("Content/ProjectileVector.png");
            textureProjectileVector.Smooth = true;
            textureProjectileEdge          = new Texture("Content/ProjectileEdge.png");
            textureProjectileEdge.Smooth   = true;

            // SOUNDS
            soundClick = new SoundBuffer("Content/113087__edgardedition__click2_16Bit.wav");
            // Source: https://www.freesound.org/people/EdgardEdition/sounds/113087/
            // Modified with Audacity to use 16 Bit flow.
            soundProjectileShot = new SoundBuffer("Content/156895__halgrimm__a-shot.wav");
            // Source: https://www.freesound.org/people/Halgrimm/sounds/156895/
            soundProjectileImpact = new SoundBuffer("Content/151713__bowlingballout__pvc-rocket-cannon_16Bit.wav");
            // Source: https://www.freesound.org/people/bowlingballout/sounds/151713/
            // Shortened and modified with Audacity to use 16 Bit flow.
            soundEnemyDeath = new SoundBuffer("Content/173126__replix__death-sound-male.wav");
            // Source: https://www.freesound.org/people/Replix/sounds/173126/
        }
Exemplo n.º 25
0
            internal void UpdateRunSounds(double TimeElapsed, int RunIndex)
            {
                if (Sounds.Run == null || Sounds.Run.Length == 0)
                {
                    return;
                }

                const double factor   = 0.04;               // 90 km/h -> m/s -> 1/x
                double       speed    = Math.Abs(Specs.CurrentSpeed);
                double       pitch    = speed * factor;
                double       baseGain = speed < 2.77777777777778 ? 0.36 * speed : 1.0;

                for (int j = 0; j < Sounds.Run.Length; j++)
                {
                    if (j == RunIndex)
                    {
                        Sounds.RunVolume[j] += 3.0 * TimeElapsed;

                        if (Sounds.RunVolume[j] > 1.0)
                        {
                            Sounds.RunVolume[j] = 1.0;
                        }
                    }
                    else
                    {
                        Sounds.RunVolume[j] -= 3.0 * TimeElapsed;

                        if (Sounds.RunVolume[j] < 0.0)
                        {
                            Sounds.RunVolume[j] = 0.0;
                        }
                    }

                    double gain = baseGain * Sounds.RunVolume[j];

                    if (Program.Sounds.IsPlaying(Sounds.Run[j].Source))
                    {
                        if (pitch > 0.01 & gain > 0.001)
                        {
                            Sounds.Run[j].Source.Pitch  = pitch;
                            Sounds.Run[j].Source.Volume = gain;
                        }
                        else
                        {
                            Program.Sounds.StopSound(Sounds.Run[j]);
                        }
                    }
                    else if (pitch > 0.02 & gain > 0.01)
                    {
                        SoundBuffer buffer = Sounds.Run[j].Buffer;

                        if (buffer != null)
                        {
                            Vector3 pos = Sounds.Run[j].Position;
                            Sounds.Run[j].Source = Program.Sounds.PlaySound(buffer, pitch, gain, pos, this, true);
                        }
                    }
                }
            }
Exemplo n.º 26
0
 /// <summary>
 ///     Liberar recursos del sonido
 /// </summary>
 public void dispose()
 {
     if (SoundBuffer != null && !SoundBuffer.Disposed)
     {
         SoundBuffer.Dispose();
         SoundBuffer = null;
     }
 }
Exemplo n.º 27
0
 /// <summary>The default constructor</summary>
 internal Horn(Train train)
 {
     this.StartSound = null;
     this.LoopSound  = null;
     this.EndSound   = null;
     this.Loop       = false;
     this.baseTrain  = train;
 }
Exemplo n.º 28
0
 public SoundInstance(SoundBuffer sound, float basePitch, float pitchVariance, float volume, bool looped = false)
 {
     this.sound         = new Sound(sound);
     this.basePitch     = basePitch;
     this.pitchVariance = pitchVariance;
     this.volume        = volume;
     this.looped        = looped;
 }
Exemplo n.º 29
0
 /// <summary>The default constructor</summary>
 public Horn(CarBase car)
 {
     this.StartSound = null;
     this.LoopSound  = null;
     this.EndSound   = null;
     this.Loop       = false;
     this.baseCar    = car;
 }
Exemplo n.º 30
0
 /// <summary>
 /// 他のバッファをFadeOut
 /// </summary>
 private void FadeOutOtherBGM()
 {
     foreach (GameObject buffer in buffers)
     {
         SoundBuffer sound = buffer.GetComponent <SoundBuffer>();
         sound.SetState(FadeState.FadeOut);
     }
 }
Exemplo n.º 31
0
			// --- constructors ---
			/// <summary>Creates a new sound source.</summary>
			/// <param name="buffer">The sound buffer.</param>
			/// <param name="radius">The effective sound radius.</param>
			/// <param name="pitch">The pitch change factor.</param>
			/// <param name="volume">The volume change factor.</param>
			/// <param name="position">The position. If a train and car are specified, the position is relative to the car, otherwise absolute.</param>
			/// <param name="train">The train this sound source is attached to, or a null reference.</param>
			/// <param name="car">The car this sound source is attached to, or a null reference.</param>
			/// <param name="looped">Whether this sound source plays in a loop.</param>
			internal SoundSource(SoundBuffer buffer, double radius, double pitch, double volume, OpenBveApi.Math.Vector3D position, TrainManager.Train train, int car, bool looped) {
				this.Buffer = buffer;
				this.Radius = radius;
				this.Pitch = pitch;
				this.Volume = volume;
				this.Position = position;
				this.Train = train;
				this.Car = car;
				this.Looped = looped;
				this.State = SoundSourceState.PlayPending;
				this.OpenAlSourceName = 0;
			}
    void AddBuffer(string filename, Sounds thisSound, bool looping, int volume)
    {
        SoundBuffer buffer;

        buffer = new SoundBuffer(
            soundDevice,
            filename,
            thisSound,
            looping);
        sounds.Add(buffer);
        buffer.Volume = volume;
    }
		public MultichannelMixerController ()
		{
			// create the URLs we'll use for source A and B
			var sourceA = NSBundle.MainBundle.PathForResource ("GuitarMonoSTP", "aif");
			var sourceB = NSBundle.MainBundle.PathForResource ("DrumsMonoSTP", "aif");

			sourceURL = new [] {
				CFUrl.FromFile (sourceA),
				CFUrl.FromFile (sourceB)
			};

			soundBuffer = new SoundBuffer[sourceURL.Length];
			for (int i = 0; i < soundBuffer.Length; ++i)
				soundBuffer [i] = new SoundBuffer ();
		}
Exemplo n.º 34
0
			// --- constructors ---
			/// <summary>Creates a new sound source.</summary>
			/// <param name="buffer">The sound buffer.</param>
			/// <param name="radius">The effective sound radius.</param>
			/// <param name="pitch">The pitch change factor.</param>
			/// <param name="volume">The volume change factor.</param>
			/// <param name="position">The position. If a train and car are specified, the position is relative to the car, otherwise absolute.</param>
			/// <param name="train">The train this sound source is attached to, or a null reference.</param>
			/// <param name="car">The car this sound source is attached to, or a null reference.</param>
			/// <param name="looped">Whether this sound source plays in a loop.</param>
			internal SoundSource(SoundBuffer buffer, double radius, double pitch, double volume, OpenBveApi.Math.Vector3 position, TrainManager.Train train, int car, bool looped) {
				this.Buffer = buffer;
				this.Radius = radius;
				this.Pitch = pitch;
				this.Volume = volume;
				this.Position = position;
				this.Train = train;
				this.Car = car;
				this.Looped = looped;
				this.State = SoundSourceState.PlayPending;
				this.OpenAlSourceName = 0;
				//Set the sound type to undefined to use Michelle's original processing
				if (train != null)
				{
					this.Type = SoundType.TrainCar;
				}
				else
				{
					this.Type = SoundType.Undefined;	
				}
				
			}
 /// <summary>Creates a new SlimDXSound.</summary>
 /// <param name="soundBuffer">The sound buffer.</param>
 public SlimDXSound(SoundBuffer soundBuffer)
 {
     _soundBuffer = soundBuffer;
 }
Exemplo n.º 36
0
		// load sound
		internal static int LoadSound(string FileName, double Radius) {
			if (OpenAlContext != IntPtr.Zero) {
				int i;
				for (i = 0; i < SoundBuffers.Length; i++) {
					if (SoundBuffers[i] != null && string.Compare(SoundBuffers[i].FileName, FileName, StringComparison.OrdinalIgnoreCase) == 0 & SoundBuffers[i].Radius == Radius) {
						return i;
					}
				}
				if (!FileName.EndsWith(".wav", StringComparison.OrdinalIgnoreCase)) {
					Interface.AddMessage(Interface.MessageType.Warning, false, "The file extension is not recognized - will be assumed to be a .wav file: " + FileName);
				}
				for (i = 0; i < SoundBuffers.Length; i++) {
					if (SoundBuffers[i] == null) break;
				}
				if (i == SoundBuffers.Length) {
					Array.Resize<SoundBuffer>(ref SoundBuffers, SoundBuffers.Length << 1);
				}
				SoundBuffers[i] = new SoundBuffer();
				SoundBuffers[i].FileName = FileName;
				SoundBuffers[i].OpenAlBufferIndex = new OpenAlIndex(0, false);
				SoundBuffers[i].Radius = (float)Radius;
				return i;
			} else {
				return -1;
			}
		}
Exemplo n.º 37
0
 ////////////////////////////////////////////////////////////
 /// <summary>
 /// Called when the current capture stops
 /// </summary>
 ////////////////////////////////////////////////////////////
 protected override void OnStop()
 {
     mySoundBuffer = new SoundBuffer(mySamplesArray.ToArray(), 1, SampleRate);
 }
 /// <summary>Disposes resources.</summary>
 public override void Dispose()
 {
     if(_soundBuffer != null)
     {
         try { _soundBuffer.Dispose(); }
         catch { }
         _soundBuffer = null;
     }
 }
Exemplo n.º 39
0
 ////////////////////////////////////////////////////////////
 /// <summary>
 /// Construct the sound buffer from another sound buffer
 /// </summary>
 /// <param name="copy">Sound buffer to copy</param>
 ////////////////////////////////////////////////////////////
 public SoundBuffer(SoundBuffer copy)
     : base(sfSoundBuffer_copy(copy.CPointer))
 {
 }
Exemplo n.º 40
0
 ////////////////////////////////////////////////////////////
 /// <summary>
 /// Construct the sound buffer from another sound buffer
 /// </summary>
 /// <param name="copy">Sound buffer to copy</param>
 ////////////////////////////////////////////////////////////
 public SoundBuffer(SoundBuffer copy)
     : base(sfSoundBuffer_Copy(copy.This))
 {
 }
Exemplo n.º 41
0
		// --- loading buffers ---
		
		/// <summary>Loads the specified sound buffer.</summary>
		/// <param name="buffer">The sound buffer.</param>
		/// <returns>Whether loading the buffer was successful.</returns>
		internal static bool LoadBuffer(SoundBuffer buffer) {
			if (buffer.Loaded)
				return true;
			if (buffer.Ignore)
				return false;

			OpenBveApi.Sounds.Sound sound;
			if (buffer.Origin.GetSound(out sound)) {
				if (sound.BitsPerSample == 8 || sound.BitsPerSample == 16) {
					byte[] bytes = GetMonoMix(sound);
					AL.GenBuffers(1, out buffer.OpenAlBufferName);
					ALFormat format = sound.BitsPerSample == 8 ? ALFormat.Mono8 : ALFormat.Mono16;
					AL.BufferData(buffer.OpenAlBufferName, format, bytes, bytes.Length, sound.SampleRate);
					buffer.Duration = sound.Duration;
					buffer.Loaded = true;
					return true;
				}
			}
			buffer.Ignore = true;
			return false;
		}
Exemplo n.º 42
0
 // --- registering buffers ---
 /// <summary>Registers a sound buffer and returns a handle to the buffer.</summary>
 /// <param name="path">The path to the sound.</param>
 /// <param name="radius">The default effective radius.</param>
 /// <returns>The handle to the sound buffer.</returns>
 internal static SoundBuffer RegisterBuffer(string path, double radius)
 {
     for (int i = 0; i < BufferCount; i++) {
         if (Buffers[i].Origin is PathOrigin) {
             if (((PathOrigin)Buffers[i].Origin).Path == path) {
                 return Buffers[i];
             }
         }
     }
     if (Buffers.Length == BufferCount) {
         Array.Resize<SoundBuffer>(ref Buffers, Buffers.Length << 1);
     }
     Buffers[BufferCount] = new SoundBuffer(path, radius);
     BufferCount++;
     return Buffers[BufferCount - 1];
 }
Exemplo n.º 43
0
 // --- loading buffers ---
 /// <summary>Loads the specified sound buffer.</summary>
 /// <param name="buffer">The sound buffer.</param>
 /// <returns>Whether loading the buffer was successful.</returns>
 internal static bool LoadBuffer(SoundBuffer buffer)
 {
     if (buffer.Loaded) {
         return true;
     } else if (buffer.Ignore) {
         return false;
     } else {
         OpenBveApi.Sounds.Sound sound;
         if (buffer.Origin.GetSound(out sound)) {
             if (sound.BitsPerSample == 8 | sound.BitsPerSample == 16) {
                 byte[] bytes = GetMonoMix(sound);
                 Al.alGenBuffers(1, out buffer.OpenAlBufferName);
                 int format = sound.BitsPerSample == 8 ? Al.AL_FORMAT_MONO8 : Al.AL_FORMAT_MONO16;
                 Al.alBufferData(buffer.OpenAlBufferName, format, bytes, bytes.Length, sound.SampleRate);
                 buffer.Duration = sound.Duration;
                 buffer.Loaded = true;
                 return true;
             }
         }
     }
     buffer.Ignore = true;
     return false;
 }
Exemplo n.º 44
0
 /// <summary>Plays a sound.</summary>
 /// <param name="buffer">The sound buffer.</param>
 /// <param name="pitch">The pitch change factor.</param>
 /// <param name="volume">The volume change factor.</param>
 /// <param name="position">The position. If a train and car are specified, the position is relative to the car, otherwise absolute.</param>
 /// <param name="train">The train the sound is attached to, or a null reference.</param>
 /// <param name="car">The car in the train the sound is attached to.</param>
 /// <param name="looped">Whether to play the sound in a loop.</param>
 /// <returns>The sound source.</returns>
 internal static SoundSource PlaySound(SoundBuffer buffer, double pitch, double volume, OpenBveApi.Math.Vector3 position, TrainManager.Train train, int car, bool looped)
 {
     if (Sources.Length == SourceCount) {
         Array.Resize<SoundSource>(ref Sources, Sources.Length << 1);
     }
     Sources[SourceCount] = new SoundSource(buffer, buffer.Radius, pitch, volume, position, train, car, looped);
     SourceCount++;
     return Sources[SourceCount - 1];
 }
Exemplo n.º 45
0
 ////////////////////////////////////////////////////////////
 /// <summary>
 /// Construct the sound from a source buffer
 /// </summary>
 /// <param name="buffer">Sound buffer to play</param>
 ////////////////////////////////////////////////////////////
 public Sound(SoundBuffer buffer)
     : base(sfSound_Create())
 {
     SoundBuffer = buffer;
 }
Exemplo n.º 46
0
 /// <summary>Registers a sound buffer and returns a handle to the buffer.</summary>
 /// <param name="data">The raw sound data.</param>
 /// <param name="radius">The default effective radius.</param>
 /// <returns>The handle to the sound buffer.</returns>
 internal static SoundBuffer RegisterBuffer(OpenBveApi.Sounds.Sound data, double radius)
 {
     if (Buffers.Length == BufferCount) {
         Array.Resize<SoundBuffer>(ref Buffers, Buffers.Length << 1);
     }
     Buffers[BufferCount] = new SoundBuffer(data, radius);
     BufferCount++;
     return Buffers[BufferCount - 1];
 }
Exemplo n.º 47
0
 // --- unloading buffers ---
 /// <summary>Unloads the specified sound buffer.</summary>
 /// <param name="buffer"></param>
 internal static void UnloadBuffer(SoundBuffer buffer)
 {
     if (buffer.Loaded) {
         Al.alDeleteBuffers(1, ref buffer.OpenAlBufferName);
         buffer.OpenAlBufferName = 0;
         buffer.Loaded = false;
         buffer.Ignore = false;
     }
 }
Exemplo n.º 48
0
 /// <summary>Gets the duration of the specified sound buffer in seconds.</summary>
 /// <param name="buffer">The sound buffer.</param>
 /// <returns>The duration of the sound buffer in seconds, or zero if the buffer could not be loaded.</returns>
 internal static double GetDuration(SoundBuffer buffer)
 {
     LoadBuffer(buffer);
     return buffer.Duration;
 }
Exemplo n.º 49
0
 // load sound
 internal static int LoadSound(string FileName, double Radius)
 {
     if (!Interface.CurrentOptions.UseSound) return -1;
     int i;
     for (i = 0; i < SoundBuffers.Length; i++) {
         if (SoundBuffers[i] != null && string.Compare(SoundBuffers[i].FileName, FileName, StringComparison.OrdinalIgnoreCase) == 0 & SoundBuffers[i].Radius == Radius) {
             return i;
         }
     }
     for (i = 0; i < SoundBuffers.Length; i++) {
         if (SoundBuffers[i] == null) break;
     }
     if (i == SoundBuffers.Length) {
         Array.Resize<SoundBuffer>(ref SoundBuffers, SoundBuffers.Length << 1);
     }
     SoundBuffers[i] = new SoundBuffer();
     SoundBuffers[i].FileName = FileName;
     SoundBuffers[i].OpenAlBufferIndex = new OpenAlIndex(0, false);
     SoundBuffers[i].Radius = (float)Radius;
     return i;
 }