Presentation is loading. Please wait.

Presentation is loading. Please wait.

11 Adding Sounds Session 7.1. Session Overview  Find out how to capture and manipulate sound on a Windows PC  Show how sound is managed as an item of.

Similar presentations


Presentation on theme: "11 Adding Sounds Session 7.1. Session Overview  Find out how to capture and manipulate sound on a Windows PC  Show how sound is managed as an item of."— Presentation transcript:

1 11 Adding Sounds Session 7.1

2 Session Overview  Find out how to capture and manipulate sound on a Windows PC  Show how sound is managed as an item of XNA content  Discover how to create SoundEffect instances and control their playback within an XNA game program  Create an XNA program that implements a drum kit  Find out how to capture and manipulate sound on a Windows PC  Show how sound is managed as an item of XNA content  Discover how to create SoundEffect instances and control their playback within an XNA game program  Create an XNA program that implements a drum kit Chapter 7.1: Adding Sounds2

3 Game Idea: “Gamepad Drum Kit”  The idea of this game is to implement a simple drum kit  Each of the buttons on the gamepad will be allocated a different drum type  When the button is pressed that drum sample is played  The idea of this game is to implement a simple drum kit  Each of the buttons on the gamepad will be allocated a different drum type  When the button is pressed that drum sample is played Chapter 7.1: Adding Sounds3

4 Computers and Sound  As far as a computer is concerned a sound sample is just another file of data  The computer can run programs that can work with this type of data  Windows Media Player will provide playback of sound data  The Audacity program will playback data and also allow us to capture and manipulate sound  As far as a computer is concerned a sound sample is just another file of data  The computer can run programs that can work with this type of data  Windows Media Player will provide playback of sound data  The Audacity program will playback data and also allow us to capture and manipulate sound Chapter 7.1: Adding Sounds4

5 Sound and Computers  Computers work with numbers  A sound is represented by a sequence of numbers, each of which gives the intensity of the sound at a particular instant in time  The above waveform is that for a kick drum  Computers work with numbers  A sound is represented by a sequence of numbers, each of which gives the intensity of the sound at a particular instant in time  The above waveform is that for a kick drum Chapter 7.1: Adding Sounds5

6 Sound and Compression  To get high-quality sound, a computer needs to sample a sound signal many thousands of times a second  This produces a lot of data  However, some of this data can be discarded because of the way that the human ear works  Loud sounds at a particular frequency will mask quiet sounds at a similar frequency  This is the basis of MP3 (and other) compression  To get high-quality sound, a computer needs to sample a sound signal many thousands of times a second  This produces a lot of data  However, some of this data can be discarded because of the way that the human ear works  Loud sounds at a particular frequency will mask quiet sounds at a similar frequency  This is the basis of MP3 (and other) compression Chapter 7.1: Adding Sounds6

7 XNA Sound Effects  XNA games can contain “Sound Effect” content  These are sound samples that can be played under program control  These should not be supplied as compressed sound  Instead they should be recorded using the uncompressed WAV format  The WAV format is a standard for “raw” sound samples  XNA games can contain “Sound Effect” content  These are sound samples that can be played under program control  These should not be supplied as compressed sound  Instead they should be recorded using the uncompressed WAV format  The WAV format is a standard for “raw” sound samples Chapter 7.1: Adding Sounds7

8 Creating Sound Samples Using Audacity  Audacity is a free Open Source program that can be used to edit audio signals  It lets you capture and edit WAV files  You can also add a plug-in to allow the program to work with MP3 files  Audacity is a free Open Source program that can be used to edit audio signals  It lets you capture and edit WAV files  You can also add a plug-in to allow the program to work with MP3 files Chapter 7.1: Adding Sounds8

9 Using Audacity  You can obtain Audacity from: http://audacity.sourceforge.net/  Once you have downloaded the program you can also download an install an MP3 plug-in that lets you work with compressed audio files  Remember to respect copyright laws if you use audio files that you did not create  You can obtain Audacity from: http://audacity.sourceforge.net/  Once you have downloaded the program you can also download an install an MP3 plug-in that lets you work with compressed audio files  Remember to respect copyright laws if you use audio files that you did not create Chapter 7.1: Adding Sounds9

10 1. Sound Capture Chapter 7.1: Adding Sounds10  We can capture some sound effects for use in our drums  This in fact turns the gamepad drum machine into a kind of sampler  We can capture some sound effects for use in our drums  This in fact turns the gamepad drum machine into a kind of sampler

11 Sound Content  I have created some sound samples that we can use for the gamepad drum kit  These were recorded using Audacity and then trimmed to the right size  I have created some sound samples that we can use for the gamepad drum kit  These were recorded using Audacity and then trimmed to the right size Chapter 7.1: Adding Sounds11

12 Adding Sound Content  Sound content is added in just the same way as other content  The Content Manager has filters to process audio content  Note that you can only use WAV files to create SoundEffect objects  Sound content is added in just the same way as other content  The Content Manager has filters to process audio content  Note that you can only use WAV files to create SoundEffect objects Chapter 7.1: Adding Sounds12

13 Browsing for Sound Content  You can add sounds like any other content  Note that you can select multiple items and add them all at once  You can add sounds like any other content  Note that you can select multiple items and add them all at once Chapter 7.1: Adding Sounds13

14 Sound Content in the Project  Once the content is added it will be made part of the project, as with images  When the project is built and transferred to the target the sound files are sent as well  You can mix images, fonts, and sound effects in the same content folder  Once the content is added it will be made part of the project, as with images  When the project is built and transferred to the target the sound files are sent as well  You can mix images, fonts, and sound effects in the same content folder Chapter 7.1: Adding Sounds14

15 The SoundEffect Type  The XNA Framework provides a type which can be used to create sound effects in games  This type is for “spot” effects such as gunshots or explosions  An instance of the SoundEffect type can hold a sound sample and be asked to play that sound  Each XNA device has hardware that allows a number of samples to be played at the same time  The Zune is the most restricted in this respect  The XNA Framework provides a type which can be used to create sound effects in games  This type is for “spot” effects such as gunshots or explosions  An instance of the SoundEffect type can hold a sound sample and be asked to play that sound  Each XNA device has hardware that allows a number of samples to be played at the same time  The Zune is the most restricted in this respect Chapter 7.1: Adding Sounds15

16 Adding SoundEffect Values to the Game World  The sounds that we want to play will be part of the Game World for the Drum Pad game  The sound values will be loaded when the LoadContent method runs  The samples will be played in the Update method  The sounds that we want to play will be part of the Game World for the Drum Pad game  The sound values will be loaded when the LoadContent method runs  The samples will be played in the Update method Chapter 7.1: Adding Sounds16 // Game World SoundEffect kick; SoundEffect cymbolTing; SoundEffect snare; SoundEffect top; // Game World SoundEffect kick; SoundEffect cymbolTing; SoundEffect snare; SoundEffect top;

17 Loading SoundEffect Values in LoadContent  The sound effects are loaded into memory along with other content  The SoundEffect version of Load is used for this  The sound effects are loaded into memory along with other content  The SoundEffect version of Load is used for this Chapter 7.1: Adding Sounds17 protected override void LoadContent() { // Create a new SpriteBatch spriteBatch = new SpriteBatch(GraphicsDevice); kick = Content.Load ("kick"); cymbolTing = Content.Load ("cymbolTing"); snare = Content.Load ("snare"); top = Content.Load ("top"); } protected override void LoadContent() { // Create a new SpriteBatch spriteBatch = new SpriteBatch(GraphicsDevice); kick = Content.Load ("kick"); cymbolTing = Content.Load ("cymbolTing"); snare = Content.Load ("snare"); top = Content.Load ("top"); }

18 Playing Sounds  This is the same edge detection code as before  If button A has been pressed the snare drum sample is played  Once playback has started the sound plays automatically  This is the same edge detection code as before  If button A has been pressed the snare drum sample is played  Once playback has started the sound plays automatically Chapter 7.1: Adding Sounds18 // test if A has been pressed since the last Update if (oldpad1.Buttons.A == ButtonState.Released && pad1.Buttons.A == ButtonState.Pressed) { snare.Play(); } // test if A has been pressed since the last Update if (oldpad1.Buttons.A == ButtonState.Released && pad1.Buttons.A == ButtonState.Pressed) { snare.Play(); }

19 2. Drum Pad Chapter 7.1: Adding Sounds19  The program loads a sound sample which can then be played using the gamepad

20 Summary  Computers manage sounds as files of data  The sounds themselves can be held in uncompressed (WAV) format or compressed (MP3 or WMA format)  Sound effects can only be created from uncompressed (WAV) format files  Sounds are managed by XNA as any other content  The SoundEffect type is used to create sound effect variables in the Game World that can be played during a game  Computers manage sounds as files of data  The sounds themselves can be held in uncompressed (WAV) format or compressed (MP3 or WMA format)  Sound effects can only be created from uncompressed (WAV) format files  Sounds are managed by XNA as any other content  The SoundEffect type is used to create sound effect variables in the Game World that can be played during a game Chapter 7.1: Adding Sounds20

21 True/False Revision Quiz  Sound is held on a computer as a collection of numbers.  When a sound file is compressed all the loud sounds are discarded.  An XNA device can only play one sound effect at a time.  The SoundEffect type manages the playback of sound during a game.  Sound is just another type of XNA content.  Sound is held on a computer as a collection of numbers.  When a sound file is compressed all the loud sounds are discarded.  An XNA device can only play one sound effect at a time.  The SoundEffect type manages the playback of sound during a game.  Sound is just another type of XNA content. Chapter 7.1: Adding Sounds21

22 True/False Revision Quiz  Sound is held on a computer as a collection of numbers.  When a sound file is compressed all the loud sounds are discarded.  An XNA device can only play one sound effect at a time.  The SoundEffect type manages the playback of sound during a game.  Sound is just another type of XNA content.  Sound is held on a computer as a collection of numbers.  When a sound file is compressed all the loud sounds are discarded.  An XNA device can only play one sound effect at a time.  The SoundEffect type manages the playback of sound during a game.  Sound is just another type of XNA content. Chapter 7.1: Adding Sounds22

23 True/False Revision Quiz  Sound is held on a computer as a collection of numbers.  When a sound file is compressed all the loud sounds are discarded.  An XNA device can only play one sound effect at a time.  The SoundEffect type manages the playback of sound during a game.  Sound is just another type of XNA content.  Sound is held on a computer as a collection of numbers.  When a sound file is compressed all the loud sounds are discarded.  An XNA device can only play one sound effect at a time.  The SoundEffect type manages the playback of sound during a game.  Sound is just another type of XNA content. Chapter 7.1: Adding Sounds23

24 True/False Revision Quiz  Sound is held on a computer as a collection of numbers.  When a sound file is compressed all the loud sounds are discarded.  An XNA device can only play one sound effect at a time.  The SoundEffect type manages the playback of sound during a game.  Sound is just another type of XNA content.  Sound is held on a computer as a collection of numbers.  When a sound file is compressed all the loud sounds are discarded.  An XNA device can only play one sound effect at a time.  The SoundEffect type manages the playback of sound during a game.  Sound is just another type of XNA content. Chapter 7.1: Adding Sounds24

25 True/False Revision Quiz  Sound is held on a computer as a collection of numbers.  When a sound file is compressed all the loud sounds are discarded.  An XNA device can only play one sound effect at a time.  The SoundEffect type manages the playback of sound during a game.  Sound is just another type of XNA content.  Sound is held on a computer as a collection of numbers.  When a sound file is compressed all the loud sounds are discarded.  An XNA device can only play one sound effect at a time.  The SoundEffect type manages the playback of sound during a game.  Sound is just another type of XNA content. Chapter 7.1: Adding Sounds25

26 True/False Revision Quiz  Sound is held on a computer as a collection of numbers.  When a sound file is compressed all the loud sounds are discarded.  An XNA device can only play one sound effect at a time.  The SoundEffect type manages the playback of sound during a game.  Sound is just another type of XNA content.  Sound is held on a computer as a collection of numbers.  When a sound file is compressed all the loud sounds are discarded.  An XNA device can only play one sound effect at a time.  The SoundEffect type manages the playback of sound during a game.  Sound is just another type of XNA content. Chapter 7.1: Adding Sounds26


Download ppt "11 Adding Sounds Session 7.1. Session Overview  Find out how to capture and manipulate sound on a Windows PC  Show how sound is managed as an item of."

Similar presentations


Ads by Google