예제 #1
0
        static void Main(string[] args)
        {
            // start the sound engine with default parameters
            ISoundEngine engine = new ISoundEngine();

            // To make irrKlang know about the memory we want to play, we register
            // the memory chunk as a sound source. We specify the name "testsound.wav", so
            // we can use the name later for playing back the sound. Note that you
            // could also specify a better fitting name like "ok.wav".
            // The method AddSoundSourceFromMemory() also returns a pointer to the created sound source,
            // it can be used as parameter for play2D() later, if you don't want to
            // play sounds via string names.

            ISoundSource source = engine.AddSoundSourceFromMemory(SoundDataArray, "testsound.wav");

            // now play the sound until user presses 'q'

            Console.Out.WriteLine("\nPlaying sounds directly from memory");
            Console.Out.WriteLine("Press any key to play some sound, press 'q' to quit.");

            do
            {
                // play the sound we added to memory
                engine.Play2D("testsound.wav");
            }while(_getch() != 'q');            // user pressed 'q' key, cancel
        }
예제 #2
0
        static public void play(byte[] song, string name, bool repeat)
        {
            stop();
            source = bgm.AddSoundSourceFromMemory(song, name);

            bgm.Play2D(source, repeat, false, true);
        }
예제 #3
0
        //#################################
        // LoadContent
        //#################################
        public override void LoadContent()
        {
            _stationSymbol = new UIItem();
            _stationSymbol.LoadContent("Images/station_icon", 4);
            _droneFleet.replaceOldDrone(new Vector3(150, 0, 100));
            Global.Camera = new Camera(Global.GraphicsManager.GraphicsDevice.DisplayMode.AspectRatio, 10000f, MathHelper.ToRadians(45), 1f, Global.CameraPosition, _droneFleet.GetActiveDrone().Position, Vector3.Up);
            _station.LoadContent();
            _planet.LoadContent();
            _sphere.LoadContent();
            _ui.LoadContent(_droneFleet);
            _frame.LoadContent();
            tutorialDialog.LoadContent();
            captainDialog.LoadContent();
            captain.LoadContent("Images/captain", 4);
            _asteroidField.LoadContent();
            //Sounds

            _engine = new ISpaceSoundEngine(SoundOutputDriver.AutoDetect, SoundEngineOptionFlag.LoadPlugins | SoundEngineOptionFlag.MultiThreaded | SoundEngineOptionFlag.MuteIfNotFocused | SoundEngineOptionFlag.Use3DBuffers);

            _explosionSource  = _engine.AddSoundSourceFromFile("Content/Media/Effects/Explosion.wav", StreamMode.AutoDetect, true);
            _explosionSource1 = _engine.AddSoundSourceFromFile("Content/Media/Effects/Objects/Explosion1.wav", StreamMode.AutoDetect, true);
            _explosionSource2 = _engine.AddSoundSourceFromFile("Content/Media/Effects/Objects/Explosion2.wav", StreamMode.AutoDetect, true);
            _explosionSource3 = _engine.AddSoundSourceFromFile("Content/Media/Effects/Objects/Explosion3.wav", StreamMode.AutoDetect, true);

            _openShop = _engine.AddSoundSourceFromFile("Content/Media/Effects/OkClick.wav", StreamMode.AutoDetect, true);


            Global.HighScorePoints = 0;
            Global.Money           = 0;
            Global.DroneDmg        = 10;
            Global.NumberOfRockets = 1;
            Global.SpeakerVolume   = 2;
        }
예제 #4
0
        public SFX(byte[] song, string name)
        {
            ISoundEngine sfx    = new ISoundEngine();
            ISoundSource source = sfx.AddSoundSourceFromMemory(song, name);

            sfx.Play2D(source, false, false, true);
        }
예제 #5
0
        public IrrklangPlayer(AudioClip clip)
        {
            if (!File.Exists(clip.CacheFileName))
            {
                throw new AGSEditorException("AudioClip file is missing from the audio cache");
            }

            if (Utilities.IsMonoRunning())
            {
                _soundEngine = new ISoundEngine(SoundOutputDriver.AutoDetect);
            }
            else
            {
                // explicitly ask for the software driver as there seem to
                // be issues with ISound returning bad data when re-using
                // the same source and certain audio drivers
                _soundEngine = new ISoundEngine(SoundOutputDriver.WinMM);
            }

            // we have to read it into memory and then play from memory,
            // because the built-in Irrklang play from file function keeps
            // the file open and locked
            byte[] audioData = File.ReadAllBytes(clip.CacheFileName);
            _source    = _soundEngine.AddSoundSourceFromMemory(audioData, clip.CacheFileName);
            _audioClip = clip;
        }
예제 #6
0
 public BulletMemory(string model, ISoundSource soundSource, float moveSpeed, bool canDmgStation)
 {
     this.model         = Global.ContentManager.Load <Model>(model);
     this.soundSource   = soundSource;
     this.moveSpeed     = moveSpeed;
     this.canDmgStation = canDmgStation;
 }
예제 #7
0
        public D2IngameCashCounterLogic(Widget widget, World world, WorldRenderer worldRenderer)
        {
            this.world      = world;
            player          = world.LocalPlayer;
            playerResources = player.PlayerActor.Trait <PlayerResources>();
            playerResources.AssignDelegates(TakeCash, TakeCash, TakeCash, TakeCash);

            displayResources = playerResources.Cash + playerResources.Resources;
            cashLabel        = playerResources.Resources.ToString();
            displayLabel     = cashLabel.F(displayResources);

            DuneMusic.Init(44100, "", DuneMusic.DuneMusicOplEmu.kOplEmuNuked);

            IReadOnlyFileSystem fileSystem = Game.ModData.DefaultFileSystem;

            using (var stream = fileSystem.Open("DUNE1.ADL"))
            {
                DuneMusic.InsertMemoryFile("test", stream.ReadAllBytes());
                byte[] temp = new byte[1800880];

                UIntPtr temp3;
                temp3 = (UIntPtr)1000000;
                temp3 = DuneMusic.SynthesizeAudio("test", 52, -1, temp, (UIntPtr)temp.Length);
                //stclick = new MemoryStream(temp);
                soundSource = Game.Sound.soundEngine.AddSoundSourceFromMemory(temp, 2, 16, 44100);
                //ISound temp2 = Game.Sound.soundEngine.Play2D(Game.LocalTick, soundSource, false, true, WPos.Zero, 100, false);
            }

            //cash.GetText = () => displayLabel;
            //cash.GetTooltipText = () => "Silo Usage: {0}/{1}".F(playerResources.Resources, playerResources.ResourceCapacity);
        }
예제 #8
0
        public static void play(byte[] song, string name, bool repeat)
        {
            stop();
            source = bgm.AddSoundSourceFromMemory(song, name);

            bgm.Play2D(source, repeat, false, true);
        }
예제 #9
0
 public override void Loaded()
 {
     if (_audio_id > -1)
     {
         _audioAsset = (Audio)Assets.find(_audio_id);
         _source     = Engine.sound.AddSoundSourceFromMemory(_audioAsset.data, _audioAsset.name + gameObject.ID);
     }
 }
예제 #10
0
 private void playFile()
 {
     resetTrackBar();
     mainSoundEngine.RemoveAllSoundSources();
     playingFile       = mainSoundEngine.AddSoundSourceFromFile(playFileLocation);
     currentlyPlaying  = mainSoundEngine.Play2D(playingFile.Name);
     trackBarIncrement = (int)playingFile.PlayLength / trackBarList.Count();
     trackBarPos       = 0;
 }
예제 #11
0
        private void pictureBox19_MouseDown(object sender, MouseEventArgs e)
        {
            pictureBox19.BackgroundImage = Properties.Resources.image2;
            ISoundEngine engine19 = new ISoundEngine();
            ISoundSource source19 = engine19.AddSoundSourceFromIOStream(Properties.Resources.SOLs, "wav");
            ISound       sound19  = engine19.Play2D(source19, false, false, true);

            keyboardkey.Text = "R";
            pianokey.Text    = "G#3";
        }
예제 #12
0
        internal AudioPlayer(AudioEngine audioEngine, string name, Stream res, AudioPreset preset) : this()
        {
            _soundEngine = AudioEngine.SoundEngine;

            FilePath = null;

            _soundSource = _soundEngine.AddSoundSourceFromIOStream(res, name);

            Add(preset, audioEngine.DefaultSourceEntity);
        }
예제 #13
0
        private void pictureBox15_MouseDown(object sender, MouseEventArgs e)
        {
            pictureBox15.BackgroundImage = Properties.Resources.image3;
            ISoundEngine engine15 = new ISoundEngine();
            ISoundSource source15 = engine15.AddSoundSourceFromIOStream(Properties.Resources.DO3, "wav");
            ISound       sound15  = engine15.Play2D(source15, false, false, true);

            keyboardkey.Text = "K";
            pianokey.Text    = "C5";
        }
예제 #14
0
        private void pictureBox14_MouseDown(object sender, MouseEventArgs e)
        {
            pictureBox14.BackgroundImage = Properties.Resources.image3;
            ISoundEngine engine14 = new ISoundEngine();
            ISoundSource source14 = engine14.AddSoundSourceFromIOStream(Properties.Resources.SI2, "wav");
            ISound       sound14  = engine14.Play2D(source14, false, false, true);

            keyboardkey.Text = "J";
            pianokey.Text    = "B4";
        }
예제 #15
0
 public void StopVideo()
 {
     if (video != null)
     {
         soundEngine.StopSound(video);
         videoSource.Dispose();
         videoSource = null;
         video       = null;
     }
 }
예제 #16
0
        private void pictureBox8_MouseDown(object sender, MouseEventArgs e)
        {
            pictureBox8.BackgroundImage = Properties.Resources.image3;
            ISoundEngine engine8 = new ISoundEngine();
            ISoundSource source8 = engine8.AddSoundSourceFromIOStream(Properties.Resources.DO2, "wav");
            ISound       sound8  = engine8.Play2D(source8, false, false, true);

            keyboardkey.Text = "A";
            pianokey.Text    = "C4";
        }
예제 #17
0
        private void pictureBox9_MouseDown(object sender, MouseEventArgs e)
        {
            pictureBox9.BackgroundImage = Properties.Resources.image3;
            ISoundEngine engine9 = new ISoundEngine();
            ISoundSource source9 = engine9.AddSoundSourceFromIOStream(Properties.Resources.RE2, "wav");
            ISound       sound9  = engine9.Play2D(source9, false, false, true);

            keyboardkey.Text = "S";
            pianokey.Text    = "D4";
        }
예제 #18
0
        private void pictureBox6_MouseDown(object sender, MouseEventArgs e)
        {
            pictureBox6.BackgroundImage = Properties.Resources.image3;
            ISoundEngine engine6 = new ISoundEngine();
            ISoundSource source6 = engine6.AddSoundSourceFromIOStream(Properties.Resources.LA, "wav");
            ISound       sound6  = engine6.Play2D(source6, false, false, true);

            keyboardkey.Text = "N";
            pianokey.Text    = "A3";
        }
예제 #19
0
        private void pictureBox7_MouseDown(object sender, MouseEventArgs e)
        {
            pictureBox7.BackgroundImage = Properties.Resources.image3;
            ISoundEngine engine7 = new ISoundEngine();
            ISoundSource source7 = engine7.AddSoundSourceFromIOStream(Properties.Resources.SI, "wav");
            ISound       sound7  = engine7.Play2D(source7, false, false, true);

            keyboardkey.Text = "M";
            pianokey.Text    = "B3";
        }
예제 #20
0
        private void pictureBox3_MouseDown(object sender, MouseEventArgs e)
        {
            pictureBox3.BackgroundImage = Properties.Resources.image3;
            ISoundEngine engine3 = new ISoundEngine();
            ISoundSource source3 = engine3.AddSoundSourceFromIOStream(Properties.Resources.MI, "wav");
            ISound       sound3  = engine3.Play2D(source3, false, false, true);

            keyboardkey.Text = "C";
            pianokey.Text    = "E3";
        }
예제 #21
0
        private void pictureBox2_MouseDown(object sender, MouseEventArgs e)
        {
            pictureBox2.BackgroundImage = Properties.Resources.image3;
            ISoundEngine engine2 = new ISoundEngine();
            ISoundSource source2 = engine2.AddSoundSourceFromIOStream(Properties.Resources.RE, "wav");
            ISound       sound2  = engine2.Play2D(source2, false, false, true);

            keyboardkey.Text = "X";
            pianokey.Text    = "D3";
        }
예제 #22
0
        private void pictureBox25_MouseDown(object sender, MouseEventArgs e)
        {
            pictureBox25.BackgroundImage = Properties.Resources.image2;
            ISoundEngine engine25 = new ISoundEngine();
            ISoundSource source25 = engine25.AddSoundSourceFromIOStream(Properties.Resources.LAs2, "wav");
            ISound       sound25  = engine25.Play2D(source25, false, false, true);

            keyboardkey.Text = "P";
            pianokey.Text    = "A#4";
        }
예제 #23
0
 public MySound(ISound sound, ISoundSource source)
 {
     Id        = Guid.NewGuid().ToString();
     Sound     = sound;
     Source    = source;
     Loop      = true;
     Stopped   = false;
     Volume    = 1.0f;
     Position  = new Vector3D(0f, 0f, 0f);
     IsPlaying = false;
 }
예제 #24
0
 public void Load(float defVolume = 1.0F)
 {
     try
     {
         SoundRef = SoundBank.SoundEngine.AddSoundSourceFromFile(FilePath);
         ChangeVolume(defVolume);
         isInitalized = true;
     }
     catch (Exception _e)
     {
         Logger.LogException(_e);
     }
 }
예제 #25
0
    //Generate all sounds from a file.
    private static Dictionary <string, ISoundSource> GetAllSoundFilesFromPath(string path)
    {
        Dictionary <string, ISoundSource> newSoundHash = new Dictionary <string, ISoundSource>();

        string[] files = Directory.GetFiles(Utils.PathToAssets + path);
        foreach (string s in files)
        {
            ISoundSource sound = Engine.AddSoundSourceFromFile(s);
            string       id    = Path.GetFileName(s);
            newSoundHash.Add(id, sound);
        }
        return(newSoundHash);
    }
예제 #26
0
 //Play a sound.
 public static void Play(string name, bool looped = false)
 {
     if (SoundHash.ContainsKey(name))
     {
         ISoundSource sound = SoundHash[name];
         sound.DefaultVolume = VolumeMax;
         Engine.Play2D(sound, looped, false, false);
     }
     else
     {
         Utils.Log("Couldn't play sound: " + name);
     }
 }
예제 #27
0
 public SoundFile(string filepath, string shortcutPath)
 {
     FilePath = shortcutPath;
     Source   = SoundEngine.AddSoundSourceFromFile(filepath, StreamMode.AutoDetect, false);
     if (Source == null)
     {
         Source = SoundEngine.GetSoundSource(filepath);
     }
     FileName     = Path.GetFileNameWithoutExtension(filepath);
     _displayName = DisplayNameFromFilename();
     //Length = Source.PlayLength;
     HasTrackList = TracklistExists(shortcutPath);
 }
예제 #28
0
        public void Play(ISoundEngine engine)
        {
            Byte[] data = new Byte[this.length * 2]; // signed 16-bit

            for (Int32 i = 0; i < this.length; i++)
            {
                Int16 sample = (Int16)values[i];
                data[i * 2]       += (byte)(sample >> 8);
                data[(i * 2) + 1] += (byte)(sample & 0xFF);
                //writer.Write(sample);
            }

            engine.RemoveSoundSource(name);
            this.source = engine.AddSoundSourceFromPCMData(data, name, fmt);
            engine.Play2D(name, true);
        }
예제 #29
0
        public override int LoadTrack(String location, String name)
        {
            String fullPath = Path.Combine(location, name);

            fullPath = fullPath + ".ogg";

            soundEngine = new ISoundEngine();
            ISoundSource song  = soundEngine.AddSoundSourceFromFile(fullPath, StreamMode.NoStreaming, true);
            ISound       sound = soundEngine.Play2D(song, false, true, true);

            if (sound != null)
            {
                return(tracks.Add(sound));
            }
            return(-1);
        }
예제 #30
0
파일: IrrklangPlayer.cs 프로젝트: mo-g/ags
        public IrrklangPlayer(AudioClip clip)
        {
            if (!File.Exists(clip.CacheFileName))
            {
                throw new AGSEditorException("AudioClip file is missing from the audio cache");
            }

            _soundEngine = new ISoundEngine(SoundOutputDriver.AutoDetect);

            // we have to read it into memory and then play from memory,
            // because the built-in Irrklang play from file function keeps
            // the file open and locked
            byte[] audioData = File.ReadAllBytes(clip.CacheFileName);
            _source    = _soundEngine.AddSoundSourceFromMemory(audioData, clip.CacheFileName);
            _audioClip = clip;
        }
예제 #31
0
        public override bool LoadSong(String location, String name)
        {
            String fullPath = Path.Combine(location, name);

            fullPath = fullPath + ".ogg";

            soundEngine = new ISoundEngine();
            ISoundSource song = soundEngine.AddSoundSourceFromFile(fullPath, StreamMode.NoStreaming, true);

            background  = soundEngine.Play2D(song, false, true, true);
            useBaseSong = false;
            if (background != null)
            {
                useBaseSong = true;
                return(true);
            }
            return(false);
        }
예제 #32
0
        private void OnSoundStopped(ISound sound, StopEventCause reason, object userData)
        {
            if (_soundSource != null)
            {
                _soundSource.Dispose();
            }
            _soundSource = null;

            //this dispose is here because sometimes sounds (over 4 seconds) were getting left in a locked state
            //but this didn't actually help.
            ((IrrKlang.ISoundEngine)userData).Dispose();


            var handler = PlaybackStopped;

            if (handler != null)
            {
                handler(this, EventArgs.Empty);
            }
        }
예제 #33
0
        public DashJavelin(ThingBlock block, ThingDefinition def)
            : base(block, def)
        {
            ModelComponent chassis = ModelComponents[0];
            // first get rid of the existing animation blender it creates automatically
            LKernel.GetG<AnimationManager>().Remove(chassis.AnimationBlender);
            chassis.AnimationBlender = null;

            Entity chassisEnt = chassis.Entity;
            // get our two animation states
            jetMax = chassisEnt.GetAnimationState("JetMax");
            jetMax.Enabled = true;
            jetMax.Weight = 0f;
            jetMin = chassisEnt.GetAnimationState("JetMin");
            jetMin.Enabled = true;
            jetMin.Weight = 1f;

            // we want the two animations to blend together, not add to each other
            chassisEnt.Skeleton.BlendMode = SkeletonAnimationBlendMode.ANIMBLEND_AVERAGE;

            jetRibbon = RibbonComponents[0].Ribbon;

            // sounds
            soundMain = LKernel.GetG<SoundMain>();

            idleSound = SoundComponents[0].Sound;
            fullSound = SoundComponents[1].Sound;
            revDownSound = soundMain.GetSource("RD_Kart_Rev_Down.ogg");
            revUpSound = soundMain.GetSource("RD_Kart_Rev_Up.ogg");

            // convert from linear velocity to KPH
            topSpeedKmHour = DefaultMaxSpeed * 3.6f;
            idleState = true;

            LKernel.GetG<Root>().FrameStarted += FrameStarted;
        }
예제 #34
0
 public Sound()
 {
     laser = engine.AddSoundSourceFromIOStream(Resourcen.laser, "laser");
 }
예제 #35
0
파일: Audio.cs 프로젝트: Zhenya21/Checkers
 public Audio(string filename)
 {
     _source = AudioProvider.GetSource(filename);
 }
예제 #36
0
파일: SoundPlayer.cs 프로젝트: zulis/Cubica
 public ISound Play(ISoundSource source)
 {
     return Play(source, false);
 }
예제 #37
0
파일: SoundPlayer.cs 프로젝트: zulis/Cubica
 public ISound Play(ISoundSource source, bool loop)
 {
     return GetSound(source, loop, true);
 }
예제 #38
0
        public ISound Play2D(ISoundSource sound, bool loop, bool relative, WPos pos, float volume, bool attenuateVolume)
        {
            if (sound == null)
            {
                Log.Write("sound", "Attempt to Play2D a null `ISoundSource`");
                return null;
            }

            var currFrame = Game.LocalTick;
            var atten = 1f;

            // Check if max # of instances-per-location reached:
            if (attenuateVolume)
            {
                int instances = 0, activeCount = 0;
                foreach (var s in sourcePool.Values)
                {
                    if (!s.IsActive)
                        continue;
                    if (s.IsRelative != relative)
                        continue;

                    ++activeCount;
                    if (s.Sound != sound)
                        continue;
                    if (currFrame - s.FrameStarted >= 5)
                        continue;

                    // Too far away to count?
                    var lensqr = (s.Pos - pos).LengthSquared;
                    if (lensqr >= GroupDistanceSqr)
                        continue;

                    // If we are starting too many instances of the same sound within a short time then stop this one:
                    if (++instances == MaxInstancesPerFrame)
                        return null;
                }

                // Attenuate a little bit based on number of active sounds:
                atten = 0.66f * ((PoolSize - activeCount * 0.5f) / PoolSize);
            }

            uint source;
            if (!TryGetSourceFromPool(out source))
                return null;

            var slot = sourcePool[source];
            slot.Pos = pos;
            slot.FrameStarted = currFrame;
            slot.Sound = sound;
            slot.IsRelative = relative;
            return new OpenAlSound(source, ((OpenAlSoundSource)sound).Buffer, loop, relative, pos, volume * atten);
        }
예제 #39
0
파일: Sound.cs 프로젝트: comradpara/OpenRA
 public ISound Play2D(ISoundSource sound, bool loop)
 {
     int source = GetSourceFromPool();
     return new OpenAlSound(source, (sound as OpenAlSoundSource).buffer, loop);
 }
예제 #40
0
        public void Play(ISoundEngine engine)
        {
            Byte[] data = new Byte[this.length * 2]; // signed 16-bit

            for (Int32 i = 0; i < this.length; i++)
            {
                Int16 sample = (Int16)values[i];
                data[i * 2] += (byte)(sample >> 8);
                data[(i * 2) + 1] += (byte)(sample & 0xFF);
                //writer.Write(sample);
            }

            engine.RemoveSoundSource(name);
            this.source = engine.AddSoundSourceFromPCMData(data, name, fmt);
            engine.Play2D(name, true);
        }
예제 #41
0
 public bool AssertSound(string sound_path, 
     string sound_name, out ISoundSource result)
 {
     if (sounds.TryGetValue(sound_name, out result))
         return true;
     else
     {
         if (!res_manager.IsResourceLoaded(sound_path))
         {
             result = null;
             return false;
         }
         byte[] buffer = res_manager.GetResource(sound_path);
         try
         {
             result = soundEngine.AddSoundSourceFromMemory(buffer, sound_name);
             result.StreamMode = StreamMode.AutoDetect;
         }
         catch (Exception ex)
         {
             LogConsole.Warning(Self, "Resource '{0}' is not a sound!", sound_path);
             LogConsole.Exception(Self, ex);
             result = null;
             return false;
         }
         sounds.Add(sound_name, result);
         return true;
     }
 }
예제 #42
0
        /// <summary>
        /// Creates an object sound. These sounds do have a 3D position and are attached to SceneNodes. Use these for sound effects and stuff.
        /// </summary>
        /// <param name="source">The sound source of the sound you want to play.</param>
        /// <param name="pos">The Position you want this sound to play at.</param>
        /// <param name="looping">Make this sound loop?</param>
        /// <param name="startPaused">Should this sound be paused when started? Default is false.</param>
        /// <param name="sfx">Does this sound have any effects? Default is false.</param>
        /// <returns>The ISound you just created, or null if we're using the null sound driver.</returns>
        public ISound Play3D(ISoundSource source, Vector3 pos, bool looping, bool startPaused = false, bool sfx = false)
        {
            if (pos == null)
                throw new ArgumentException("Position cannot be null!", "pos");

            Launch.Log("[Sounds] Creating 3D sound: " + source.Name + " Looping: " + looping);

            ISound sound = Engine.Play3D(source, pos.x, pos.y, pos.z, looping, startPaused, sfx);
            if(sound == null)
                return null;

            sounds.Add(sound);

            if (!enableSounds) {
                sound.Paused = true;
                sound.Volume = 0;
            }
            else if (startPaused)
                sound.Paused = true;

            return sound;
        }
예제 #43
0
        /// <summary>
        /// Creates a 2D music sound. This has no position and is controlled by a different option than the Play2D and Play3D methods.
        /// </summary>
        /// <param name="source">The sound source of the sound you want to play</param>
        /// <param name="startPaused">Should this sound be paused when started? Default is false.</param>
        /// <returns>The ISound you just created, or null if we're using the null sound driver.</returns>
        public ISound PlayMusic(ISoundSource source, bool startPaused = false)
        {
            Launch.Log("[Sounds] Creating music: " + source.Name);

            ISound music = Engine.Play2D(source, true, startPaused, false);
            if(music == null)
                return null;

            musics.Add(music);

            music.Volume = 0.5f;
            if (!enableMusic) {
                music.Paused = true;
                music.Volume = 0;
            }
            else if (startPaused)
                music.Paused = true;

            return music;
        }
예제 #44
0
        /// <summary>
        /// Creates an ambient sound. These have no 3D position or effects or anything, so this is ideal for level ambients and whatnot.
        /// </summary>
        /// <param name="source">The sound source of the sound you want to play.</param>
        /// <param name="looping">Make this sound loop?</param>
        /// <param name="startPaused">Should this sound be paused when started? Default is false.</param>
        /// <param name="sfx">Does this sound have any effects? Default is false.</param>
        /// <returns>The ISound you just created, or null if we're using the null sound driver.</returns>
        public ISound Play2D(ISoundSource source, bool looping, bool startPaused = false, bool sfx = false)
        {
            Launch.Log("[Sounds] Creating 2D sound: " + source.Name + " Looping: " + looping);

            ISound sound = Engine.Play2D(source, looping, startPaused, sfx);
            if(sound == null)
                return null;

            sounds.Add(sound);

            if (!enableSounds) {
                sound.Paused = true;
                sound.Volume = 0;
            }
            else if (startPaused)
                sound.Paused = true;

            return sound;
        }
예제 #45
0
        private void CarregaAudio()
        {
            // Piano
               source = engine.AddSoundSourceFromMemory(LibSom.AudioPiano.A1, "PIANO_A1.WAV");
               source = engine.AddSoundSourceFromMemory(LibSom.AudioPiano.A2, "PIANO_A2.WAV");
               source = engine.AddSoundSourceFromMemory(LibSom.AudioPiano.AS1, "PIANO_AS1.WAV");
               source = engine.AddSoundSourceFromMemory(LibSom.AudioPiano.AS2, "PIANO_AS2.WAV");
               source = engine.AddSoundSourceFromMemory(LibSom.AudioPiano.B1, "PIANO_B1.WAV");
               source = engine.AddSoundSourceFromMemory(LibSom.AudioPiano.B2, "PIANO_B2.WAV");
               source = engine.AddSoundSourceFromMemory(LibSom.AudioPiano.C1, "PIANO_C1.WAV");
               source = engine.AddSoundSourceFromMemory(LibSom.AudioPiano.C2, "PIANO_C2.WAV");
               source = engine.AddSoundSourceFromMemory(LibSom.AudioPiano.C3, "PIANO_C3.WAV");
               source = engine.AddSoundSourceFromMemory(LibSom.AudioPiano.CS1, "PIANO_CS1.WAV");
               source = engine.AddSoundSourceFromMemory(LibSom.AudioPiano.CS2, "PIANO_CS2.WAV");
               source = engine.AddSoundSourceFromMemory(LibSom.AudioPiano.D1, "PIANO_D1.WAV");
               source = engine.AddSoundSourceFromMemory(LibSom.AudioPiano.D2, "PIANO_D2.WAV");
               source = engine.AddSoundSourceFromMemory(LibSom.AudioPiano.DS1, "PIANO_DS1.WAV");
               source = engine.AddSoundSourceFromMemory(LibSom.AudioPiano.DS2, "PIANO_DS2.WAV");
               source = engine.AddSoundSourceFromMemory(LibSom.AudioPiano.E1, "PIANO_E1.WAV");
               source = engine.AddSoundSourceFromMemory(LibSom.AudioPiano.E2, "PIANO_E2.WAV");
               source = engine.AddSoundSourceFromMemory(LibSom.AudioPiano.F1, "PIANO_F1.WAV");
               source = engine.AddSoundSourceFromMemory(LibSom.AudioPiano.F2, "PIANO_F2.WAV");
               source = engine.AddSoundSourceFromMemory(LibSom.AudioPiano.FS1, "PIANO_FS1.WAV");
               source = engine.AddSoundSourceFromMemory(LibSom.AudioPiano.FS2, "PIANO_FS2.WAV");
               source = engine.AddSoundSourceFromMemory(LibSom.AudioPiano.G1, "PIANO_G1.WAV");
               source = engine.AddSoundSourceFromMemory(LibSom.AudioPiano.G2, "PIANO_G2.WAV");
               source = engine.AddSoundSourceFromMemory(LibSom.AudioPiano.GS1, "PIANO_GS1.WAV");
               source = engine.AddSoundSourceFromMemory(LibSom.AudioPiano.GS2, "PIANO_GS2.WAV");

               // Guitar
               source = engine.AddSoundSourceFromMemory(LibSom.AudioGuitar.A1, "GUITAR_A1.WAV");
               source = engine.AddSoundSourceFromMemory(LibSom.AudioGuitar.A2, "GUITAR_A2.WAV");
               source = engine.AddSoundSourceFromMemory(LibSom.AudioGuitar.AS1, "GUITAR_AS1.WAV");
               source = engine.AddSoundSourceFromMemory(LibSom.AudioGuitar.AS2, "GUITAR_AS2.WAV");
               source = engine.AddSoundSourceFromMemory(LibSom.AudioGuitar.B1, "GUITAR_B1.WAV");
               source = engine.AddSoundSourceFromMemory(LibSom.AudioGuitar.B2, "GUITAR_B2.WAV");
               source = engine.AddSoundSourceFromMemory(LibSom.AudioGuitar.C1, "GUITAR_C1.WAV");
               source = engine.AddSoundSourceFromMemory(LibSom.AudioGuitar.C2, "GUITAR_C2.WAV");
               source = engine.AddSoundSourceFromMemory(LibSom.AudioGuitar.C3, "GUITAR_C3.WAV");
               source = engine.AddSoundSourceFromMemory(LibSom.AudioGuitar.CS1, "GUITAR_CS1.WAV");
               source = engine.AddSoundSourceFromMemory(LibSom.AudioGuitar.CS2, "GUITAR_CS2.WAV");
               source = engine.AddSoundSourceFromMemory(LibSom.AudioGuitar.D1, "GUITAR_D1.WAV");
               source = engine.AddSoundSourceFromMemory(LibSom.AudioGuitar.D2, "GUITAR_D2.WAV");
               source = engine.AddSoundSourceFromMemory(LibSom.AudioGuitar.DS1, "GUITAR_DS1.WAV");
               source = engine.AddSoundSourceFromMemory(LibSom.AudioGuitar.DS2, "GUITAR_DS2.WAV");
               source = engine.AddSoundSourceFromMemory(LibSom.AudioGuitar.E1, "GUITAR_E1.WAV");
               source = engine.AddSoundSourceFromMemory(LibSom.AudioGuitar.E2, "GUITAR_E2.WAV");
               source = engine.AddSoundSourceFromMemory(LibSom.AudioGuitar.F1, "GUITAR_F1.WAV");
               source = engine.AddSoundSourceFromMemory(LibSom.AudioGuitar.F2, "GUITAR_F2.WAV");
               source = engine.AddSoundSourceFromMemory(LibSom.AudioGuitar.FS1, "GUITAR_FS1.WAV");
               source = engine.AddSoundSourceFromMemory(LibSom.AudioGuitar.FS2, "GUITAR_FS2.WAV");
               source = engine.AddSoundSourceFromMemory(LibSom.AudioGuitar.G1, "GUITAR_G1.WAV");
               source = engine.AddSoundSourceFromMemory(LibSom.AudioGuitar.G2, "GUITAR_G2.WAV");
               source = engine.AddSoundSourceFromMemory(LibSom.AudioGuitar.GS1, "GUITAR_GS1.WAV");
               source = engine.AddSoundSourceFromMemory(LibSom.AudioGuitar.GS2, "GUITAR_GS2.WAV");

               // Percussion
               source = engine.AddSoundSourceFromMemory(LibSom.AudioPercussion.A1, "PERCUSSION_A1.WAV");
               source = engine.AddSoundSourceFromMemory(LibSom.AudioPercussion.A2, "PERCUSSION_A2.WAV");
               source = engine.AddSoundSourceFromMemory(LibSom.AudioPercussion.AS1, "PERCUSSION_AS1.WAV");
               source = engine.AddSoundSourceFromMemory(LibSom.AudioPercussion.AS2, "PERCUSSION_AS2.WAV");
               source = engine.AddSoundSourceFromMemory(LibSom.AudioPercussion.B1, "PERCUSSION_B1.WAV");
               source = engine.AddSoundSourceFromMemory(LibSom.AudioPercussion.B2, "PERCUSSION_B2.WAV");
               source = engine.AddSoundSourceFromMemory(LibSom.AudioPercussion.C1, "PERCUSSION_C1.WAV");
               source = engine.AddSoundSourceFromMemory(LibSom.AudioPercussion.C2, "PERCUSSION_C2.WAV");
               source = engine.AddSoundSourceFromMemory(LibSom.AudioPercussion.C3, "PERCUSSION_C3.WAV");
               source = engine.AddSoundSourceFromMemory(LibSom.AudioPercussion.CS1, "PERCUSSION_CS1.WAV");
               source = engine.AddSoundSourceFromMemory(LibSom.AudioPercussion.CS2, "PERCUSSION_CS2.WAV");
               source = engine.AddSoundSourceFromMemory(LibSom.AudioPercussion.D1, "PERCUSSION_D1.WAV");
               source = engine.AddSoundSourceFromMemory(LibSom.AudioPercussion.D2, "PERCUSSION_D2.WAV");
               source = engine.AddSoundSourceFromMemory(LibSom.AudioPercussion.DS1, "PERCUSSION_DS1.WAV");
               source = engine.AddSoundSourceFromMemory(LibSom.AudioPercussion.DS2, "PERCUSSION_DS2.WAV");
               source = engine.AddSoundSourceFromMemory(LibSom.AudioPercussion.E1, "PERCUSSION_E1.WAV");
               source = engine.AddSoundSourceFromMemory(LibSom.AudioPercussion.E2, "PERCUSSION_E2.WAV");
               source = engine.AddSoundSourceFromMemory(LibSom.AudioPercussion.F1, "PERCUSSION_F1.WAV");
               source = engine.AddSoundSourceFromMemory(LibSom.AudioPercussion.F2, "PERCUSSION_F2.WAV");
               source = engine.AddSoundSourceFromMemory(LibSom.AudioPercussion.FS1, "PERCUSSION_FS1.WAV");
               source = engine.AddSoundSourceFromMemory(LibSom.AudioPercussion.FS2, "PERCUSSION_FS2.WAV");
               source = engine.AddSoundSourceFromMemory(LibSom.AudioPercussion.G1, "PERCUSSION_G1.WAV");
               source = engine.AddSoundSourceFromMemory(LibSom.AudioPercussion.G2, "PERCUSSION_G2.WAV");
               source = engine.AddSoundSourceFromMemory(LibSom.AudioPercussion.GS1, "PERCUSSION_GS1.WAV");
               source = engine.AddSoundSourceFromMemory(LibSom.AudioPercussion.GS2, "PERCUSSION_GS2.WAV");

            // Vioin

            /*           source = engine.AddSoundSourceFromMemory(LibSom.AudioViolin1.A1 , "VIOLIN_A1.WAV");
               source = engine.AddSoundSourceFromMemory(LibSom.AudioViolin1.A2 , "VIOLIN_A2.WAV");
               source = engine.AddSoundSourceFromMemory(LibSom.AudioViolin1.AS1 , "VIOLIN_AS1.WAV");
               source = engine.AddSoundSourceFromMemory(LibSom.AudioViolin1.AS2 , "VIOLIN_AS2.WAV");

               source = engine.AddSoundSourceFromMemory(LibSom.AudioViolin2.B1 , "VIOLIN_B1.WAV");
               source = engine.AddSoundSourceFromMemory(LibSom.AudioViolin2.B2 , "VIOLIN_B2.WAV");
               source = engine.AddSoundSourceFromMemory(LibSom.AudioViolin2.C1 , "VIOLIN_C1.WAV");
               source = engine.AddSoundSourceFromMemory(LibSom.AudioViolin2.C2 , "VIOLIN_C2.WAV");

               source = engine.AddSoundSourceFromMemory(LibSom.AudioViolin3.C3 , "VIOLIN_C3.WAV");
               source = engine.AddSoundSourceFromMemory(LibSom.AudioViolin3.CS1 , "VIOLIN_CS1.WAV");
               source = engine.AddSoundSourceFromMemory(LibSom.AudioViolin3.CS2 , "VIOLIN_CS2.WAV");
               source = engine.AddSoundSourceFromMemory(LibSom.AudioViolin3.D1 , "VIOLIN_D1.WAV");

               source = engine.AddSoundSourceFromMemory(LibSom.AudioViolin4.D2 , "VIOLIN_D2.WAV");
               source = engine.AddSoundSourceFromMemory(LibSom.AudioViolin4.DS1 , "VIOLIN_DS1.WAV");
               source = engine.AddSoundSourceFromMemory(LibSom.AudioViolin4.DS2 , "VIOLIN_DS2.WAV");
               source = engine.AddSoundSourceFromMemory(LibSom.AudioViolin4.E1 , "VIOLIN_E1.WAV");

               source = engine.AddSoundSourceFromMemory(LibSom.AudioViolin5.E2  , "VIOLIN_E2.WAV");
               source = engine.AddSoundSourceFromMemory(LibSom.AudioViolin5.F1  , "VIOLIN_F1.WAV");
               source = engine.AddSoundSourceFromMemory(LibSom.AudioViolin5.F2  , "VIOLIN_F2.WAV");
               source = engine.AddSoundSourceFromMemory(LibSom.AudioViolin5.FS1  , "VIOLIN_FS1.WAV");

               source = engine.AddSoundSourceFromMemory(LibSom.AudioViolin6.FS2 , "VIOLIN_FS2.WAV");
               source = engine.AddSoundSourceFromMemory(LibSom.AudioViolin6.G1 , "VIOLIN_F1.WAV");
               source = engine.AddSoundSourceFromMemory(LibSom.AudioViolin6.G2 , "VIOLIN_F2.WAV");
               source = engine.AddSoundSourceFromMemory(LibSom.AudioViolin6.GS1 , "VIOLIN_GS1.WAV");
               source = engine.AddSoundSourceFromMemory(LibSom.AudioViolin6.GS2 , "VIOLIN_GS2.WAV");
            */
        }
예제 #46
0
파일: Sound.cs 프로젝트: mgatland/OpenRA
 public static void PlayVideo(byte[] raw)
 {
     rawSource = LoadSoundRaw(raw);
     video = soundEngine.Play2D(rawSource, false, true, float2.Zero, SoundVolume);
 }
예제 #47
0
파일: Sound.cs 프로젝트: OpenRA/OpenRA
 public void PlayVideo(byte[] raw, int channels, int sampleBits, int sampleRate)
 {
     rawSource = soundEngine.AddSoundSourceFromMemory(raw, channels, sampleBits, sampleRate);
     video = soundEngine.Play2D(rawSource, false, true, WPos.Zero, InternalSoundVolume, false);
 }
예제 #48
0
파일: Sound.cs 프로젝트: JamesDunne/OpenRA
 public ISound Play2D(ISoundSource sound, bool loop, bool relative, float2 pos, float volume)
 {
     return new NullSound();
 }
예제 #49
0
파일: Sound.cs 프로젝트: Generalcamo/OpenRA
 public static void PlayVideo(byte[] raw)
 {
     rawSource = LoadSoundRaw(raw);
     video = soundEngine.Play2D(rawSource, false, true, WPos.Zero, InternalSoundVolume, false);
 }
예제 #50
0
 public bool GetSound(string sound_name, out ISoundSource result)
 {
     if (sounds.TryGetValue(sound_name, out result))
         return true;
     else
     {
         LogConsole.Warning(Self, "Sound '{0}' is not registered!", sound_name);
         return false;
     }
 }
예제 #51
0
파일: Sound.cs 프로젝트: Generalcamo/OpenRA
        public ISound Play2D(ISoundSource sound, bool loop, bool relative, WPos pos, float volume, bool attenuateVolume)
        {
            if (sound == null)
            {
                Log.Write("sound", "Attempt to Play2D a null `ISoundSource`");
                return null;
            }

            var world = Game.orderManager.world;
            int currFrame = world != null ? world.FrameNumber : 0;
            float atten = 1f;

            // Check if max # of instances-per-location reached:
            if (attenuateVolume)
            {
                int instances = 0, activeCount = 0;
                foreach (var s in sourcePool.Values)
                {
                    if (!s.isActive)
                        continue;
                    if (s.isRelative != relative)
                        continue;

                    ++activeCount;
                    if (s.sound != sound)
                        continue;
                    if (currFrame - s.frameStarted >= 5)
                        continue;

                    // Too far away to count?
                    var lensqr = (s.pos - pos).LengthSquared;
                    if (lensqr >= groupDistanceSqr)
                        continue;

                    // If we are starting too many instances of the same sound within a short time then stop this one:
                    if (++instances == maxInstancesPerFrame)
                        return null;
                }

                // Attenuate a little bit based on number of active sounds:
                atten = 0.66f * ((POOL_SIZE - activeCount * 0.5f) / POOL_SIZE);
            }

            int source = GetSourceFromPool();
            if (source == -1) return null;

            var slot = sourcePool[source];
            slot.pos = pos;
            slot.frameStarted = currFrame;
            slot.sound = sound;
            slot.isRelative = relative;
            return new OpenAlSound(source, (sound as OpenAlSoundSource).buffer, loop, relative, pos, volume * atten);
        }
예제 #52
0
 /// <summary>
 /// Initializes the sound
 /// </summary>
 /// <param name="defVolume">default volume for the sound, between 0.0F and 1.0F</param>
 /// <param name="volumeAdjust">do not attempt at all to set volume for this sound (used as override for irrklang issue)</param>
 public void Load(float defVolume = 1.0F, bool volumeAdjust = true)
 {
     soundRef = SoundBank.SoundEngine.AddSoundSourceFromFile(filePath);
     isInitalized = true;
     if (volumeAdjust) ChangeVolume(defVolume);
 }
예제 #53
0
파일: Sound.cs 프로젝트: JamesDunne/OpenRA
 public ISound Play2D(ISoundSource sound, bool loop, bool relative, float2 pos, float volume)
 {
     int source = GetSourceFromPool();
     return new OpenAlSound(source, (sound as OpenAlSoundSource).buffer, loop, relative, pos, volume);
 }
예제 #54
0
파일: SoundPlayer.cs 프로젝트: zulis/Cubica
 public ISound GetSound(ISoundSource source, bool loop, bool play)
 {
     return engine.Play2D(source, loop, !play, false);
 }
예제 #55
0
        public void Play()
        {
            if(IsRecording)
                throw new ApplicationException("Can't play while recording.");

            if (_sound != null)
            {
                _engine.StopAllSounds();
            }

            if(!File.Exists(_path))
                throw new FileNotFoundException("Could not find sound file", _path);

            //turns out, the silly engine will keep playing the same recording, even
            //after we've chaned the contents of the file or even delete it.
            //so, we need to make a new engine.
            //   NO   _sound = _engine.Play2D(path, false);

            var engine = new IrrKlang.ISoundEngine();

            // we have to read it into memory and then play from memory,
            // because the built-in Irrklang play from file function keeps
            // the file open and locked
            byte[] audioData = File.ReadAllBytes(_path);	//REVIEW: will this leak?
             _soundSource = engine.AddSoundSourceFromMemory(audioData, _path);
            if (_sound != null)
                _sound.Dispose();
            _sound = engine.Play2D(_soundSource, false, false, false);
            _sound.setSoundStopEventReceiver(_irrklangEventProxy,engine);
        }
예제 #56
0
 void IResource.LoadFromXML(XmlNode node)
 {
     //try
     {
         float vol = 1.25f;
         float mndist = 1;
         float mxdist = 50;
         foreach (XmlAttribute attrib in node.Attributes)
         {
             switch (attrib.Name)
             {
                 case "name":
                     name = attrib.Value;
                     break;
                 case "filename":
                     sound = SoundEngine.Device.AddSoundSourceFromFile(attrib.Value);
                     break;
                 case "volume":
                     float.TryParse(attrib.Value, out vol);
                     break;
                 case "mindistance":
                     float.TryParse(attrib.Value, out mndist);
                     break;
                 case "maxdistance":
                     float.TryParse(attrib.Value, out mxdist);
                     break;
             }
             Volume = vol;
             MaxDistance = mxdist;
             MinDistance = mndist;
         }
     }
     /*
     catch
     {
         sound.Dispose();
     }*/
 }
예제 #57
0
파일: Sound.cs 프로젝트: Generalcamo/OpenRA
 public ISound Play2D(ISoundSource sound, bool loop, bool relative, WPos pos, float volume, bool attenuateVolume)
 {
     return new NullSound();
 }
예제 #58
0
        private void OnSoundStopped(ISound sound, StopEventCause reason, object userData)
        {
            if (_soundSource != null)
                _soundSource.Dispose();
            _soundSource = null;

            //this dispose is here because sometimes sounds (over 4 seconds) were getting left in a locked state
            //but this didn't actually help.
            ((IrrKlang.ISoundEngine)userData).Dispose();

            var handler = PlaybackStopped;
            if (handler != null) handler(this, EventArgs.Empty);
        }
예제 #59
0
 public MySound(ISound sound, ISoundSource source)
 {
     Id = Guid.NewGuid().ToString();
     Sound = sound;
     Source = source;
     Loop = true;
     Stopped = false;
     Volume = 1.0f;
     Position = new Vector3D(0f, 0f, 0f);
     IsPlaying = false;
 }
예제 #60
0
 public override void Loaded()
 {
     if (_audio_id > -1)
     {
         _audioAsset = (Audio)Assets.find(_audio_id);
         _source = Engine.sound.AddSoundSourceFromMemory(_audioAsset.data, _audioAsset.name + gameObject.ID);
     }
 }