sound effects and audio

Post on 24-May-2015

1.192 Views

Category:

Technology

0 Downloads

Preview:

Click to see full reader

DESCRIPTION

Programing game in XNA

TRANSCRIPT

Sound Effects and AudioSound Effects and Audio

Tran Minh Triet – Nguyen Khac HuyFaculty of Information TechnologyUniversity of Science, VNU-HCM

XNA and SoundXNA and Sound

XNA 3.0+ allows us to access sounds in two ways

Direct accessMicrosoft Cross-Platform Audio Creation Tool (XACT)

Before 3.0, you could only use XACT

Direct AccessDirect Access

Place mp3 or wav files into your content folder.Access wav with SoundEffectAccess mp3 with Song

Direct Access - ExampleDirect Access - Example

Start a new “XNA Windows Game” project

Add two member variablesSoundEffect soundEffect;Song song

Looking for start.wav, Kalimba.mp3 media in SimpleSounds Demo project

Adding the media to Content

Direct Access - ExampleDirect Access - Example

Direct Access - ExampleDirect Access - Example

In LoadContent add the following lines//Load the sound soundEffect =

Content.Load<SoundEffect>(@"Audio\start");

song = Content.Load<Song>(@"Audio\Kalimba");

//Play the soundMediaPlayer.Play(song);

Direct Access - ExampleDirect Access - Example

In Update add the following lines// TODO: Add your update logic hereif

(Keyboard.GetState().IsKeyDown(Keys.Space))

soundEffect.Play();

Build and compile the project

Trying to listen the sounds which are played in the same time

XACTXACT

Use this to bundle raw wave files together

Add effects to sound

Generated by the Microsoft Cross-Platform Audio Creation Tool, known as XACT

Not a sound editor, just used to bundle files together or change effects.

XACT - How to doXACT - How to do

Making Sounds with XNA Game Studio and XACT

Step 1: Get A Wave File

Step 2: Create an XACT Project with Wave Files

Step 3: Load an XACT Project Through the Content Pipeline

Step 4: Play Sounds Using the Audio API

Step 1: Get a wave fileStep 1: Get a wave file

Audio in XNA Game Studio is, at heart, wave-based

Repairing the media by resusing start.wav file

Don’t need to include the start.wav file as content in the project

Go to the next step

Step 2: Create an XACT ProjectStep 2: Create an XACT Project

Start XACT by choosing Start Programs ➤ ➤Microsoft XNA Game Studio 3.0 Tools ➤ ➤Cross-Platform Audio Creation Tool 2 (XACT2)

In the XACT main window, choose File ➤New Project, and save it as mysound.

On the left side of the window, right-click Wave Bank and select New Wave Bank

Step 2: Create an XACT ProjectStep 2: Create an XACT Project

From the new wave bank, right click and choose Insert Wave File(s)

Also need to create a New Sound Bank

Drag the ‘start’ wave bank to the Sound Bank panel

Looking at the panel on the left bottom corner, configure settings as you want

Save the project as MySounds.xap

Step 2: Create an XACT ProjectStep 2: Create an XACT Project

Step 3: Load XACTStep 3: Load XACT

There are three objects to manage the file contents

AudioEngine

Reference to the audio services

Adjust settings to create the wave and sound banks

Generating the .xgs file when XAP file is compiled

Step 3: Load XACTStep 3: Load XACT

WaveBank

A collection of wave files

Pass as parameters the AudioEngine object

Generating the .xwb file

It’s not explicitly used, but needing to create

SoundBankA collection of sound cues

Step 3: Load XACTStep 3: Load XACT

Adding the mysound.xap file to Content

Create audio objects

// Audio objects

AudioEngine audioEngine;

WaveBank waveBank;

SoundBank soundBank;

Step 3: Load XACTStep 3: Load XACT

Initialize the audio components

audioEngine = new AudioEngine(@"Content\MySound.xgs");

// Assume the default names for the wave and sound banks.

// To change these names, change properties in XACT.

waveBank = new WaveBank(audioEngine, @"Content\Wave Bank.xwb");

soundBank = new SoundBank(audioEngine, @"Content\Sound Bank.xsb");

Step 4: Using Audio in GamesStep 4: Using Audio in Games

Calling a simple method PlayCue to play

soundBank.PlayCue(“start");

Step 4: Using Audio in GamesStep 4: Using Audio in Games

Calling a simple method PlayCue to play

soundBank.PlayCue(“start");

OrCue mySound;

mySound = soundBank.GetCue(" start");

mySound.Play();

Q&AQ&A

?

ReferencesReferences

XNA framework inputhttp://msdn.microsoft.com/en-us/library/bb203895(XNAGameStudio.30).aspx

EbookLearning XNA 3.0 – Aaron ReedBeginning XNA 2.0 Game Programming

top related