Sound Effects and Audio

1,502 views

Published on

Programing game in XNA

0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
1,502
On SlideShare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
Downloads
31
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide
  • Control the objects on the screen and give your application some user interaction. Mouse input is never available on the Xbox360,andThe Zune only supports its emulated controls—you won’t be plugginga mouse, a keyboard, or any other input devices into a Zune anytime soon.
  • What would your favorite game be like without sound?
  • You don’t need to include the .wav files as content in the project, because the final wave bank will contain all sound files included in the audio project when you compile your game.
  • Tại sao không dùng XACT3? Sinh viên tự tìm hiểu
  • Save the project as MySounds.xap. You’re ready to use the sounds in your program!
  • Ô bên trái góc dưới màn hình để thiết lập các tùy biến cho âm thanh
  • You need to create the following three objects to manage the file contentsAudioEngine: This object is the program reference to the audio services in the computer, and is used mainly to adjust a few general settings and as a parameter to create the wave and sound banks. When creating an AudioEngine object in your program, you need to use the name of the global settings file for the XACT content as a parameter. This settings file name is generated when the XAP file is compiled, and as a default has the same name as the XAP file, with an .xgs extension.WaveBank: This is a collection of wave files. To create this bank in your code, you need to pass as parameters the AudioEngine object (which must be previously created) and the compiled wave bank file, which is generated when you compile your project with the default name Wave Bank.xwb. Although the wave bank is not explicitly used in your program, you need to create this object, because the sound cues in the sound bank depend on the wave files in this bank.SoundBank: This is a collection of sound cues. You can define cues as references to the wave files stored in the wave bank, along with properties that establish details on how to play these wave files and methods that let you manage their playback.
  • You need to create the following three objects to manage the file contentsAudioEngine: This object is the program reference to the audio services in the computer, and is used mainly to adjust a few general settings and as a parameter to create the wave and sound banks. When creating an AudioEngine object in your program, you need to use the name of the global settings file for the XACT content as a parameter. This settings file name is generated when the XAP file is compiled, and as a default has the same name as the XAP file, with an .xgs extension.WaveBank: This is a collection of wave files. To create this bank in your code, you need to pass as parameters the AudioEngine object (which must be previously created) and the compiled wave bank file, which is generated when you compile your project with the default name Wave Bank.xwb. Although the wave bank is not explicitly used in your program, you need to create this object, because the sound cues in the sound bank depend on the wave files in this bank.SoundBank: This is a collection of sound cues. You can define cues as references to the wave files stored in the wave bank, along with properties that establish details on how to play these wave files and methods that let you manage their playback.
  • You can play a sound in two ways: with a simple playback or in a playback loop. Once you initialize the audio objects, doing a playback is a matter of calling a simple method: PlayCue. You can improve on the previous example by playing a sound cue every time the sprites collide.
  • You can play a sound in two ways: with a simple playback or in a playback loop. Once you initialize the audio objects, doing a playback is a matter of calling a simple method: PlayCue. You can improve on the previous example by playing a sound cue every time the sprites collide.
  • Sound Effects and Audio

    1. 1. Sound Effects and Audio<br />Tran Minh Triet – Nguyen KhacHuy<br />Faculty of Information Technology<br />University of Science, VNU-HCM<br />
    2. 2. XNA and Sound<br />XNA 3.0+ allows us to access sounds in two ways<br />Direct access<br />Microsoft Cross-Platform Audio Creation Tool (XACT)<br />Before 3.0, you could only use XACT<br />
    3. 3. Direct Access<br />Place mp3 or wav files into your content folder.<br />Access wav with SoundEffect<br />Access mp3 with Song<br />
    4. 4. Direct Access - Example<br />Start a new “XNA Windows Game” project<br />Add two member variables<br />SoundEffect soundEffect;<br />Song song<br />Looking for start.wav, Kalimba.mp3 media in SimpleSounds Demo project<br />Adding the media to Content<br />
    5. 5. Direct Access - Example<br />
    6. 6. Direct Access - Example<br />In LoadContent add the following lines<br />//Load the sound<br /> soundEffect = Content.Load<SoundEffect>(@"Audiostart");<br /> song = Content.Load<Song>(@"AudioKalimba");<br />//Play the sound<br />MediaPlayer.Play(song);<br />
    7. 7. Direct Access - Example<br />In Update add the following lines<br />// TODO: Add your update logic here<br />if (Keyboard.GetState().IsKeyDown(Keys.Space))<br /> soundEffect.Play();<br />Build and compile the project<br />Trying to listen the sounds which are played in the same time<br />
    8. 8. XACT<br />Use this to bundle raw wave files together<br />Add effects to sound<br />Generated by the Microsoft Cross-Platform Audio Creation Tool, known as XACT<br />Not a sound editor, just used to bundle files together or change effects.<br />
    9. 9. XACT - How to do<br />Making Sounds with XNA Game Studio and XACT<br />Step 1: Get A Wave File<br />Step 2: Create an XACT Project with Wave Files<br />Step 3: Load an XACT Project Through the Content Pipeline<br />Step 4: Play Sounds Using the Audio API<br />
    10. 10. Step 1: Get a wave file<br />Audio in XNA Game Studio is, at heart, wave-based<br />Repairing the media by resusing start.wav file<br />Don’t need to include the start.wav file as content in the project<br />Go to the next step<br />
    11. 11. Step 2: Create an XACT Project<br />Start XACT by choosing Start ➤ Programs ➤ Microsoft XNA Game Studio 3.0 ➤ Tools ➤ Cross-Platform Audio Creation Tool 2 (XACT2)<br />In the XACT main window, choose File ➤ New Project, and save it as mysound.<br />On the left side of the window, right-click Wave Bank and select New Wave Bank<br />
    12. 12. Step 2: Create an XACT Project<br />From the new wave bank, right click and choose Insert Wave File(s)<br />Also need to create a New Sound Bank<br />Drag the ‘start’ wave bank to the Sound Bank panel<br />Looking at the panel on the left bottom corner, configure settings as you want<br />Save the project as MySounds.xap<br />
    13. 13. Step 2: Create an XACT Project<br />
    14. 14. Step 3: Load XACT<br />There are three objects to manage the file contents<br />AudioEngine<br />Reference to the audio services<br />Adjust settings to create the wave and sound banks<br />Generating the .xgs file when XAP file is compiled<br />
    15. 15. Step 3: Load XACT<br />WaveBank<br />A collection of wave files<br />Pass as parameters the AudioEngine object<br />Generating the .xwb file<br />It’s not explicitly used, but needing to create<br />SoundBank<br />A collection of sound cues<br />
    16. 16. Step 3: Load XACT<br />Adding the mysound.xap file to Content<br />Create audio objects<br />// Audio objects<br />AudioEngine audioEngine;<br />WaveBank waveBank;<br />SoundBank soundBank;<br />
    17. 17. Step 3: Load XACT<br />Initialize the audio components<br /> audioEngine = new AudioEngine(@"ContentMySound.xgs");<br /> // Assume the default names for the wave and sound banks.<br /> // To change these names, change properties in XACT.<br /> waveBank = new WaveBank(audioEngine, @"ContentWave Bank.xwb");<br /> soundBank = new SoundBank(audioEngine, @"ContentSound Bank.xsb");<br />
    18. 18. Step 4: Using Audio in Games<br />Calling a simple method PlayCue to play<br />soundBank.PlayCue(“start");<br />
    19. 19. Step 4: Using Audio in Games<br />Calling a simple method PlayCue to play<br />soundBank.PlayCue(“start");<br />Or<br />Cue mySound;<br />mySound = soundBank.GetCue(" start");<br />mySound.Play();<br />
    20. 20. Q&A<br />?<br />
    21. 21. References<br />XNA framework input<br />http://msdn.microsoft.com/en-us/library/bb203895(XNAGameStudio.30).aspx<br />Ebook<br />Learning XNA 3.0 – Aaron Reed<br />Beginning XNA 2.0 Game Programming<br />

    ×