public override void Dispose(bool disposing) { if (enemySound != null) { enemySound.Stop(AudioStopOptions.Immediate); enemySound.Dispose(); enemySound = null; } if (animation != null) { animation.Dispose(disposing); animation = null; } if (deathAnimation != null) { deathAnimation.Dispose(disposing); deathAnimation = null; } if (deathLight != null) { deathLight.Dispose(disposing); deathLight = null; } enemyPhysicsComponent.Dispose(true); enemyPhysicsComponent = null; base.Dispose(disposing); }
public void PlayBuzzer() { fxCat.SetVolume(10f); cue = soundBank.GetCue("Buzzer"); cue.Play(); fxCat.SetVolume(6f); }
public PlayerEngineSound() { AEM = AudioEngineManager.GetInstance(); previousVelocity = 0; currentSound = AEM.soundBank.GetCue("subengine"); }
/// <summary> /// Constructor. /// </summary> public CoopLobbyScreen(Cue bgm) : base("Splitscreen Lobby") { this.bgm = bgm; // Create our menu entries. player1MenuEntry = new MenuEntry(string.Empty); player2MenuEntry = new MenuEntry(string.Empty); start = new MenuEntry("Start Game"); SetMenuEntryText(); MenuEntry back = new MenuEntry("Back"); // Hook up menu event handlers. player1MenuEntry.Selected += Player1MenuEntrySelected; player2MenuEntry.Selected += Player2MenuEntrySelected; start.Selected += StartMenuEntrySelected; back.Selected += OnCancel; // Add entries to the menu. MenuEntries.Add(player1MenuEntry); MenuEntries.Add(player2MenuEntry); MenuEntries.Add(back); }
public static void PlayMusic(string name) { StopMusic(); cue = soundBank.GetCue(name); cue.Play(); }
public Beam(Vector2 srcCenter, int Thickness, Ship Owner, GameplayObject target) { this.Target = target; this.owner = Owner; Vector2 TargetPosition = Vector2.Normalize(target.Center); if (Owner.InFrustum) { this.DamageToggleSound = AudioManager.GetCue("sd_shield_static_1"); } if (this.owner.isInDeepSpace || this.owner.GetSystem() == null) { UniverseScreen.DeepSpaceManager.BeamList.Add(this); } else { this.system = this.owner.GetSystem(); this.system.spatialManager.BeamList.Add(this); } this.Source = srcCenter; this.BeamOffsetAngle = Owner.Rotation - MathHelper.ToRadians(HelperFunctions.findAngleToTarget(srcCenter, TargetPosition)); this.Destination = HelperFunctions.findPointFromAngleAndDistanceUsingRadians(srcCenter, Owner.Rotation + this.BeamOffsetAngle, this.range); this.ActualHitDestination = this.Destination; this.Vertices = new VertexPositionNormalTexture[4]; this.Indexes = new int[6]; this.BeamZ = RandomMath2.RandomBetween(-1f, 1f); Vector3[] points = HelperFunctions.BeamPoints(srcCenter, TargetPosition, (float)Thickness, new Vector2[4], 0, this.BeamZ); this.UpperLeft = points[0]; this.UpperRight = points[1]; this.LowerLeft = points[2]; this.LowerRight = points[3]; this.FillVertices(); }
public override void Dispose() { if (!base.IsDisposed) { Console.WriteLine("Disposing Get Item Screen"); this.m_continueText.Dispose(); this.m_continueText = null; this.m_levelUpBGImage.Dispose(); this.m_levelUpBGImage = null; SpriteObj[] levelUpParticles = this.m_levelUpParticles; for (int i = 0; i < levelUpParticles.Length; i++) { SpriteObj spriteObj = levelUpParticles[i]; spriteObj.Dispose(); } Array.Clear(this.m_levelUpParticles, 0, this.m_levelUpParticles.Length); this.m_levelUpParticles = null; this.m_buildUpSound = null; this.m_itemSprite.Dispose(); this.m_itemSprite = null; this.m_itemFoundSprite.Dispose(); this.m_itemFoundSprite = null; this.m_itemFoundText.Dispose(); this.m_itemFoundText = null; this.m_tripStat1.Dispose(); this.m_tripStat2.Dispose(); this.m_tripStat1 = null; this.m_tripStat2 = null; this.m_tripStat1FoundText.Dispose(); this.m_tripStat2FoundText.Dispose(); this.m_tripStat1FoundText = null; this.m_tripStat2FoundText = null; base.Dispose(); } }
public FieldPong() { graphics = new GraphicsDeviceManager(this); content = new ContentManager(Services); graphics.PreferredBackBufferWidth = 1024; graphics.PreferredBackBufferHeight = 768; graphics.MinimumPixelShaderProfile = ShaderProfile.PS_2_0; graphics.SynchronizeWithVerticalRetrace = true; physicsSimulator = new PhysicsSimulator(new Vector2(0)); physicsSimulator.AllowedPenetration = 0.3f; physicsSimulator.BiasFactor = 1.0f; Services.AddService(typeof(PhysicsSimulator), physicsSimulator); screenManager = new ScreenManager(this); Components.Add(screenManager); bloomProcessor = new BloomPostProcessor(this); Components.Add(bloomProcessor); // Uncomment this to monitor the FPS: //fpsCounter = new FrameRateCounter(this); //Components.Add(fpsCounter); audioEngine = new AudioEngine("Content\\Audio\\FieldPongAudio.xgs"); waveBank = new WaveBank(audioEngine, "Content\\Audio\\Wave Bank.xwb"); soundBank = new SoundBank(audioEngine, "Content\\Audio\\Sound Bank.xsb"); backgroundMusic = soundBank.GetCue("GameSong0010 16 Bit"); backgroundMusic.Play(); }
public VictoryState(UrbanRace game) : base(game) { this.type = Type.VICTORY; this.background = null; this.record = null; this.button = null; this.pressedButton = null; this.selectedButton = null; this.ledFont = null; this.retroFont = null; // Audio optionOver = null; optionSelected = null; song = null; retryButtonPos = new Vector2(Settings.getOpt("victoryRetryButtonX"), Settings.getOpt("victoryRetryButtonY")); retryTextPos = new Vector2(Settings.getOpt("victoryRetryTextX"), Settings.getOpt("victoryRetryTextY")); menuButtonPos = new Vector2(Settings.getOpt("victoryMenuButtonX"), Settings.getOpt("victoryMenuButtonY")); menuTextPos = new Vector2(Settings.getOpt("victoryMenuTextX"), Settings.getOpt("victoryMenuTextY")); recordPanelPos = new Vector2(Settings.getOpt("victoryRecordPanelX"), Settings.getOpt("victoryRecordPanelY")); recordTextPos = new Vector2(Settings.getOpt("victoryRecordTextX"), Settings.getOpt("victoryRecordTextY")); recordNumberPos = new Vector2(Settings.getOpt("victoryRecordNumberX"), Settings.getOpt("victoryRecordNumberY")); this.spriteBatch = new SpriteBatch(game.GraphicsDevice); }
public override void Dispose() { if (!base.IsDisposed) { foreach (RaindropObj current in this.m_rainFG) { current.Dispose(); } this.m_rainFG.Clear(); this.m_rainFG = null; this.m_mountain1 = null; this.m_mountain2 = null; if (this.m_rainSFX != null) { this.m_rainSFX.Dispose(); } this.m_rainSFX = null; this.m_tree1 = null; this.m_tree2 = null; this.m_tree3 = null; this.m_fern1 = null; this.m_fern2 = null; this.m_fern3 = null; this.m_introText.Dispose(); this.m_introText = null; base.Dispose(); } }
public void TriggerBossEvent() { mBossEvent = true; mMusic.Pause(); mBossMusic = mSounds.GetCue( "boss_music" ); mMusicName = mBossMusic.Name; mBossMusic.Play(); }
protected void SetMotorPlaying(bool soundOn) { if (soundOn) { if (motorSound == null) { motorSound = audio.PlaySound(soundName); } else if (motorSound.IsPaused) { motorSound.Resume(); } float jScale = pj.GetJointSpeed() / 2f; jScale = jScale > 3 ? 3f : jScale < -6 ? -6f : jScale; motorSound.SetVariable("Pitch", jScale); motorSound.SetVariable("Volume", .8f); } else { if (motorSound != null && motorSound.IsPlaying) { motorSound.Pause(); } } isMotorPlaying = soundOn; }
public void Apply3DPosition(Cue cue, AudioListener listener, AudioEmitter emitter, Vector3 listenerPosition, Vector3 emitterPosition) { listenerPosition = listener.Position; emitterPosition = emitter.Position; cue.Apply3D(listener, emitter); }
static void playLoop(ref Cue cue) { if (!cue.IsPlaying) { StopLoops(); InitCues(); cue.Play(); } }
public void PlayDefendSound(Unit selected) { if (selected is Soldier && selected.isPlayerUnit) { cue = soundBank.GetCue("SoldierDefend"); } else if (selected is Soldier && !selected.isPlayerUnit) { cue = soundBank.GetCue("ESoldierDefend"); } else if (selected is Ranger && selected.isPlayerUnit) { cue = soundBank.GetCue("RangerDefend"); } else if (selected is Ranger && !selected.isPlayerUnit) { cue = soundBank.GetCue("ERangerDefend"); } else if (selected is Defender && selected.isPlayerUnit) { cue = soundBank.GetCue("DefenderDefend"); } else { cue = soundBank.GetCue("EDefenderDefend"); } cue.Play(); }
public override void HandleInput(InputState input) { if (input.MenuUp) { this.beep = AudioManager.GetCue("blip_click"); this.beep.Play(); MenuScreen menuScreen = this; menuScreen.selectedEntry = menuScreen.selectedEntry - 1; if (this.selectedEntry < 0) { this.selectedEntry = this.menuEntries.Count - 1; } } if (input.MenuDown) { this.beep = AudioManager.GetCue("blip_click"); this.beep.Play(); MenuScreen menuScreen1 = this; menuScreen1.selectedEntry = menuScreen1.selectedEntry + 1; if (this.selectedEntry >= this.menuEntries.Count) { this.selectedEntry = 0; } } if (input.MenuSelect) { this.OnSelectEntry(this.selectedEntry); return; } if (input.MenuCancel) { this.OnCancel(); } }
public void PlayAttackSound(Unit attacker) { if (attacker is Soldier && attacker.isPlayerUnit) { cue = soundBank.GetCue("SoldierAttack"); } else if (attacker is Soldier && !attacker.isPlayerUnit) { cue = soundBank.GetCue("ESoldierAttack"); } else if (attacker is Ranger && attacker.isPlayerUnit) { cue = soundBank.GetCue("RangerAttack"); } else if (attacker is Ranger && !attacker.isPlayerUnit) { cue = soundBank.GetCue("ERangerAttack"); } else if (attacker is Defender && attacker.isPlayerUnit) { cue = soundBank.GetCue("DefenderAttack"); } else { cue = soundBank.GetCue("EDefenderAttack"); } cue.Play(); }
public Audio(string clip, string settings, string waveBank, string soundBank, Game game) : base(game) { this.audioEngine = new AudioEngine(this.Game.Content.RootDirectory + @"\" + settings); this.waveBank = new WaveBank(this.audioEngine, this.Game.Content.RootDirectory + @"\" + waveBank); this.soundBank = new SoundBank(this.audioEngine, this.Game.Content.RootDirectory + @"\" + soundBank); this.sound = this.soundBank.GetCue(clip); }
public DefenderMusic( SoundBank sounds, AudioEngine engine ) { mSounds = sounds; mEngine = engine; mMusic = sounds.GetCue( "stage_music" ); mMusicName = mMusic.Name; mVolume = 1.0f; mMusic.Play(); }
public void StopAllSounds() { if (motorSound != null) { motorSound.Stop(AudioStopOptions.Immediate); } motorSound = null; }
public static void StartMainTheme() { if (mainTheme == null) { mainTheme = soundBank.GetCue("space"); mainTheme.Play(); } }
void Tower_ZeroHealth(object sender, EventArgs e) { if(heartbeatCue.IsPlaying) heartbeatCue.Stop(AudioStopOptions.Immediate); audioEngine.GetCategory("Drums").Stop(AudioStopOptions.Immediate); outroCue = soundBank.GetCue("Outro"); outroCue.Play(); }
public CueEmitter(Cue sound, Vector3 position) { cue = sound; audioEmitter = new AudioEmitter(); audioEmitter.Position = position; audioEmitter.Velocity = Vector3.Zero; }
public static Sound1D Create(string name, Cue cue, Action<string> onFinished) { Sound1D freshSound = Pool.Acquire<Sound1D>(); freshSound.Name = name; freshSound._cue = cue; freshSound.OnFinished = onFinished; return freshSound; }
public Music(SoundBank sounds, AudioEngine engine) { this.sounds = sounds; this.engine = engine; music = sounds.GetCue("stage_music"); musicName = music.Name; volume = 1.0f; music.Play(); }
public PositionedSound(Cue cue, String cueName, string soundBankFile) : base() { mSound = new Sound(cue, cueName, soundBankFile); Variables = mSound.Variables; mSound.OnCueRetrieved += new Sound.OnCueRetrievedHandler(UpdateAudio); mEmitter = new AudioEmitter(); }
/// <summary> /// Stop playing current sound /// </summary> public static void StopSound() { if (currentSong == null) return; currentSong.Stop(AudioStopOptions.Immediate); currentSong.Dispose(); currentSong = null; }
public XactBgm(SoundBank soundBank, WaveBank waveBank, string cueName) { sb = soundBank; wb = waveBank ; this.cueName = cueName; cue = sb.GetCue(cueName); }
public PlayerShip(Game game, Vector2 position) { Game = game; _soundBank = Game.Services.GetService<SoundBank[]>(); _world = Game.Services.GetService<World>(); krypton = Game.Services.GetService<KryptonEngine>(); thrustLR = _soundBank[0].GetCue("thrust01"); thrustLR.Play(); thrustLR.Pause(); thrustUD = _soundBank[0].GetCue("thrust01"); thrustUD.Play(); thrustUD.Pause(); Position = position; _particleRenderer = Game.Services.GetService<SpriteBatchRenderer>(); //_textures = Game.Services.GetService<Textures>(); //Loadcontentstuff _shiptxture = Game.Content.Load<Texture2D>("player_ship"); _turretTxture = Game.Content.Load<Texture2D>(".\\guns\\turret01"); _centreVect = new Vector2(_shiptxture.Width / 2, _shiptxture.Height / 2); ProximityBox = new Rectangle(0, 0, _shiptxture.Width+Globals.PhysBuffer, _shiptxture.Height + Globals.PhysBuffer); //make ship fixture in for farseer box = BodyFactory.CreateCircle(_world, ConvertUnits.ToSimUnits(_shiptxture.Width / 2), 7.0f); box.BodyType = BodyType.Dynamic; box.Restitution = 0.5f; box.Friction = 0.2f; box.FixedRotation = true; box.LinearDamping = 0.4f; box.Position = ConvertUnits.ToSimUnits(Position.X + _centreVect.X, Position.Y + _centreVect.Y); box.UserData = "player"; //box.OnCollision += Collide; box.OnSeparation += Collide; //make light in krypton var mLightTexture = LightTextureBuilder.CreateConicLight(Game.GraphicsDevice, 256, 2.0f); light = CreateLights(mLightTexture,400); var mLightTexture2 = LightTextureBuilder.CreatePointLight(Game.GraphicsDevice, 64); light2 = CreateLights(mLightTexture2,200); //set up thruster particle _thrustparticle = Game.Content.Load<ParticleEffect>(".\\mercury\\thruster"); _thrustparticle.LoadContent(Game.Content); _thrusterEmitter = (ConeEmitter)_thrustparticle[0]; //_thrusterEmitter.Initialise(); _thrusterEmitter.ParticleTexture = Game.Content.Load<Texture2D>(".\\mercury\\Particle004"); _thrustparticle.Initialise(); _particleRenderer.LoadContent(Game.Content); //_centerVect = new Vector2(_shiptxture.Width / 2,_shiptxture.Width / 2); currentWeapon = new Gun(Game, true, BulletsStats.Plasma01); }
public void Apply3DAll(Cue cue, AudioListener listener, AudioEmitter emitter, Vector3 listenerPosition, Vector3 emitterPosition, Vector3 listenerVelocity, Vector3 emitterVelocity) { listenerPosition = listener.Position; emitterPosition = emitter.Position; listener.Velocity = listener.Velocity; emitter.Velocity = emitter.Velocity; cue.Apply3D(listener, emitter); }
public void PlayCue(string name) { if (String.IsNullOrEmpty(name)) { throw new ArgumentNullException("name"); } if (!INTERNAL_cueData.ContainsKey(name)) { throw new InvalidOperationException("name not found!"); } Cue newCue = new Cue( INTERNAL_baseEngine, INTERNAL_waveBankNames, name, INTERNAL_cueData[name], true ); newCue.Play(); }
public override void Apply(Cue cue, XACTClip track, float elapsedTime) { StopEvent evt = (StopEvent)Event; AudioStopOptions stopOptions = evt.StopOptions; switch (evt.Scope) { case XACTClip.StopEventScope.Cue: cue.Stop(stopOptions); break; case XACTClip.StopEventScope.Track: /* FIXME: Need to stop this and ONLY this track * track.Stop(stopOptions); */ break; } Played = true; }
public override void Apply(Cue cue, XACTClip track, float elapsedTime) { SetRampValueEvent evt = (SetRampValueEvent)Event; if (elapsedTime <= Timestamp / 1000.0f + evt.Duration) { switch (evt.Property) { case CueProperty.Volume: cue.eventVolume = GetValue(evt, elapsedTime); break; case CueProperty.Pitch: cue.eventPitch = GetValue(evt, elapsedTime); break; } } else { HandleRepeating(); } }
public void Play(Cue player) { bool paused = Paused; _player = player; GSGE.Debug.assert(_player != null); for (int i = 0; i < _tracks.Length; i++) { // pick some new randomness if (!paused) { _tracks[i].Reroll(); } Sound _sound = GetSound(i); if (_sound != null) { // ensure we dont exceed our audio category limit mData.category.AddPlaying(this); _sound.Play(); Update(); if (!paused) { player.mData.instances.Add(_sound); } } else { GSGE.Debug.logMessage("missing sound, probably streaming"); } //throw new NotImplementedException(); } }
internal bool INTERNAL_addCue(Cue newCue) { lock (activeCues) { if (activeCues.Count >= maxCueInstances) { if (maxCueBehavior == MaxInstanceBehavior.Fail) { return(false); // Just ignore us... } else if (maxCueBehavior == MaxInstanceBehavior.Queue) { if (maxFadeInMS > 0) { newCue.INTERNAL_startFadeIn(maxFadeInMS); } if (maxFadeOutMS > 0) { activeCues[0].INTERNAL_startFadeOut(maxFadeOutMS); } else { activeCues[0].Stop(AudioStopOptions.AsAuthored); } } else if (maxCueBehavior == MaxInstanceBehavior.ReplaceOldest) { if (!INTERNAL_removeOldestCue(activeCues[0].Name)) { return(false); // Just ignore us... } if (maxFadeInMS > 0) { newCue.INTERNAL_startFadeIn(maxFadeInMS); } } else if (maxCueBehavior == MaxInstanceBehavior.ReplaceQuietest) { float lowestVolume = float.MaxValue; int lowestIndex = -1; for (int i = 0; i < activeCues.Count; i += 1) { if (!activeCues[i].JustStarted) { float vol = activeCues[i].INTERNAL_calculateVolume(); if (vol < lowestVolume) { lowestVolume = vol; lowestIndex = i; } } } if (lowestIndex > -1) { activeCues[lowestIndex].Stop(AudioStopOptions.AsAuthored); } else { return(false); // Just ignore us... } if (maxFadeInMS > 0) { newCue.INTERNAL_startFadeIn(maxFadeInMS); } } else if (maxCueBehavior == MaxInstanceBehavior.ReplaceLowestPriority) { // FIXME: Priority? if (!INTERNAL_removeOldestCue(activeCues[0].Name)) { return(false); // Just ignore us... } if (maxFadeInMS > 0) { newCue.INTERNAL_startFadeIn(maxFadeInMS); } } } cueInstanceCounts[newCue.Name].Add(newCue); activeCues.Add(newCue); } return(true); }
public abstract void Apply(Cue cue, XACTClip track, float elapsedTime);
//Defer loading because some programs load soundbanks before wavebanks private void Load() { #if !ANDROID using (Stream soundbankstream = TitleContainer.OpenStream(filename)) { #else using (var fileStream = Game.Activity.Assets.Open(filename)) { MemoryStream soundbankstream = new MemoryStream(); fileStream.CopyTo(soundbankstream); soundbankstream.Position = 0; #endif using (BinaryReader soundbankreader = new BinaryReader(soundbankstream)) { //Parse the SoundBank. //Thanks to Liandril for "xactxtract" for some of the offsets uint magic = soundbankreader.ReadUInt32(); if (magic != 0x4B424453) //"SDBK" { throw new Exception("Bad soundbank format"); } uint toolVersion = soundbankreader.ReadUInt16(); uint formatVersion = soundbankreader.ReadUInt16(); if (formatVersion != 46) { #if DEBUG System.Diagnostics.Debug.WriteLine("Warning: SoundBank format not supported"); #endif } uint crc = soundbankreader.ReadUInt16(); //TODO: Verify crc (FCS16) uint lastModifiedLow = soundbankreader.ReadUInt32(); uint lastModifiedHigh = soundbankreader.ReadUInt32(); uint platform = soundbankreader.ReadByte(); //??? uint numSimpleCues = soundbankreader.ReadUInt16(); uint numComplexCues = soundbankreader.ReadUInt16(); soundbankreader.ReadUInt16(); //unkn uint numTotalCues = soundbankreader.ReadUInt16(); uint numWaveBanks = soundbankreader.ReadByte(); uint numSounds = soundbankreader.ReadUInt16(); uint cueNameTableLen = soundbankreader.ReadUInt16(); soundbankreader.ReadUInt16(); //unkn uint simpleCuesOffset = soundbankreader.ReadUInt32(); uint complexCuesOffset = soundbankreader.ReadUInt32(); //unkn uint cueNamesOffset = soundbankreader.ReadUInt32(); soundbankreader.ReadUInt32(); //unkn uint variationTablesOffset = soundbankreader.ReadUInt32(); soundbankreader.ReadUInt32(); //unkn uint waveBankNameTableOffset = soundbankreader.ReadUInt32(); uint cueNameHashTableOffset = soundbankreader.ReadUInt32(); uint cueNameHashValsOffset = soundbankreader.ReadUInt32(); uint soundsOffset = soundbankreader.ReadUInt32(); name = System.Text.Encoding.UTF8.GetString(soundbankreader.ReadBytes(64), 0, 64).Replace("\0", ""); //parse wave bank name table soundbankstream.Seek(waveBankNameTableOffset, SeekOrigin.Begin); waveBanks = new WaveBank[numWaveBanks]; for (int i = 0; i < numWaveBanks; i++) { string bankname = System.Text.Encoding.UTF8.GetString(soundbankreader.ReadBytes(64), 0, 64).Replace("\0", ""); waveBanks[i] = audioengine.Wavebanks[bankname]; } //parse cue name table soundbankstream.Seek(cueNamesOffset, SeekOrigin.Begin); string[] cueNames = System.Text.Encoding.UTF8.GetString(soundbankreader.ReadBytes((int)cueNameTableLen), 0, (int)cueNameTableLen).Split('\0'); soundbankstream.Seek(simpleCuesOffset, SeekOrigin.Begin); for (int i = 0; i < numSimpleCues; i++) { byte flags = soundbankreader.ReadByte(); uint soundOffset = soundbankreader.ReadUInt32(); XactSound sound = new XactSound(this, soundbankreader, soundOffset); Cue cue = new Cue(audioengine, cueNames[i], sound); cues.Add(cue.Name, cue); } soundbankstream.Seek(complexCuesOffset, SeekOrigin.Begin); for (int i = 0; i < numComplexCues; i++) { Cue cue; byte flags = soundbankreader.ReadByte(); if (((flags >> 2) & 1) != 0) { //not sure :/ uint soundOffset = soundbankreader.ReadUInt32(); soundbankreader.ReadUInt32(); //unkn XactSound sound = new XactSound(this, soundbankreader, soundOffset); cue = new Cue(audioengine, cueNames[numSimpleCues + i], sound); } else { uint variationTableOffset = soundbankreader.ReadUInt32(); uint transitionTableOffset = soundbankreader.ReadUInt32(); //parse variation table long savepos = soundbankstream.Position; soundbankstream.Seek(variationTableOffset, SeekOrigin.Begin); uint numEntries = soundbankreader.ReadUInt16(); uint variationflags = soundbankreader.ReadUInt16(); soundbankreader.ReadByte(); soundbankreader.ReadUInt16(); soundbankreader.ReadByte(); XactSound[] cueSounds = new XactSound[numEntries]; float[] probs = new float[numEntries]; uint tableType = (variationflags >> 3) & 0x7; for (int j = 0; j < numEntries; j++) { switch (tableType) { case 0: //Wave { uint trackIndex = soundbankreader.ReadUInt16(); byte waveBankIndex = soundbankreader.ReadByte(); byte weightMin = soundbankreader.ReadByte(); byte weightMax = soundbankreader.ReadByte(); cueSounds[j] = new XactSound(this.GetWave(waveBankIndex, trackIndex)); break; } case 1: { uint soundOffset = soundbankreader.ReadUInt32(); byte weightMin = soundbankreader.ReadByte(); byte weightMax = soundbankreader.ReadByte(); cueSounds[j] = new XactSound(this, soundbankreader, soundOffset); break; } case 4: //CompactWave { uint trackIndex = soundbankreader.ReadUInt16(); byte waveBankIndex = soundbankreader.ReadByte(); cueSounds[j] = new XactSound(this.GetWave(waveBankIndex, trackIndex)); break; } default: throw new NotSupportedException(); } } soundbankstream.Seek(savepos, SeekOrigin.Begin); cue = new Cue(cueNames[numSimpleCues + i], cueSounds, probs); } //Instance Limit soundbankreader.ReadUInt32(); soundbankreader.ReadByte(); soundbankreader.ReadByte(); cues.Add(cue.Name, cue); } } } loaded = true; }
internal void INTERNAL_addCue(Cue newCue) { cueInstanceCounts[newCue.Name] += 1; newCue.SetVariable("NumCueInstances", cueInstanceCounts[newCue.Name]); activeCues.Add(newCue); }
public override void Apply(Cue cue, XACTClip track, float elapsedTime) { // FIXME: Implement action for a marker event. Some kind of callback? HandleRepeating(); }
/// <param name="audioEngine">AudioEngine that will be associated with this sound bank.</param> /// <param name="fileName">Path to a .xsb SoundBank file.</param> public SoundBank(AudioEngine audioEngine, string fileName) { _audioengine = audioEngine; fileName = FileHelpers.NormalizeFilePathSeparators(fileName); #if !ANDROID using (var stream = TitleContainer.OpenStream(fileName)) { #else using (var fileStream = Game.Activity.Assets.Open(fileName)) { MemoryStream stream = new MemoryStream(); fileStream.CopyTo(stream); stream.Position = 0; #endif using (var reader = new BinaryReader(stream)) { // Thanks to Liandril for "xactxtract" for some of the offsets. uint magic = reader.ReadUInt32(); if (magic != 0x4B424453) //"SDBK" { throw new Exception("Bad soundbank format"); } reader.ReadUInt16(); // toolVersion uint formatVersion = reader.ReadUInt16(); // TODO: This does not match XNA, XNA uses 43. if (formatVersion != 46) { Debug.WriteLine("Warning: SoundBank format {0} not supported.", formatVersion); } reader.ReadUInt16(); // crc, TODO: Verify crc (FCS16) reader.ReadUInt32(); // lastModifiedLow reader.ReadUInt32(); // lastModifiedHigh reader.ReadByte(); // platform ??? uint numSimpleCues = reader.ReadUInt16(); uint numComplexCues = reader.ReadUInt16(); reader.ReadUInt16(); //unkn reader.ReadUInt16(); // numTotalCues uint numWaveBanks = reader.ReadByte(); reader.ReadUInt16(); // numSounds uint cueNameTableLen = reader.ReadUInt16(); reader.ReadUInt16(); //unkn uint simpleCuesOffset = reader.ReadUInt32(); uint complexCuesOffset = reader.ReadUInt32(); //unkn uint cueNamesOffset = reader.ReadUInt32(); reader.ReadUInt32(); //unkn reader.ReadUInt32(); // variationTablesOffset reader.ReadUInt32(); //unkn uint waveBankNameTableOffset = reader.ReadUInt32(); reader.ReadUInt32(); // cueNameHashTableOffset reader.ReadUInt32(); // cueNameHashValsOffset reader.ReadUInt32(); // soundsOffset //name = System.Text.Encoding.UTF8.GetString(soundbankreader.ReadBytes(64),0,64).Replace("\0",""); //parse wave bank name table stream.Seek(waveBankNameTableOffset, SeekOrigin.Begin); _waveBanks = new WaveBank[numWaveBanks]; _waveBankNames = new string[numWaveBanks]; for (int i = 0; i < numWaveBanks; i++) { _waveBankNames[i] = System.Text.Encoding.UTF8.GetString(reader.ReadBytes(64), 0, 64).Replace("\0", ""); } //parse cue name table stream.Seek(cueNamesOffset, SeekOrigin.Begin); string[] cueNames = System.Text.Encoding.UTF8.GetString(reader.ReadBytes((int)cueNameTableLen), 0, (int)cueNameTableLen).Split('\0'); // Simple cues if (numSimpleCues > 0) { stream.Seek(simpleCuesOffset, SeekOrigin.Begin); for (int i = 0; i < numSimpleCues; i++) { reader.ReadByte(); // flags uint soundOffset = reader.ReadUInt32(); var oldPosition = stream.Position; stream.Seek(soundOffset, SeekOrigin.Begin); XactSound sound = new XactSound(this, reader); stream.Seek(oldPosition, SeekOrigin.Begin); Cue cue = new Cue(_audioengine, cueNames[i], sound); _cues.Add(cue.Name, cue); } } // Complex cues if (numComplexCues > 0) { stream.Seek(complexCuesOffset, SeekOrigin.Begin); for (int i = 0; i < numComplexCues; i++) { Cue cue; byte flags = reader.ReadByte(); if (((flags >> 2) & 1) != 0) { uint soundOffset = reader.ReadUInt32(); reader.ReadUInt32(); //unkn var oldPosition = stream.Position; stream.Seek(soundOffset, SeekOrigin.Begin); XactSound sound = new XactSound(this, reader); stream.Seek(oldPosition, SeekOrigin.Begin); cue = new Cue(_audioengine, cueNames[numSimpleCues + i], sound); } else { uint variationTableOffset = reader.ReadUInt32(); reader.ReadUInt32(); // transitionTableOffset //parse variation table long savepos = stream.Position; stream.Seek(variationTableOffset, SeekOrigin.Begin); uint numEntries = reader.ReadUInt16(); uint variationflags = reader.ReadUInt16(); reader.ReadByte(); reader.ReadUInt16(); reader.ReadByte(); XactSound[] cueSounds = new XactSound[numEntries]; float[] probs = new float[numEntries]; uint tableType = (variationflags >> 3) & 0x7; for (int j = 0; j < numEntries; j++) { switch (tableType) { case 0: //Wave { int trackIndex = reader.ReadUInt16(); int waveBankIndex = reader.ReadByte(); reader.ReadByte(); // weightMin reader.ReadByte(); // weightMax cueSounds[j] = new XactSound(this, waveBankIndex, trackIndex); break; } case 1: { uint soundOffset = reader.ReadUInt32(); reader.ReadByte(); // weightMin reader.ReadByte(); // weightMax var oldPosition = stream.Position; stream.Seek(soundOffset, SeekOrigin.Begin); cueSounds[j] = new XactSound(this, reader); stream.Seek(oldPosition, SeekOrigin.Begin); break; } case 3: { uint soundOffset = reader.ReadUInt32(); var weightMin = reader.ReadSingle(); var weightMax = reader.ReadSingle(); var varFlags = reader.ReadUInt32(); var linger = (varFlags & 0x01) == 0x01; var oldPosition = stream.Position; stream.Seek(soundOffset, SeekOrigin.Begin); cueSounds[j] = new XactSound(this, reader); stream.Seek(oldPosition, SeekOrigin.Begin); break; } case 4: //CompactWave { int trackIndex = reader.ReadUInt16(); int waveBankIndex = reader.ReadByte(); cueSounds[j] = new XactSound(this, waveBankIndex, trackIndex); break; } default: throw new NotSupportedException(); } } stream.Seek(savepos, SeekOrigin.Begin); cue = new Cue(_audioengine, cueNames[numSimpleCues + i], cueSounds, probs); } // Instance limiting var instanceLimit = reader.ReadByte(); var fadeInSec = reader.ReadUInt16() / 1000.0f; var fadeOutSec = reader.ReadUInt16() / 1000.0f; var instanceFlags = reader.ReadByte(); _cues.Add(cue.Name, cue); } } } } }
private void Load() { using (FileStream fileStream = new FileStream(this.filename, FileMode.Open)) { using (BinaryReader soundReader = new BinaryReader((Stream)fileStream)) { if ((int)soundReader.ReadUInt32() != 1262634067) { throw new Exception("Bad soundbank format"); } int num1 = (int)soundReader.ReadUInt16(); int num2 = (int)soundReader.ReadUInt16(); int num3 = (int)soundReader.ReadUInt16(); int num4 = (int)soundReader.ReadUInt32(); int num5 = (int)soundReader.ReadUInt32(); int num6 = (int)soundReader.ReadByte(); uint num7 = (uint)soundReader.ReadUInt16(); uint num8 = (uint)soundReader.ReadUInt16(); int num9 = (int)soundReader.ReadUInt16(); int num10 = (int)soundReader.ReadUInt16(); uint num11 = (uint)soundReader.ReadByte(); int num12 = (int)soundReader.ReadUInt16(); uint num13 = (uint)soundReader.ReadUInt16(); int num14 = (int)soundReader.ReadUInt16(); uint num15 = soundReader.ReadUInt32(); uint num16 = soundReader.ReadUInt32(); uint num17 = soundReader.ReadUInt32(); int num18 = (int)soundReader.ReadUInt32(); int num19 = (int)soundReader.ReadUInt32(); int num20 = (int)soundReader.ReadUInt32(); uint num21 = soundReader.ReadUInt32(); int num22 = (int)soundReader.ReadUInt32(); int num23 = (int)soundReader.ReadUInt32(); int num24 = (int)soundReader.ReadUInt32(); this.name = Encoding.UTF8.GetString(soundReader.ReadBytes(64)).Replace("\0", ""); fileStream.Seek((long)num21, SeekOrigin.Begin); this.waveBanks = new WaveBank[(IntPtr)num11]; for (int index1 = 0; (long)index1 < (long)num11; ++index1) { string index2 = Encoding.UTF8.GetString(soundReader.ReadBytes(64)).Replace("\0", ""); this.waveBanks[index1] = this.audioengine.Wavebanks[index2]; } fileStream.Seek((long)num17, SeekOrigin.Begin); string[] strArray = Encoding.UTF8.GetString(soundReader.ReadBytes((int)num13)).Split(new char[1]); fileStream.Seek((long)num15, SeekOrigin.Begin); for (int index = 0; (long)index < (long)num7; ++index) { int num25 = (int)soundReader.ReadByte(); uint soundOffset = soundReader.ReadUInt32(); XactSound sound = new XactSound(this, soundReader, soundOffset); Cue cue = new Cue(this.audioengine, strArray[index], sound); this.cues.Add(cue.Name, cue); } fileStream.Seek((long)num16, SeekOrigin.Begin); for (int index1 = 0; (long)index1 < (long)num8; ++index1) { Cue cue; if (((int)soundReader.ReadByte() >> 2 & 1) != 0) { uint soundOffset = soundReader.ReadUInt32(); int num25 = (int)soundReader.ReadUInt32(); XactSound sound = new XactSound(this, soundReader, soundOffset); cue = new Cue(this.audioengine, strArray[(long)num7 + (long)index1], sound); } else { uint num25 = soundReader.ReadUInt32(); int num26 = (int)soundReader.ReadUInt32(); long position = fileStream.Position; fileStream.Seek((long)num25, SeekOrigin.Begin); uint num27 = (uint)soundReader.ReadUInt16(); uint num28 = (uint)soundReader.ReadUInt16(); int num29 = (int)soundReader.ReadByte(); int num30 = (int)soundReader.ReadUInt16(); int num31 = (int)soundReader.ReadByte(); XactSound[] _sounds = new XactSound[(IntPtr)num27]; float[] _probs = new float[(IntPtr)num27]; uint num32 = num28 >> 3 & 7U; for (int index2 = 0; (long)index2 < (long)num27; ++index2) { switch (num32) { case 0U: uint trackIndex1 = (uint)soundReader.ReadUInt16(); byte waveBankIndex1 = soundReader.ReadByte(); int num33 = (int)soundReader.ReadByte(); int num34 = (int)soundReader.ReadByte(); _sounds[index2] = new XactSound(this.GetWave(waveBankIndex1, trackIndex1)); break; case 1U: uint soundOffset = soundReader.ReadUInt32(); int num35 = (int)soundReader.ReadByte(); int num36 = (int)soundReader.ReadByte(); _sounds[index2] = new XactSound(this, soundReader, soundOffset); break; case 4U: uint trackIndex2 = (uint)soundReader.ReadUInt16(); byte waveBankIndex2 = soundReader.ReadByte(); _sounds[index2] = new XactSound(this.GetWave(waveBankIndex2, trackIndex2)); break; default: throw new NotImplementedException(); } } fileStream.Seek(position, SeekOrigin.Begin); cue = new Cue(strArray[(long)num7 + (long)index1], _sounds, _probs); } int num37 = (int)soundReader.ReadUInt32(); int num38 = (int)soundReader.ReadByte(); int num39 = (int)soundReader.ReadByte(); this.cues.Add(cue.Name, cue); } } } this.loaded = true; }
/// <param name="audioEngine">AudioEngine that will be associated with this sound bank.</param> /// <param name="fileName">Path to a .xsb SoundBank file.</param> public SoundBank(AudioEngine audioEngine, string fileName) { if (audioEngine == null) { throw new ArgumentNullException("audioEngine"); } if (string.IsNullOrEmpty(fileName)) { throw new ArgumentNullException("fileName"); } _audioengine = audioEngine; using (var stream = AudioEngine.OpenStream(fileName)) using (var reader = new BinaryReader(stream)) { // Thanks to Liandril for "xactxtract" for some of the offsets. uint magic = reader.ReadUInt32(); if (magic != 0x4B424453) //"SDBK" { throw new Exception("Bad soundbank format"); } reader.ReadUInt16(); // toolVersion uint formatVersion = reader.ReadUInt16(); if (formatVersion != 43) { Debug.WriteLine("Warning: SoundBank format {0} not supported.", formatVersion); } reader.ReadUInt16(); // crc, TODO: Verify crc (FCS16) reader.ReadUInt32(); // lastModifiedLow reader.ReadUInt32(); // lastModifiedHigh reader.ReadByte(); // platform ??? uint numSimpleCues = reader.ReadUInt16(); uint numComplexCues = reader.ReadUInt16(); reader.ReadUInt16(); //unkn reader.ReadUInt16(); // numTotalCues uint numWaveBanks = reader.ReadByte(); reader.ReadUInt16(); // numSounds uint cueNameTableLen = reader.ReadUInt16(); reader.ReadUInt16(); //unkn uint simpleCuesOffset = reader.ReadUInt32(); uint complexCuesOffset = reader.ReadUInt32(); //unkn uint cueNamesOffset = reader.ReadUInt32(); reader.ReadUInt32(); //unkn reader.ReadUInt32(); // variationTablesOffset reader.ReadUInt32(); //unkn uint waveBankNameTableOffset = reader.ReadUInt32(); reader.ReadUInt32(); // cueNameHashTableOffset reader.ReadUInt32(); // cueNameHashValsOffset reader.ReadUInt32(); // soundsOffset //name = System.Text.Encoding.UTF8.GetString(soundbankreader.ReadBytes(64),0,64).Replace("\0",""); //parse wave bank name table stream.Seek(waveBankNameTableOffset, SeekOrigin.Begin); _waveBanks = new WaveBank[numWaveBanks]; _waveBankNames = new string[numWaveBanks]; for (int i = 0; i < numWaveBanks; i++) { _waveBankNames[i] = System.Text.Encoding.UTF8.GetString(reader.ReadBytes(64), 0, 64).Replace("\0", ""); } //parse cue name table stream.Seek(cueNamesOffset, SeekOrigin.Begin); string[] cueNames = System.Text.Encoding.UTF8.GetString(reader.ReadBytes((int)cueNameTableLen), 0, (int)cueNameTableLen).Split('\0'); // Simple cues if (numSimpleCues > 0) { stream.Seek(simpleCuesOffset, SeekOrigin.Begin); for (int i = 0; i < numSimpleCues; i++) { reader.ReadByte(); // flags uint soundOffset = reader.ReadUInt32(); var oldPosition = stream.Position; stream.Seek(soundOffset, SeekOrigin.Begin); XactSound sound = new XactSound(audioEngine, this, reader); stream.Seek(oldPosition, SeekOrigin.Begin); Cue cue = new Cue(_audioengine, cueNames[i], sound); _cues.Add(cue.Name, cue); } } // Complex cues if (numComplexCues > 0) { stream.Seek(complexCuesOffset, SeekOrigin.Begin); for (int i = 0; i < numComplexCues; i++) { Cue cue; byte flags = reader.ReadByte(); if (((flags >> 2) & 1) != 0) { uint soundOffset = reader.ReadUInt32(); reader.ReadUInt32(); //unkn var oldPosition = stream.Position; stream.Seek(soundOffset, SeekOrigin.Begin); XactSound sound = new XactSound(audioEngine, this, reader); stream.Seek(oldPosition, SeekOrigin.Begin); cue = new Cue(_audioengine, cueNames[numSimpleCues + i], sound); } else { uint variationTableOffset = reader.ReadUInt32(); reader.ReadUInt32(); // transitionTableOffset //parse variation table long savepos = stream.Position; stream.Seek(variationTableOffset, SeekOrigin.Begin); uint numEntries = reader.ReadUInt16(); uint variationflags = reader.ReadUInt16(); reader.ReadByte(); reader.ReadUInt16(); reader.ReadByte(); XactSound[] cueSounds = new XactSound[numEntries]; float[] probs = new float[numEntries]; uint tableType = (variationflags >> 3) & 0x7; for (int j = 0; j < numEntries; j++) { switch (tableType) { case 0: //Wave { int trackIndex = reader.ReadUInt16(); int waveBankIndex = reader.ReadByte(); reader.ReadByte(); // weightMin reader.ReadByte(); // weightMax cueSounds[j] = new XactSound(this, waveBankIndex, trackIndex); break; } case 1: { uint soundOffset = reader.ReadUInt32(); reader.ReadByte(); // weightMin reader.ReadByte(); // weightMax var oldPosition = stream.Position; stream.Seek(soundOffset, SeekOrigin.Begin); cueSounds[j] = new XactSound(audioEngine, this, reader); stream.Seek(oldPosition, SeekOrigin.Begin); break; } case 3: { uint soundOffset = reader.ReadUInt32(); reader.ReadSingle(); // weightMin reader.ReadSingle(); // weightMax reader.ReadUInt32(); // flags var oldPosition = stream.Position; stream.Seek(soundOffset, SeekOrigin.Begin); cueSounds[j] = new XactSound(audioEngine, this, reader); stream.Seek(oldPosition, SeekOrigin.Begin); break; } case 4: //CompactWave { int trackIndex = reader.ReadUInt16(); int waveBankIndex = reader.ReadByte(); cueSounds[j] = new XactSound(this, waveBankIndex, trackIndex); break; } default: throw new NotSupportedException(); } } stream.Seek(savepos, SeekOrigin.Begin); cue = new Cue(_audioengine, cueNames[numSimpleCues + i], cueSounds, probs); } // Instance limiting reader.ReadByte(); //instanceLimit reader.ReadUInt16(); //fadeInSec, divide by 1000.0f reader.ReadUInt16(); //fadeOutSec, divide by 1000.0f reader.ReadByte(); //instanceFlags _cues.Add(cue.Name, cue); } } } }
internal void AddSound(Cue sound) { sounds.Add(sound); }