XNA Audio Input

    Diese Seite verwendet Cookies. Durch die Nutzung unserer Seite erklären Sie sich damit einverstanden, dass wir Cookies setzen. Weitere Informationen

    • XNA Audio Input

      Gute Tag liebe XNA Freunde

      Hiermit Release ich für euch das Audio Input für eure Spiele.
      Es ist schon alles perfekt eingestellt. Ihr müsst es nur noch an eurem
      XNA Game anpassen.



      "Code"

      Brainfuck-Quellcode

      1. /*//---------------------------------------------------//
      2. * Audio.cs *
      3. * Microsoft XNA Game Platform *
      4. * Adventure of Kanaarh *
      5. * Copyright (C) Jok3r *
      6. * Copyright (C) Kevin Kaymak. All rights reserved *
      7. */
      8. //--------------------------------------------------//
      9. using System;
      10. using System.Collections.Generic;
      11. using Microsoft.Xna.Framework;
      12. using Microsoft.Xna.Framework.Audio;
      13. namespace AdventureofK
      14. {
      15. public class Audio : GameComponent
      16. {
      17. private static Audio audio = null;
      18. private AudioEngine audioEngine;
      19. private SoundBank soundBank;
      20. private WaveBank waveBank;
      21. private Audio(Game game, string settingsFile, string waveBankFile, string soundBankFile)
      22. : base(game)
      23. {
      24. try
      25. {
      26. audioEngine = new AudioEngine(settingsFile);
      27. waveBank = new WaveBank(audioEngine, waveBankFile);
      28. soundBank = new SoundBank(audioEngine, soundBankFile);
      29. }
      30. catch (NoAudioHardwareException)
      31. {
      32. audioEngine = null;
      33. waveBank = null;
      34. soundBank = null;
      35. }
      36. }
      37. public static void Initialize(Game game, string settingsFile, string waveBankFile, string soundBankFile)
      38. {
      39. audio = new Audio(game, settingsFile, waveBankFile, soundBankFile);
      40. if (game != null)
      41. {
      42. game.Components.Add(audio);
      43. }
      44. }
      45. public static Cue GetCue(string cueName)
      46. {
      47. if (String.IsNullOrEmpty(cueName) ||
      48. (audio == null) || (audio.audioEngine == null) ||
      49. (audio.soundBank == null) || (audio.waveBank == null))
      50. {
      51. return null;
      52. }
      53. return audio.soundBank.GetCue(cueName);
      54. }
      55. public static void PlayCue(string cueName)
      56. {
      57. if ((audio != null) && (audio.audioEngine != null) &&
      58. (audio.soundBank != null) && (audio.waveBank != null))
      59. {
      60. audio.soundBank.PlayCue(cueName);
      61. }
      62. }
      63. private Cue musicCue;
      64. private Stack<string> musicCueNameStack = new Stack<string>();
      65. public static void PlayMusic(string cueName)
      66. {
      67. if (audio != null)
      68. {
      69. audio.musicCueNameStack.Clear();
      70. PushMusic(cueName);
      71. }
      72. }
      73. public static void PushMusic(string cueName)
      74. {
      75. if ((audio != null) && (audio.audioEngine != null) &&
      76. (audio.soundBank != null) && (audio.waveBank != null))
      77. {
      78. audio.musicCueNameStack.Push(cueName);
      79. if ((audio.musicCue == null) ||
      80. (audio.musicCue.Name != cueName))
      81. {
      82. if (audio.musicCue != null)
      83. {
      84. audio.musicCue.Stop(AudioStopOptions.AsAuthored);
      85. audio.musicCue.Dispose();
      86. audio.musicCue = null;
      87. }
      88. audio.musicCue = GetCue(cueName);
      89. if (audio.musicCue != null) ;
      90. {
      91. audio.musicCue.Play();
      92. }
      93. }
      94. }
      95. }
      96. public static void PopMusic()
      97. {
      98. if ((audio != null) && (audio.audioEngine != null) &&
      99. (audio.soundBank != null) && (audio.waveBank != null))
      100. {
      101. string cueName = null;
      102. if (audio.musicCueNameStack.Count > 0)
      103. {
      104. audio.musicCueNameStack.Pop();
      105. if (audio.musicCueNameStack.Count > 0)
      106. {
      107. cueName = audio.musicCueNameStack.Peek();
      108. }
      109. }
      110. if ((audio.musicCue == null) ||
      111. (audio.musicCue.Name != cueName))
      112. {
      113. if (audio.musicCue != null)
      114. {
      115. audio.musicCue.Stop(AudioStopOptions.AsAuthored);
      116. audio.musicCue.Dispose();
      117. audio.musicCue = null;
      118. }
      119. if (!String.IsNullOrEmpty(cueName))
      120. {
      121. audio.musicCue = GetCue(cueName);
      122. if (audio.musicCue != null)
      123. {
      124. audio.musicCue.Play();
      125. }
      126. }
      127. }
      128. }
      129. }
      130. public static void StopMusic()
      131. {
      132. if (audio != null)
      133. {
      134. audio.musicCueNameStack.Clear();
      135. if (audio.musicCue != null)
      136. {
      137. audio.musicCue.Stop(AudioStopOptions.AsAuthored);
      138. audio.musicCue.Dispose();
      139. audio.musicCue = null;
      140. }
      141. }
      142. }
      143. public override void Update(GameTime gameTime)
      144. {
      145. if (audioEngine != null)
      146. {
      147. audioEngine.Update();
      148. }
      149. base.Update(gameTime);
      150. }
      151. protected override void Dispose(bool disposing)
      152. {
      153. try
      154. {
      155. if (disposing)
      156. {
      157. StopMusic();
      158. if (soundBank != null)
      159. {
      160. soundBank.Dispose();
      161. soundBank = null;
      162. }
      163. if (waveBank != null)
      164. {
      165. waveBank.Dispose();
      166. waveBank = null;
      167. }
      168. if (audioEngine != null)
      169. {
      170. audioEngine.Dispose();
      171. audioEngine = null;
      172. }
      173. }
      174. }
      175. finally
      176. {
      177. base.Dispose(disposing);
      178. }
      179. }
      180. }
      181. }
      Alles anzeigen


      Ihr müsst nur euren Namespace anpassen.
      Auserdem müsst ihr in eurer Game.cs folgende dinge adden.

      im Feld

      Quellcode

      1. [COLOR=red]public Game1()[/COLOR]

      Quellcode

      1. public Game1()
      2. {
      3. [COLOR=red] Audio.Initialize(this, @"[B][COLOR=darkorange]Euer Pfad zur Audio.rgs[/COLOR][/B]",
      4. @"[B][COLOR=darkorange]Euer Pfad zur WaveBank .xwb[/COLOR][/B]", @"[B][COLOR=darkorange]Euer Pfad zur SoundBank.xbs[/COLOR][/B]");[/COLOR]
      5. }
      und schon könnt ihr euren Sound und eure Musik
      im Spiel / XNA verwenden.

      Für diesen Code habe ich ca 3 Stunden harte Arbeit gebraucht.

      Es sind:
      -185 Zeilen
      -k.A Absätze
      -6.411 Zeichen
      - 394
      Wörter

      Ich werde schauen das ich noch mehr solche Dateien Releasen werde, da ich
      ja weniger Zeit habe ein paar XNA Tutorials zu schreiben.


      Wer Support brauch bei diesem Code, kann sich gerne an mich wenden.

    • Werbung zur Unterstützung des Forums ( Bitte AddBlocker deaktivieren )