/// <summary> /// Play a sound /// </summary> private static void PlaySound() { // Load a sound buffer from a wav file SoundBuffer Buffer = new SoundBuffer("datas/sound/footsteps.wav"); // Display sound informations Console.WriteLine("footsteps.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); } }
/// <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"></param> public Sound(string source, bool loop = false) { buffer = Sounds.Load(source); sound = new SFML.Audio.Sound(buffer); Loop = loop; sound.RelativeToListener = false; }
public static void PlaySound(string filename) { var buffer = new SoundBuffer(filename); var sound = new Sound(buffer); sound.Play(); }
/// <summary> /// Initializes a new instance of the <see cref="AudioStream"/> class. /// </summary> /// <param name="fileName">Name of the file.</param> /// <param name="sndBuffer">The SND buffer.</param> public AudioStream(string fileName, SoundBuffer sndBuffer) { OutputBuffer = sndBuffer; _outputSound = new Sound(sndBuffer); Init(fileName, false); }
public static void PrecacheSound(string what) { if (sounds.ContainsKey(what)) { return; } string thePath = Path.Combine(RootDirectory, what); SoundBuffer theFont = new SoundBuffer(thePath); sounds.Add(what, theFont); }
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; }
public SoundManager() { SoundBuffer sb = new SoundBuffer(@"sounds/explosion.wav"); m_SoundBufferList.Add("explosion", sb); sb = new SoundBuffer(@"sounds/laser.wav"); m_SoundBufferList.Add("laser", sb); sb = new SoundBuffer(@"sounds/hit.wav"); m_SoundBufferList.Add("hit", sb); sb = new SoundBuffer(@"sounds/powerup.wav"); m_SoundBufferList.Add("powerup", sb); }
/// <summary> /// Loads a sound from the base sound directory. LoadSound will cache sounds by name. /// </summary> public static SoundBuffer LoadSound(string name) { SoundBuffer soundBuffer; if (!Buffers.TryGetValue(name, out soundBuffer)) { soundBuffer = new SoundBuffer(Path.Combine(BaseLocation, SoundLocation, name)); Buffers.Add(name, soundBuffer); } return soundBuffer; }
public static SoundBuffer LoadSound(string name) { SoundBuffer sb; if (!Buffers.TryGetValue(name, out sb)) { sb = new SoundBuffer(Path.Combine(GameOptions.SoundLocation, name)); Buffers.Add(name, sb); } return sb; }
/// <summary> /// Initializes a new instance of the <see cref="AudioStream"/> class. /// </summary> /// <param name="fileName">Name of the file.</param> /// <param name="streaming">if set to <c>true</c> [streaming].</param> public AudioStream(string fileName, bool streaming) { if (streaming) _outputStream = new Music(fileName); else { OutputBuffer = new SoundBuffer(fileName); _outputSound = new Sound(OutputBuffer); } Init(fileName, streaming); }
public SoundBuffer GetSound(string soundName) { if (hashtableSoundBuffers.ContainsKey(soundName)) { return (SoundBuffer)hashtableSoundBuffers[soundName]; } else { SoundBuffer soundBuffer = new SoundBuffer(soundName); hashtableSoundBuffers.Add(soundName, soundBuffer); return soundBuffer; } }
public Sample(string path) { this.path = path; // determine name var s = path.LastIndexOf('\\'); name = path.Substring(s + 1); s = name.LastIndexOf('.'); if (s >= 0) name = name.Substring(0, s); // aight, create buffer this.buffer = new SA.SoundBuffer(path); this.volume_modifier = 1f; this.index = count; count++; }
public CannonWeapon(Game game, Entity sourceObject) : base(game, sourceObject) { ProjectileSpeed = 600.0f; Damage = 4000; ProjectileRotateSpeed = 10; ShootSoundBuffer1 = new SoundBuffer("assets/audio/shotgun1.ogg"); ShootSoundBuffer2 = new SoundBuffer("assets/audio/shotgun2.ogg"); ShootSound1 = new Sound(ShootSoundBuffer1); ShootSound2 = new Sound(ShootSoundBuffer2); ExplosionSoundBuffer1 = new SoundBuffer("assets/audio/explode1.ogg"); ExplosionSoundBuffer2 = new SoundBuffer("assets/audio/explode2.ogg"); ExplosionSound1 = new Sound(ExplosionSoundBuffer1); ExplosionSound2 = new Sound(ExplosionSoundBuffer2); SplashSoundBuffer1 = new SoundBuffer("assets/audio/splash1.ogg"); SplashSoundBuffer2 = new SoundBuffer("assets/audio/splash2.ogg"); SplashSound1 = new Sound(SplashSoundBuffer1); SplashSound2 = new Sound(SplashSoundBuffer2); }
private void LoadResources() { // Set up start screen graphics Texture txStart = new Texture(@"resources\logo.png"); spStart = new Sprite(txStart); // Main game screen background Texture txBack = new Texture(@"resources\back.png"); spBack = new Sprite(txBack); Texture txDot = new Texture(@"resources\dot.png"); spDot = new Sprite(txDot); powerSprites[0] = new Texture(@"resources\power-1.png"); powerSprites[1] = new Texture(@"resources\power-2.png"); powerSprites[2] = new Texture(@"resources\power-3.png"); spPower = new Sprite((Texture)powerSprites[powerSpriteId]); startBuffer = new SFML.Audio.SoundBuffer(@"resources\pacman_beginning.wav"); startSound = new SFML.Audio.Sound(startBuffer); chompBuffer = new SFML.Audio.SoundBuffer(@"resources\dot.wav"); chompSound = new SFML.Audio.Sound(chompBuffer); energizerBuffer = new SFML.Audio.SoundBuffer(@"resources\energizer.wav"); energizerSound = new SFML.Audio.Sound(energizerBuffer); sirenBuffer = new SFML.Audio.SoundBuffer(@"resources\siren.wav"); sirenSound = new SFML.Audio.Sound(sirenBuffer); playerDeathBuffer = new SFML.Audio.SoundBuffer(@"resources\pacman_death.wav"); playerDeathSound = new SFML.Audio.Sound(playerDeathBuffer); }
/// <summary> /// Load a new sound from copying another sound. /// </summary> /// <param name="sound">The sound to copy from.</param> public Sound(Sound sound) { buffer = sound.buffer; this.sound = new SFML.Audio.Sound(buffer); Loop = sound.Loop; sound.RelativeToListener = sound.RelativeToListener; X = sound.X; Y = sound.Y; Z = sound.Z; Volume = sound.Volume; Pitch = sound.Pitch; Attenuation = sound.Attenuation; MinimumDistance = sound.MinimumDistance; Offset = sound.Offset; }
/// <summary> /// Load a new sound from an IO Stream. /// </summary> /// <param name="stream">The memory stream of the sound data.</param> /// <param name="loop">Determines if the sound should loop.</param> public Sound(Stream stream, bool loop = false) { buffer = new SoundBuffer(stream); sound = new SFML.Audio.Sound(buffer); Loop = loop; }
//////////////////////////////////////////////////////////// /// <summary> /// Called when the current capture stops /// </summary> //////////////////////////////////////////////////////////// protected override void OnStop() { mySoundBuffer = new SoundBuffer(mySamplesArray.ToArray(), 1, SampleRate); }
public SoundBuffer(string filename) : base(filename) { Buffer = new SFML.Audio.SoundBuffer(filename); }
/// <summary> /// Loads the specified asset. /// </summary> /// <param name="manager">The manager.</param> /// <param name="key">The asset key.</param> /// <returns> /// The loaded asset. /// </returns> public object Load(AssetManager manager, string key) { SoundBuffer buffer = new SoundBuffer(key); return buffer; }
//////////////////////////////////////////////////////////// /// <summary> /// Construct a sound buffer from another sound buffer /// </summary> /// <param name="copy">Sound buffer to copy</param> //////////////////////////////////////////////////////////// public SoundBuffer(SoundBuffer copy) : base(sfSoundBuffer_copy(copy.CPointer)) { }
//////////////////////////////////////////////////////////// /// <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; }
private static void InitializeSoundBuffers() { SoundBufferBrokenWall = new SoundBuffer(Environment.CurrentDirectory + @"/Data/Sounds/SoundBrokenWall.wav"); SoundBufferDeath = new SoundBuffer(Environment.CurrentDirectory + @"/Data/Sounds/SoundDeath.wav"); SoundBufferEvilEye = new SoundBuffer(Environment.CurrentDirectory + @"/Data/Sounds/SoundEvilEye.wav"); SoundBufferKill1 = new SoundBuffer(Environment.CurrentDirectory + @"/Data/Sounds/SoundKill1.wav"); SoundBufferKill2 = new SoundBuffer(Environment.CurrentDirectory + @"/Data/Sounds/SoundKill2.wav"); SoundBufferKill3 = new SoundBuffer(Environment.CurrentDirectory + @"/Data/Sounds/SoundKill3.wav"); SoundBufferLaugh1 = new SoundBuffer(Environment.CurrentDirectory + @"/Data/Sounds/SoundLaugh1.wav"); SoundBufferLaugh2 = new SoundBuffer(Environment.CurrentDirectory + @"/Data/Sounds/SoundLaugh2.wav"); SoundBufferLaugh3 = new SoundBuffer(Environment.CurrentDirectory + @"/Data/Sounds/SoundLaugh3.wav"); SoundBufferMimic = new SoundBuffer(Environment.CurrentDirectory + @"/Data/Sounds/SoundMimic.wav"); SoundBufferNoBrains = new SoundBuffer(Environment.CurrentDirectory + @"/Data/Sounds/SoundNoBrains.wav"); SoundBufferPitBump = new SoundBuffer(Environment.CurrentDirectory + @"/Data/Sounds/SoundPitBump.wav"); SoundBufferPotion = new SoundBuffer(Environment.CurrentDirectory + @"/Data/Sounds/SoundPotion.wav"); SoundBufferStep1 = new SoundBuffer(Environment.CurrentDirectory + @"/Data/Sounds/SoundStep1.wav"); SoundBufferStep2 = new SoundBuffer(Environment.CurrentDirectory + @"/Data/Sounds/SoundStep2.wav"); SoundBufferSwing = new SoundBuffer(Environment.CurrentDirectory + @"/Data/Sounds/SoundSwing.wav"); SoundBufferTrapdoor = new SoundBuffer(Environment.CurrentDirectory + @"/Data/Sounds/SoundTrapdoor.wav"); SoundBufferWallBump = new SoundBuffer(Environment.CurrentDirectory + @"/Data/Sounds/SoundWallBump.wav"); SoundBufferOrbHit = new SoundBuffer(Environment.CurrentDirectory + @"/Data/Sounds/SoundOrbHit.wav"); }
/// <summary> /// Releases unmanaged and - optionally - managed resources. /// </summary> public void Dispose() { if (_outputStream != null) { _outputStream.Dispose(); _outputStream = null; } if (OutputBuffer != null) { OutputBuffer.Dispose(); OutputBuffer = null; } if (_outputSound != null) { _outputSound.Dispose(); _outputSound = null; } }
private static void LoadContentInitialize() { window = new RenderWindow( new VideoMode(800, 600), "Project Title"); windowSize = new Vector2f(800, 600); window.SetFramerateLimit(60); window.Closed += (a, b) => { window.Close(); }; camera2D = new View(cameraPos, new Vector2f(640, 480)); tempIdleN = new Sprite(new Texture("Content/tempIdleN.png")); tempIdleS = new Sprite(new Texture("Content/tempIdleS.png")); tempIdleEW = new Sprite(new Texture("Content/tempIdleEW.png")); background = new Sprite(new Texture("Content/background.png")); basicLevelDec = new Sprite(new Texture("Content/basicLevel_decorMap.png")); basicLevelCol = new Texture("Content/basicLevel_collisionMap.png"); backgroundTexture = basicLevelCol; map = backgroundTexture.CopyToImage(); font = new Font("Content/Font1.ttf"); click = new SoundBuffer("Content/click.wav"); SaD = new SoundBuffer("Content/SaD.wav"); fart = new SoundBuffer("Content/fart.wav"); crunch = new SoundBuffer("Content/crunch.wav"); window.TextEntered += (object sender, TextEventArgs e) => { if (Keyboard.IsKeyPressed(Keyboard.Key.Back)) { if (clientPlayer.textCapture.Length > 0) clientPlayer.textCapture = clientPlayer.textCapture.Substring(0, clientPlayer.textCapture.Length - 1); } else if (Keyboard.IsKeyPressed(Keyboard.Key.Return)) { } else if (Keyboard.IsKeyPressed(Keyboard.Key.LControl)) { } else if (Keyboard.IsKeyPressed(Keyboard.Key.Tab)) { } else { clientPlayer.textCapture += e.Unicode; } }; window.Closed += (object sender, EventArgs e) => { client.Disconnect("Exit"); System.Threading.Thread.Sleep(100); }; }
public void OnActivate() { // Store window window = Root.Singleton.Window; rctScreen = Util.ScreenRect(window.Size.X, window.Size.Y, 1.7778f); // Load sprites sprBackground = new Sprite(Root.Singleton.Material("img/main_menus/main_base2.png")); sprBackground.Position = new Vector2f(rctScreen.Left, rctScreen.Top); sprBackground.Scale = Util.Scale(sprBackground, new Vector2f(rctScreen.Width, rctScreen.Height)); // Load audio mscMenu = Root.Singleton.Music("audio/music/bp_MUS_TitleScreen.ogg"); sndButtonHover = Root.Singleton.Sound("audio/waves/ui/select_light1.wav"); //mscMenu.Stop(); //mscMenu.Play(); // Load UI var btnContinue = new ImageButton(); btnContinue.Image = Root.Singleton.Material("img/main_menus/continue_on.png"); btnContinue.HoveredImage = Root.Singleton.Material("img/main_menus/continue_select2.png"); btnContinue.DisabledImage = Root.Singleton.Material("img/main_menus/continue_off.png"); btnContinue.Enabled = false; btnContinue.HoverSound = sndButtonHover; Util.LayoutControl(btnContinue, (int)(1200 - btnContinue.Image.Size.X), 260, (int)btnContinue.Image.Size.X, (int)btnContinue.Image.Size.Y, rctScreen); btnContinue.Parent = Root.Singleton.Canvas; btnContinue.Init(); var btnNewGame = new ImageButton(); btnNewGame.Image = Root.Singleton.Material("img/main_menus/start_on.png"); btnNewGame.HoveredImage = Root.Singleton.Material("img/main_menus/start_select2.png"); btnNewGame.DisabledImage = Root.Singleton.Material("img/main_menus/start_off.png"); btnNewGame.Enabled = true; btnNewGame.HoverSound = sndButtonHover; btnNewGame.OnClick += (sender) => { Root.Singleton.mgrState.FSMTransist<NewGame>(); }; Util.LayoutControl(btnNewGame, (int)(1200 - btnNewGame.Image.Size.X), 320, (int)btnNewGame.Image.Size.X, (int)btnNewGame.Image.Size.Y, rctScreen); btnNewGame.Parent = Root.Singleton.Canvas; btnNewGame.Init(); var btnTutorial = new ImageButton(); btnTutorial.Image = Root.Singleton.Material("img/main_menus/tutorial_on.png"); btnTutorial.HoveredImage = Root.Singleton.Material("img/main_menus/tutorial_select2.png"); btnTutorial.DisabledImage = Root.Singleton.Material("img/main_menus/tutorial_off.png"); btnTutorial.Enabled = false; btnTutorial.HoverSound = sndButtonHover; Util.LayoutControl(btnTutorial, (int)(1200 - btnTutorial.Image.Size.X), 380, (int)btnTutorial.Image.Size.X, (int)btnTutorial.Image.Size.Y, rctScreen); btnTutorial.Parent = Root.Singleton.Canvas; btnTutorial.Init(); var btnStats = new ImageButton(); btnStats.Image = Root.Singleton.Material("img/main_menus/stats_on.png"); btnStats.HoveredImage = Root.Singleton.Material("img/main_menus/stats_select2.png"); btnStats.DisabledImage = Root.Singleton.Material("img/main_menus/stats_off.png"); btnStats.Enabled = false; btnStats.HoverSound = sndButtonHover; Util.LayoutControl(btnStats, (int)(1200 - btnStats.Image.Size.X), 440, (int)btnStats.Image.Size.X, (int)btnStats.Image.Size.Y, rctScreen); btnStats.Parent = Root.Singleton.Canvas; btnStats.Init(); var btnOptions = new ImageButton(); btnOptions.Image = Root.Singleton.Material("img/main_menus/options_on.png"); btnOptions.HoveredImage = Root.Singleton.Material("img/main_menus/options_select2.png"); btnOptions.DisabledImage = Root.Singleton.Material("img/main_menus/options_off.png"); btnOptions.Enabled = true; btnOptions.HoverSound = sndButtonHover; btnOptions.OnClick += (sender) => { Root.Singleton.mgrState.Activate<Gamestate.OptionsMenu>(); }; Util.LayoutControl(btnOptions, (int)(1200 - btnOptions.Image.Size.X), 500, (int)btnOptions.Image.Size.X, (int)btnOptions.Image.Size.Y, rctScreen); btnOptions.Parent = Root.Singleton.Canvas; btnOptions.Init(); var btnCredits = new ImageButton(); btnCredits.Image = Root.Singleton.Material("img/main_menus/credits_on.png"); btnCredits.HoveredImage = Root.Singleton.Material("img/main_menus/credits_select2.png"); btnCredits.DisabledImage = Root.Singleton.Material("img/main_menus/credits_off.png"); btnCredits.Enabled = false; btnCredits.HoverSound = sndButtonHover; Util.LayoutControl(btnCredits, (int)(1200 - btnCredits.Image.Size.X), 560, (int)btnCredits.Image.Size.X, (int)btnCredits.Image.Size.Y, rctScreen); btnCredits.Parent = Root.Singleton.Canvas; btnCredits.Init(); var btnQuit = new ImageButton(); btnQuit.Image = Root.Singleton.Material("img/main_menus/quit_on.png"); btnQuit.HoveredImage = Root.Singleton.Material("img/main_menus/quit_select2.png"); btnQuit.DisabledImage = Root.Singleton.Material("img/main_menus/quit_off.png"); btnQuit.Enabled = true; btnQuit.HoverSound = sndButtonHover; btnQuit.OnClick += (sender) => { Root.Singleton.Exiting = true; }; Util.LayoutControl(btnQuit, (int)(1200 - btnQuit.Image.Size.X), 620, (int)btnQuit.Image.Size.X, (int)btnQuit.Image.Size.Y, rctScreen); btnQuit.Parent = Root.Singleton.Canvas; btnQuit.Init(); }
//////////////////////////////////////////////////////////// /// <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)) { }
//////////////////////////////////////////////////////////// /// <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)) { }
public SoundInstance(SoundBuffer sound, float basePitch, float pitchVariance) { this.sound = new Sound(sound); this.basePitch = basePitch; this.pitchVariance = pitchVariance; }
private static void InitializeSounds() { var soundsDirectory = new DirectoryInfo(Settings.Paths.Sounds); if (!soundsDirectory.Exists) { Utils.Log(string.Format("directory <<{0}>> does not exist", soundsDirectory.FullName), "InitializeSounds", ConsoleColor.White); return; } var soundsDirectories = new List<DirectoryInfo> {soundsDirectory}; soundsDirectories.AddRange(soundsDirectory.GetDirectories("*.", SearchOption.AllDirectories)); foreach (var directoryInfo in soundsDirectories) foreach (var fileInfo in directoryInfo.GetFiles()) { if (!Settings.Assets.SoundsExtensions.Contains(fileInfo.Extension.ToLower())) continue; var directoryName = directoryInfo.FullName.Replace(soundsDirectory.FullName, @""); if (!directoryInfo.FullName.EndsWith("\\")) directoryName = directoryName.Insert(directoryName.Length, "\\"); var soundBuffer = new SoundBuffer(fileInfo.FullName); Sounds.Add(directoryName + GetAssetName(fileInfo), new Sound(soundBuffer)); Utils.Log(string.Format("sound <<{0}>> loaded", directoryName + GetAssetName(fileInfo)), "InitializeSounds", ConsoleColor.White); } }
public SoundBuffer Sound(string filename) { if (dctSound.ContainsKey(filename)) return dctSound[filename]; var res = Resource(filename); if (res == null) return null; var snd = new SoundBuffer(res); dctSound.Add(filename, snd); return snd; }
/// <summary> /// Load a new sound from an IO Stream. /// </summary> /// <param name="stream"></param> public Sound(Stream stream) { buffer = new SoundBuffer(stream); sound = new SFML.Audio.Sound(buffer); }