/// <summary> /// constructor /// </summary> public GameView(EventManager eventManager) { if (eventManager == null) { throw new ArgumentNullException("eventManager"); } eventManager.OnMapBuiltEvent += new EventHandler<MapBuiltEventArgs>(Subscribe); eventManager.OnEntityPlaceEvent += new EventHandler<EntityPlaceEventArgs>(Subscribe); eventManager.OnEntityMoveEvent += new EventHandler<EntityMoveEventArgs>(Subscribe); Events.Tick += new EventHandler<TickEventArgs>(this.Tick); Events.Quit += new EventHandler<QuitEventArgs>(this.Quit); this.width = 424; this.height = 440; this.backSprites = new ArrayList(); this.frontSprites = new ArrayList(); if (File.Exists(Path.Combine(dataDirectory, "boing.wav"))) { filePath = ""; } try { this.sound = new Sound(Path.Combine(filePath, Path.Combine(dataDirectory, "boing.wav"))); } catch (SdlException) { // Linux audio problem } }
public Thruster(Ship ship, bool reverseThruster, string soundFilename, float thrusterPower, int engineLength, int exhaustConeDeg, Color exhaustColorMin, Color exhaustColorMax) { this.owner = ship; this.reverseThruster = reverseThruster; this.power = thrusterPower; this.engineLength = engineLength; this.exhaustConeDegRange = exhaustConeDeg; this.particlePixelEmitter = new ParticlePixelEmitter(exhaustColorMin, exhaustColorMax); this.particlePixelEmitter.Emitting = false; this.particlePixelEmitter.Life = -1; // -1 means infinite life. // Particles per 1000 updates... this.particlePixelEmitter.Frequency = Configuration.Ships.Thrusters.Frequency; this.particlePixelEmitter.LifeMin = Configuration.Ships.Thrusters.LifeMin; this.particlePixelEmitter.LifeMax = Configuration.Ships.Thrusters.LifeMax; this.particlePixelEmitter.SpeedMin = Configuration.Ships.Thrusters.SpeedMin; this.particlePixelEmitter.SpeedMax = Configuration.Ships.Thrusters.SpeedMax; this.Add(this.particlePixelEmitter); this.thrusterSound = new Sound(soundFilename); this.thrusterSound.Volume = Configuration.SoundVolume; }
public ShipCreationEffect() : base(Configuration.Ships.Creation.MinColor, Configuration.Ships.Creation.MaxColor, Configuration.Ships.Creation.RadiusMin, Configuration.Ships.Creation.RadiusMax) { this.Emitting = false; this.creationSound = new Sound(Configuration.Ships.Creation.SoundFilename); this.creationSound.Volume = Configuration.SoundVolume; }
private void Events_ChannelFinished(object sender, ChannelFinishedEventArgs e) { if (this.queuedSound != null) { this.sound = this.queuedSound; this.queuedSound = null; this.Play(this.sound); } }
/////////////////////////////////// //Custom Constructor /////////////////////////////////// // allow Reloading of an AudioObject public AudioManagerPanel(AudioObject AudioInformation, AssetManagerForm mainForm) { InitializeComponent(); this.MainForm = mainForm; AudioFile = AudioInformation; nameTb.Enabled = false; this.nameTb.Text=AudioFile.name; this.CompteurVolumeTb.Text = AudioFile.volume.ToString(); this.repeatNUD.Value = AudioFile.loops; this.preloadCB.Checked = AudioFile.isPreloaded; if (this.AudioFile.type.Equals("STREAM")) { this.typeSoundRb.Checked = false; this.typeStreamRb.Checked = true; } else { this.typeSoundRb.Checked = true; this.typeStreamRb.Checked = false; } if (File.Exists(AudioFile.path)) { if (!AudioFile.path.Equals("")) { string[] ext = nameTb.Text.Split('.'); try { if (ext[1].ToString().ToLower() == "wav") { SoundPlayer = new Sound(AudioFile.path); } else if (ext[1].ToString().ToLower() == "ogg") { MusicFile = new Music(AudioFile.path); } else { SoundPlayer = null; MusicFile = null; } } catch (Exception ex) { MessageBox.Show("Audio file loading failed !", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } }
/*internal SegmentState play(Segment segment, int ms) * { * //throw new Exception("The method or operation is not implemented."); * segment.play(ms); * }*/ //internal void play(Segment segment, int ms) internal void play(SdlDotNet.Audio.Sound segment, int ms) { try { segment.Play(); } catch (SdlException e) { e.Message.ToString(); } }
/// <summary> /// Plays a sound effect. /// </summary> /// <param name="soundEffectName">Name of the sound effect.</param> public static void PlaySoundEffect(string soundEffectName) { if (IO.Options.Sound) { soundEffectName = FileNameConverter(IO.Paths.SfxPath, soundEffectName); if (IO.IO.FileExists(IO.Paths.SfxPath + soundEffectName)) { SdlAudio.Sound sound = new SdlDotNet.Audio.Sound(IO.Paths.SfxPath + soundEffectName); sound.Play(); } } }
public void YheayBaby() { try { Sound Yheah = new Sound("YeahBaby.ogg"); Yheah.FadeIn(50); Yheah.Play(); } catch { } }
public void PlayMetalClash(int volume) { try { Sound Metal = new Sound("crash_metal.ogg"); Metal.Volume = volume; Metal.FadeIn(50); Metal.Play(); } catch { } }
public void playBoem() { try { Sound Boem = new Sound("boem.ogg"); Boem.Volume = 100; Boem.FadeIn(50); Boem.Play(); } catch { } }
public Cannon(Ship owner, int barrelLength, Surface bulletSurface, float power, TimeSpan cooldown, float muzzleSpeed, int bulletLife) { this.owner = owner; this.bulletSurface = bulletSurface; this.power = power; this.cooldown = cooldown; this.muzzleSpeed = muzzleSpeed; this.bulletLife = bulletLife; this.barrelLength = barrelLength; this.lastFiredTime = DateTime.MinValue; this.bulletCollection = new ParticleCollection(); this.fireSound = new Sound(Configuration.Ships.Cannon.FiringSoundFilename); this.fireSound.Volume = Configuration.SoundVolume; this.dryFireSound = new Sound(Configuration.Ships.Cannon.DryFireSoundFilename); this.dryFireSound.Volume = Configuration.SoundVolume; }
private void initializeSounds() { sounds = new SdlDotNet.Audio.Sound[Enum.GetNames(typeof(Sounds)).Length]; for (int i = 0; i < Enum.GetNames(typeof(Sounds)).Length; i++) { sounds[i] = new SdlDotNet.Audio.Sound( game.AppPath + "sfx" + Path.DirectorySeparatorChar + ((Sounds)i).ToString().ToLower() + ".ogg" ); } channels = new Channel[numChannels]; for (int i = 0; i < numChannels; i++) { channels[i] = new Channel(i); } }
/// <summary> /// /// </summary> /// <param name="fileName"></param> public static void PlayAsynchronousSound(string fileName) { //if( Core.options.enableSoundEffect && Core.soundEffectManager.IsAvailable ) // sndPlaySound(fileName,1); //SDL.net.Audio.play(fileName); try { if (sounds.Contains(fileName)) { ((SdlDotNet.Audio.Sound)sounds[fileName]).Play(); } else { SdlDotNet.Audio.Sound newSound = new SdlDotNet.Audio.Sound(fileName); sounds.Add(fileName, newSound); newSound.Play(); } } catch (SdlException e) { e.Message.ToString(); } }
public void Init() { //Init position of items in list /* itemY[0] = startY; itemY[1] = startY+12;//+12 itemY[2] = startY+27;//+15 itemY[3] = startY+42;//+15 itemY[4] = startY+60;//+18 itemY[5] = startY+80;//+20 itemY[6] = startY+102;//+22 itemY[7] = startY+126;//+24 itemY[8] = startY+152;//+26 itemY[9] = startY+184;//+32 itemY[10] = startY+220;//+36 // center item itemY[11] = startY+266;//+46 itemY[12] = startY+302;//+36 itemY[13] = startY+334;//+32 itemY[14] = startY+360;//+26 itemY[15] = startY+384;//+24 itemY[16] = startY+406;//+22 itemY[17] = startY+426;//+20 itemY[18] = startY+444;//+18 itemY[19] = startY+459;//+15 itemY[20] = startY+471;//+12 */ itemY[0] = startY; itemY[1] = startY+16;//+16 itemY[2] = startY+35;//+19 itemY[3] = startY+54;//+19 itemY[4] = startY+76;//+22 itemY[5] = startY+100;//+24 itemY[6] = startY+126;//+26 itemY[7] = startY+154;//+28 itemY[8] = startY+184;//+30 itemY[9] = startY+220;//+36 itemY[10] = startY+260;//+40 // center item itemY[11] = startY+310;//+50 itemY[12] = startY+350;//+40 itemY[13] = startY+386;//+36 itemY[14] = startY+416;//+30 itemY[15] = startY+444;//+28 itemY[16] = startY+470;//+26 itemY[17] = startY+494;//+24 itemY[18] = startY+516;//+22 itemY[19] = startY+535;//+19 itemY[20] = startY+554;//+19 itemX[0] = startX; itemX[1] = startX+3; itemX[2] = startX+6; itemX[3] = startX+9; itemX[4] = startX+12; itemX[5] = startX+15; itemX[6] = startX+18; itemX[7] = startX+21; itemX[8] = startX+24; itemX[9] = startX+27; itemX[10] = startX+30;// center item itemX[11] = startX+27; itemX[12] = startX+24; itemX[13] = startX+21; itemX[14] = startX+18; itemX[15] = startX+15; itemX[16] = startX+12; itemX[17] = startX+9; itemX[18] = startX+6; itemX[19] = startX+3; itemX[20] = startX; sfError = new Surface (new Size (1, 1)); sfErrorBackground = new Surface (new Size (1, 1)); try { changeGame = new Sound (ConfigurationSettings.AppSettings ["ChangeGameSound"]); changeEmulator = new Sound (ConfigurationSettings.AppSettings ["ChangeEmulatorSound"]); music = new Sound (ConfigurationSettings.AppSettings ["MusicSound"]); } catch (Exception ex) { displayError = true; errorMessage += "Problem loading sounds, file may be missing... \n"; } if (ConfigurationSettings.AppSettings ["PlayMusic"] == "true") { music.Play (true); } time = SdlDotNet.Core.Timer.TicksElapsed; emulators [0] = "Mame"; emulators [1] = "Snes"; rand = new Random (); currentEmulator = 0; try { _sfTitle = new Surface (ConfigurationSettings.AppSettings ["ApplicationLogo"]); } catch (Exception ex) { displayError = true; errorMessage += "Problem loading logo, file may be missing... \n"; _sfTitle = new Surface (new Size (1, 1)); } _ptTitle.X = (ScreenManager.ScreenSize.Width - _sfTitle.Width) / 2; _ptTitle.Y = 10; sfBackgroundImage = new Surface (ConfigurationSettings.AppSettings ["BackgroundImage"]); currentIndex = 0; // We load the mame game list switchEmulator (); fontXXSmall = new SdlDotNet.Graphics.Font (ConfigurationSettings.AppSettings ["FontFile"], 8); fontXSmall = new SdlDotNet.Graphics.Font (ConfigurationSettings.AppSettings ["FontFile"], 10); fontSmall = new SdlDotNet.Graphics.Font (ConfigurationSettings.AppSettings ["FontFile"], 13); fontNormal = new SdlDotNet.Graphics.Font (ConfigurationSettings.AppSettings ["FontFile"], 16); fontMedium = new SdlDotNet.Graphics.Font (ConfigurationSettings.AppSettings ["FontFile"], 20); fontLarge = new SdlDotNet.Graphics.Font (ConfigurationSettings.AppSettings ["FontFile"], 24); fontXL = new SdlDotNet.Graphics.Font (ConfigurationSettings.AppSettings ["FontFile"], 32); fontXXL = new SdlDotNet.Graphics.Font (ConfigurationSettings.AppSettings ["FontFile"], 44); font8 = new SdlDotNet.Graphics.Font (ConfigurationSettings.AppSettings ["FontFile"], 8); font10 = new SdlDotNet.Graphics.Font (ConfigurationSettings.AppSettings ["FontFile"], 10); font12 = new SdlDotNet.Graphics.Font (ConfigurationSettings.AppSettings ["FontFile"], 12); font14 = new SdlDotNet.Graphics.Font (ConfigurationSettings.AppSettings ["FontFile"], 14); font16 = new SdlDotNet.Graphics.Font (ConfigurationSettings.AppSettings ["FontFile"], 16); font18 = new SdlDotNet.Graphics.Font (ConfigurationSettings.AppSettings ["FontFile"], 18); font20 = new SdlDotNet.Graphics.Font (ConfigurationSettings.AppSettings ["FontFile"], 20); font24 = new SdlDotNet.Graphics.Font (ConfigurationSettings.AppSettings ["FontFile"], 24); font28 = new SdlDotNet.Graphics.Font (ConfigurationSettings.AppSettings ["FontFile"], 28); font32 = new SdlDotNet.Graphics.Font (ConfigurationSettings.AppSettings ["FontFile"], 32); font36 = new SdlDotNet.Graphics.Font (ConfigurationSettings.AppSettings ["FontFile"], 36); font40 = new SdlDotNet.Graphics.Font (ConfigurationSettings.AppSettings ["FontFile"], 40); //init starfield for (int i=0; i<512; i++) { starsX [i] = rand.Next (-1000, 1000); starsY [i] = rand.Next (-1000, 1000); starsZ [i] = rand.Next (100, 1000); starsZV [i] = rand.Next (1, 8); } pixels = new Surface (new Size (1280, 1024)); if (displayError == true) { sfError = fontNormal.Render (errorMessage, Color.White); sfErrorBackground = new Surface (new Size (sfError.Width + 40, sfError.Height + 40)); sfErrorBackground.Fill (Color.Gray); sfErrorBackground.Blit (sfError, new Point (((sfErrorBackground.Width - sfError.Width) / 2), 20)); ScreenManager.MainScreen.Blit (sfErrorBackground, new Point (((ScreenManager.MainScreen.Width - sfErrorBackground.Width) / 2), 250)); } }
protected virtual void Dispose(bool disposing) { if (!this.disposed) { // We haven't been disposed yet. if (disposing) { /* The method has been called directly or indirectly by a * user's code. Dispose of managed resources here. */ if (this.creationSound != null) { this.creationSound.Dispose(); this.creationSound = null; } } // Dispose of unmanaged resources _only_ out here. this.disposed = true; } }
public void Go() { // Load the music and sounds. music["mason2"] = new Music(Path.Combine(Path.Combine(filePath, fileDirectory), "mason2.mid")); music["fard-two"] = new Music(Path.Combine(Path.Combine(filePath, fileDirectory), "fard-two.ogg")); boing = new Sound(Path.Combine(Path.Combine(filePath, fileDirectory), "boing.wav")); textDisplay = new TextSprite(" ", new SdlDotNet.Graphics.Font(Path.Combine(Path.Combine(filePath, fileDirectory), "FreeSans.ttf"), 20), Color.Red); // Start up SDL Video.WindowIcon(); Video.WindowCaption = "SDL.NET - AudioExample"; screen = Video.SetVideoMode(width, height); // Play the music and setup the queues. music["mason2"].Play(); //music["fard-two"].Play(); // Set up the music queue and start it music["mason2"].QueuedMusic = music["fard-two"]; music["fard-two"].QueuedMusic = music["mason2"]; MusicPlayer.EnableMusicFinishedCallback(); // Begin the SDL ticker Events.Fps = 50; textDisplay.Text = SdlDotNetExamplesBrowser.StringManager.GetString( "AudioExampleDirections", CultureInfo.CurrentUICulture); textDisplay.TextWidth = 200; Events.Run(); }
void Events_Tick(object sender, TickEventArgs e) { // randomly start "animations" if (--next < 0) { var flash = new Flash { Surface = next_surface(), Point = next_point(), Tick = random.Next(100, 1000) }; flash.Surface.Alpha = (byte)random.Next(100, 255); flash.Surface.AlphaBlending = true; flash.Surface.Fill(next_color()); flashes.Add(flash); next = next_gen(); } screen.Blit(background); var keep = new List<Flash>(); foreach (var flash in flashes) { if (--flash.Tick > 0) { keep.Add(flash); } else { var snd = new Sound("resources/cow4.wav"); snd.Volume = 40; snd.Play(); } screen.Blit(flash.Surface, flash.Point); flash.Tick--; } flashes = keep; screen.Update(); tick++; }
/// <summary> /// Plays a sound the specified number of times on a specific channel /// </summary> /// <param name="sound">The sound to play</param> /// <param name="continuous">If true, sound will be looped.</param> /// <returns>The channel used to play the sound</returns> /// <remarks></remarks> public int Play(Sound sound, bool continuous) { if (continuous == true) { return this.Play(sound, -1, (int)SdlFlag.InfiniteLoop); } else { return this.Play(sound); } }
/// <summary> /// Plays a sound the specified number of times on a specific channel /// </summary> /// <param name="sound">The sound to play</param> /// <param name="loops"> /// The number of loops. Specify 1 to have the sound play twice /// </param> /// <returns>The channel used to play the sound</returns> /// <remarks></remarks> public int Play(Sound sound, int loops) { return this.Play(sound, loops, (int)SdlFlag.InfiniteLoop); }
/// <summary> /// </summary> /// <param name="seg">Sound-effect object</param> /// <param name="concurrentPlaybackMax">Number of maximum concurrent playback.</param> /// <param name="intervalTime">Interval between two successive playbacks</param> public RepeatableSoundEffectImpl(SdlDotNet.Audio.Sound seg, int concurrentPlaybackMax, int intervalTime) { this.segment = seg; this.concurrentPlaybackMax = concurrentPlaybackMax; this.intervalTime = intervalTime; }
public OrbitClash() { Video.WindowIcon(); Video.SetVideoMode(Configuration.DisplaySize.Width, Configuration.DisplaySize.Height, false); Video.WindowCaption = Configuration.Title; Mixer.ChannelsAllocated = Configuration.MaxSoundChannels; this.theGameHasBegun = false; this.particleSystem = new ParticleSystem(); this.mainTitle = new MainTitle(); Surface infoBarSurface = new Surface(Configuration.InfoBar.ImageFilename); this.infoBar = infoBarSurface.Convert(Video.Screen, true, false); // Player 1. this.player1 = new Player(1); this.player1.LeftKey = Configuration.Controls.Player1.Left; this.player1.RightKey = Configuration.Controls.Player1.Right; this.player1.UpKey = Configuration.Controls.Player1.Up; this.player1.DownKey = Configuration.Controls.Player1.Down; this.player1.FireKey = Configuration.Controls.Player1.Fire; // Player 2. this.player2 = new Player(2); this.player2.LeftKey = Configuration.Controls.Player2.Left; this.player2.RightKey = Configuration.Controls.Player2.Right; this.player2.UpKey = Configuration.Controls.Player2.Up; this.player2.DownKey = Configuration.Controls.Player2.Down; this.player2.FireKey = Configuration.Controls.Player2.Fire; this.bulletShipImpactSound = new Sound(Configuration.Bullets.BulletShipImpactSoundFilename); this.bulletShipImpactSound.Volume = Configuration.SoundVolume; this.bulletShipImpactBounceSound = new Sound(Configuration.Bullets.BulletShipImpactBounceSoundFilename); this.bulletShipImpactBounceSound.Volume = Configuration.SoundVolume; this.bulletPlanetImpactSound = new Sound(Configuration.Bullets.BulletPlanetImpactSoundFilename); this.bulletPlanetImpactSound.Volume = Configuration.SoundVolume; this.shipShipImpactSound = new Sound(Configuration.Ships.ShipShipImpactSoundFilename); this.shipShipImpactSound.Volume = Configuration.SoundVolume; // Setup screen bounce-boundary manipulator. this.boundaryManipulator = new ParticleBoundary(new Rectangle(Configuration.PlayArea.Location, Configuration.PlayArea.Size)); this.particleSystem.Manipulators.Add(this.boundaryManipulator); // Set up star-background. Surface backgroundSurface = new Surface(Configuration.PlayAreaBackgroundImageFilename); this.background = backgroundSurface.Convert(Video.Screen, true, false); // Setup the planet. Point planetLocation = new Point(Configuration.PlayArea.Width / 2, Configuration.PlayArea.Height / 2); this.planet = new Planet(Configuration.Planet.ImageFilename, Configuration.Planet.ImageTransparentColor, planetLocation, Configuration.Planet.ImageScale); this.particleSystem.Add(this.planet); // Draw the planetary halo onto the background. if (Configuration.Planet.ShowPlanetaryHalo) { Point haloPosition = new Point(this.planet.Center.X - Configuration.Planet.GravityWellRadius, this.planet.Center.Y - Configuration.Planet.GravityWellRadius); this.background.Blit(this.planet.HaloSurface, haloPosition); } // Setup the gravity manipulator. this.gravityManipulator = new GravityWell(this.planet.Center, Configuration.Planet.GravityWellRadius, Configuration.Planet.GravityPower); this.particleSystem.Manipulators.Add(this.gravityManipulator); // Setup speed limit manipulator. this.speedLimitManipulator = new SpeedLimit(Configuration.UniversalSpeedLimit); //this.particleSystem.Manipulators.Add(this.speedLimitManipulator); Events.KeyboardDown += new EventHandler<KeyboardEventArgs>(this.KeyboardDown); Events.KeyboardUp += new EventHandler<KeyboardEventArgs>(this.KeyboardUp); Events.Fps = Configuration.Fps; Events.Tick += new EventHandler<TickEventArgs>(this.Tick); Events.Quit += new EventHandler<QuitEventArgs>(this.Quit); }
protected virtual void Dispose(bool disposing) { if (!this.disposed) { // We haven't been disposed yet. if (disposing) { /* The method has been called directly or indirectly by a * user's code. Dispose of managed resources here. */ if (this.mainTitle != null) { this.mainTitle.Dispose(); this.mainTitle = null; } if (this.background != null) { this.background.Dispose(); this.background = null; } if (this.planet != null) { this.planet.Dispose(); this.planet = null; } if (this.player1.Ship != null) { this.player1.Ship.Dispose(); this.player1.Ship = null; } if (this.player2.Ship != null) { this.player2.Ship.Dispose(); this.player2.Ship = null; } if (this.player1 != null) { this.player1.Dispose(); this.player1 = null; } if (this.player2 != null) { this.player2.Dispose(); this.player2 = null; } if (this.bulletShipImpactBounceSound != null) { this.bulletShipImpactBounceSound.Dispose(); this.bulletShipImpactBounceSound = null; } if (this.bulletPlanetImpactSound != null) { this.bulletPlanetImpactSound.Dispose(); this.bulletPlanetImpactSound = null; } if (this.bulletShipImpactSound != null) { this.bulletShipImpactSound.Dispose(); this.bulletShipImpactSound = null; } if (this.shipShipImpactSound != null) { this.shipShipImpactSound.Dispose(); this.shipShipImpactSound = null; } } // Dispose of unmanaged resources _only_ out here. this.disposed = true; } }
/// <summary> /// /// </summary> public void Go() { if (File.Exists(fileName)) { filePath = ""; fileDirectory = ""; } else if (File.Exists(Path.Combine(fileDirectory, fileName))) { filePath = ""; } int width = 800; int height = 600; Video.WindowIcon(); Video.WindowCaption = "SDL.NET - Triad"; Events.KeyboardDown += new EventHandler<KeyboardEventArgs>(this.KeyboardDown); Events.KeyboardUp += new EventHandler<KeyboardEventArgs>(this.KeyboardUp); Events.Tick += new EventHandler<TickEventArgs>(this.Tick); Events.Quit += new EventHandler<QuitEventArgs>(this.Quit); board = new Scoreboard(); board.X = 600; board.Y = 0; board.Size = new Size(200, 400); screen = Video.SetVideoMode(width, height); surf = screen.CreateCompatibleSurface(width, height); surf.Fill( new Rectangle(new Point(0, 0), surf.Size), Color.Black); grid = new BlockGrid(new Point(20, 20), new Size(11, 13)); grid.BlocksDestroyed += new EventHandler<BlocksDestroyedEventArgs>(grid_BlocksDestroyed); levelUpSound = Mixer.Sound(Path.Combine(Path.Combine(filePath, fileDirectory), "levelup.wav")); Events.Run(); }
/// <summary> /// /// </summary> /// <param name="seg"></param> public RepeatableSoundEffectImpl(SdlDotNet.Audio.Sound seg) : this(seg, 3, 200) { }
// Import an sound file // private void importBt_Click(object sender, EventArgs e) { // We clean previous Audio file // if (channelSound != null) { channelSound.Dispose(); channelSound = null; } if (SoundPlayer != null) SoundPlayer.Dispose(); if (MusicPlayer.IsPlaying) MusicPlayer.Stop(); if (MusicFile != null) MusicFile.Dispose(); //Open dialogue to get the file // OpenFileDialog openFileD = new OpenFileDialog(); openFileD.Multiselect = false; openFileD.DefaultExt = ".wav"; openFileD.AddExtension = false; //Configure allowed extensions // openFileD.Filter = "Audio files (*.wav)|*.wav|MP3 (*.mp3)|*.mp3|OGG (*.ogg)|*.ogg|M4a (*.m4a)|*.m4a"; if (openFileD.ShowDialog() == DialogResult.OK) { try { if (File.Exists(openFileD.FileName)) { string directoryDest = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "\\Native-Software\\Asset Manager"; if (!Directory.Exists(directoryDest)) Directory.CreateDirectory(directoryDest); string fileNameDest = directoryDest+"\\"+this.MainForm.CurrentAssetProject.ProjectName+"\\"+openFileD.SafeFileName; File.Copy(openFileD.FileName, fileNameDest,true); //Get File Name and Path AudioFile.name = openFileD.SafeFileName; AudioFile.path = fileNameDest; this.nameTb.Text = AudioFile.name; //Load a sound or a music regarding the format // (only wav and ogg are supported by SDL_mixer library :( // TODO : Found an other Audio Library // string[] ext = nameTb.Text.Split('.'); if (ext[1].ToString().ToLower() == "wav") { SoundPlayer = new Sound(fileNameDest); } else if (ext[1].ToString().ToLower() == "ogg") { MusicFile = new Music(fileNameDest); } else { //If the format is not supported, we make sure that no Audio file is loaded // SoundPlayer = null; MusicFile = null; } this.nameTb.Text = AudioFile.name; } } catch (Exception ex) { MessageBox.Show("Error during image loading ! \n\n " + ex.Message); } } }
/// <summary> /// Plays a sound once on a specific channel /// </summary> /// <param name="sound">The sound to play</param> /// <returns>The channel used to play the sound</returns> /// <remarks></remarks> public int Play(Sound sound) { return this.Play(sound, 0); }
/// <summary> /// Stop playing on a specific channel /// </summary> /// <remarks></remarks> public void Stop() { SdlMixer.Mix_HaltChannel(this.index); this.sound = null; }
/// <summary> /// Plays a sound the specified number of times on a /// specific channel, stopping after the specified number of ms /// </summary> /// <param name="sound">The sound to play</param> /// <param name="loops"> /// The number of loops. Specify 1 to have the sound play twice /// </param> /// <param name="milliseconds">The time limit in milliseconds</param> /// <returns>The channel used to play the sound</returns> /// <remarks></remarks> public int Play(Sound sound, int loops, int milliseconds) { if (sound == null) { throw new ArgumentNullException("sound"); } int ret = SdlMixer.Mix_PlayChannelTimed(this.index, sound.Handle, loops, milliseconds); if (ret == (int)SdlFlag.Error) { throw SdlException.Generate(); } this.Sound = sound; return ret; }
/// <summary> /// Separate out audio stream for playback /// </summary> private void parseAudio() { bool isLeft = true; short prevSampleL = 0; short prevSampleR = 0; long start; // Check for null audio if (audioOffsets.Count == 0) return; short data; // Set up buffer MemoryStream buffer = new MemoryStream(); byte[] temp; buffer.Write(WavHeader, 0, WavHeader.Length); file.BaseStream.Seek(audioOffsets.Peek(), SeekOrigin.Begin); ROQChunkHeader chunk = readChunkHeader(); if (chunk.BlockType == ROQBlockType.Stereo){ while (audioOffsets.Count > 0) { file.BaseStream.Seek(audioOffsets.Dequeue(), SeekOrigin.Begin); start = file.BaseStream.Position; chunk = readChunkHeader(); prevSampleL = (short)(((chunk.BlockParameter & 0xFF00) ^ 0x8000) & 0xff00); prevSampleR = (short)(((chunk.BlockParameter << 8) ^ 0x8000) & 0xff00); //isLeft = true; temp = file.ReadBytes((int)chunk.DataSize); foreach(byte d in temp) { if (d < 128) { data = (short)(d * d); } else { data = (short)(-(d - 128) * (d - 128)); } if (isLeft) { prevSampleL += data; buffer.WriteByte((byte)(prevSampleL & 0xFF)); buffer.WriteByte((byte)(prevSampleL >> 8)); } else { prevSampleR += data; buffer.WriteByte((byte)(prevSampleR & 0xFF)); buffer.WriteByte((byte)(prevSampleR >> 8)); } isLeft = !isLeft; } //System.Console.WriteLine("Finished chunk"); } } else { while (audioOffsets.Count > 0) { file.BaseStream.Seek(audioOffsets.Dequeue(), SeekOrigin.Begin); start = file.BaseStream.Position; chunk = readChunkHeader(); prevSampleL = (short)(chunk.BlockParameter ^ 0x8000); while (file.BaseStream.Position < chunk.DataSize + start+8){ data = file.ReadByte(); if (data < 128) { data *= data; prevSampleL += data; buffer.WriteByte((byte)(prevSampleL & 0xFF)); buffer.WriteByte((byte)(prevSampleL >> 8)); } else { data -= 128; data *= data; prevSampleL -= data; buffer.WriteByte((byte)(prevSampleL & 0xFF)); buffer.WriteByte((byte)(prevSampleL >> 8)); } } } } /*while (audioOffsets.Count > 0) { // Find next audio chunk file.BaseStream.Seek(audioOffsets.Dequeue(), System.IO.SeekOrigin.Begin); // Read header // Check for compression /*if (chunk.LengthBits == 0 || chunk.LengthMask == 0) { // No compression - direct copy byte[] t;// = new byte[chunk.DataSize]; t = file.ReadBytes(chunk.DataSize); buffer.Write(t, 0, t.Length); } else { // Decompress and copy System.IO.MemoryStream t; decompress(file, ref chunk, out t); t.Position = 0; t.WriteTo(buffer); }*/ // } // Little messy but only runs on VDX load at this stage byte[] audiob = buffer.ToArray(); int g = audiob.Length - 8; audiob[7] = (byte)((g & 0xFF000000) >> 24); audiob[6] = (byte)((g & 0xFF0000) >> 16); audiob[5] = (byte)((g & 0xFF00) >> 8); audiob[4] = (byte)(g & 0xFF); g = audiob.Length - 44; audiob[43] = (byte)((g & 0xFF000000) >> 24); audiob[42] = (byte)((g & 0xFF0000) >> 16); audiob[41] = (byte)((g & 0xFF00) >> 8); audiob[40] = (byte)(g & 0xFF); if (chunk.BlockType == ROQBlockType.Stereo) { //audiob[32]=; audiob[32] = 4; // 4 bytes per sample audiob[22] = 2; // 2 channel audiob[28] = 0x88; // updated byte/s rate audiob[29] = 0x58; audiob[30] = 0x01; //audiob[34] = 32; // bits per channel } buffer.Close(); audioLength = Math.Ceiling(g / (decimal)22); audio = new Sound(audiob); }
/// <summary> /// Plays a sound the specified number of times on a /// specific channel, stopping after the specified number of ms /// </summary> /// <param name="sound">The sound to play</param> /// <param name="milliseconds">The time limit in milliseconds</param> /// <returns>The channel used to play the sound</returns> /// <remarks></remarks> public int PlayTimed(Sound sound, int milliseconds) { return Play(sound, -1, milliseconds); }
/// <summary> /// Destroy sprite /// </summary> /// <param name="disposing">If true, remove all unamanged resources</param> protected virtual void Dispose(bool disposing) { if (!this.disposed) { if (disposing) { if (this.entitySprite != null) { this.entitySprite.Dispose(); this.entitySprite = null; } if (this.sound != null) { this.sound.Dispose(); this.sound = null; } } this.disposed = true; } }
/// <summary> /// Destroy sprite /// </summary> /// <param name="disposing">If true, remove all unamanged resources</param> protected virtual void Dispose(bool disposing) { if (!this.disposed) { if (disposing) { if (this.sound != null) { this.sound.Dispose(); this.sound = null; } if (this.queuedSound != null) { this.queuedSound.Dispose(); this.queuedSound = null; } if (this.lastSound != null) { this.lastSound.Dispose(); this.lastSound = null; } } this.disposed = true; } }
/// <summary> /// /// </summary> /// <param name="disposing"></param> protected virtual void Dispose(bool disposing) { if (!this.disposed) { if (disposing) { if (this.textDisplay != null) { this.textDisplay.Dispose(); this.textDisplay = null; } if (this.boing != null) { this.boing.Dispose(); this.boing = null; } } this.disposed = true; } }
/// <summary> /// Parse the VDX to locate individual chunks /// </summary> private void parseROQ() { long stop = 0; // Final stream position /*if (rlData.HasValue) { stop = rlData.Value.offset + rlData.Value.length; } else { stop = file.BaseStream.Length; }*/ //ROQHeader header = new VDXHeader(); ROQChunkHeader chunk = new ROQChunkHeader(); // Initialise queue's audioOffsets = new Queue<long>(); //videoOffsets = new Queue<long>(); // Read VDX header //header.ID = file.ReadUInt16(); //if (header.ID != 0x9267) // throw new Exception("Invalid VDX header"); //header.Unknown1 = file.ReadByte(); //header.Unknown2 = file.ReadByte(); //header.Unknown3 = file.ReadByte(); //header.Unknown4 = file.ReadByte(); //header.FPS = file.ReadUInt16(); //fps = (byte)header.FPS; try { chunk = readChunkHeader(); if (chunk.BlockType != ROQBlockType.FileStart) throw new Exception("Bad file type"); while (file.BaseStream.Position < file.BaseStream.Length) { // Read VDX chunk header chunk = readChunkHeader(); // Add offsets where appropriate switch (chunk.BlockType) { case ROQBlockType.Mono: case ROQBlockType.Stereo: audioOffsets.Enqueue(file.BaseStream.Position - VDXChunkHeader.size); break; case ROQBlockType.AudioContainer: break; //case VDXBlockType.Video: // videoFrames++; // goto case VDXBlockType.Zero; //case VDXBlockType.Zero: // videoMaster.Enqueue(file.BaseStream.Position - VDXChunkHeader.size); // break; //case VDXBlockType.Sound: // audioOffsets.Enqueue(file.BaseStream.Position - VDXChunkHeader.size); // break; case ROQBlockType.Image: //if (imageOffset == 0) imageOffset.Add(file.BaseStream.Position - ROQChunkHeader.size); break; case ROQBlockType.ImageInfo: //System.Diagnostics.Debug.WriteLine("Img Info - size: " + file.ReadUInt16() + "x" + file.ReadUInt16()); break; } // Seek to next chunk if (chunk.BlockType != ROQBlockType.AudioContainer) file.BaseStream.Seek(chunk.DataSize, System.IO.SeekOrigin.Current); } } catch { audio = null; //videoFrames = 1; } }
public Sound(string _filename) { sound = new SdlDotNet.Audio.Sound(_filename); }