Example: biology

Sound Effects and Music - Department of …

Sound Effects and MusicChapter 4 Content Sound Basics The Java Sound API Playing a Sound Creating a Real-Time Sound Filter Architecture Creating a Real-Time Echo Filter Emulating 3D Sound Creating a Sound Manager Playing Music Summary2 Introduction When playing a game Sound Effects might be there but you don t hear them. You expect to hear them. Sound is important part of a game. We will learn basics of playing Sound and then move to Effects . Create a Sound manager. Learn to play Music with dynamic Basics Sound is vibration through a medium. Your eardrums pick up the vibration and signal your brain, which interprets it as Sound .

Sound Effects and Music Chapter 4 Content •Sound Basics •The Java Sound API •Playing a Sound •Creating a Real-Time Sound Filter Architecture •Creating a …

Tags:

  Music, Effect, Sound, Sound effects and music

Information

Domain:

Source:

Link to this page:

Please notify us if you found a problem with this document:

Other abuse

Advertisement

Transcription of Sound Effects and Music - Department of …

1 Sound Effects and MusicChapter 4 Content Sound Basics The Java Sound API Playing a Sound Creating a Real-Time Sound Filter Architecture Creating a Real-Time Echo Filter Emulating 3D Sound Creating a Sound Manager Playing Music Summary2 Introduction When playing a game Sound Effects might be there but you don t hear them. You expect to hear them. Sound is important part of a game. We will learn basics of playing Sound and then move to Effects . Create a Sound manager. Learn to play Music with dynamic Basics Sound is vibration through a medium. Your eardrums pick up the vibration and signal your brain, which interprets it as Sound .

2 Vibration through the air creates pressure fluctuations. Faster fluctuations create a higher Sound wave frequency, leading you to hear a higher Basics (2) Digital Sound , such as that in CD audio and many computer Sound formats, contains Sound as a series of discrete samples of the Sound 's amplitudes. Sample rate is amount of samples stored per second ( CD 44,100 Hz) Higher sample rates result in a more accurate audio representation, and lower sample rates mean poorer quality but a smaller file size. Samples are typically 16 bits, giving 65,536 amplitude possibilities.

3 Multichannel Sound API Java Sound API is in the package, Java Sound can play Sound formats with 8- or 16-bit samples with sample rates from 8000Hz to 48,000Hz. Mono or Stereo. Sample rate is amount of samples stored per second ( CD 44,100 Hz) You could generate all these samples yourself in code. Better though: get Sound samples from a Sound file. Java Sound provides support for reading three sampled Sound file formats: AIFF, AU, and Sound API (2) Some Sound programs that you can use to create, record, and edit sounds are -Pro Tools ( ), -Cool Edit ( ), -GoldWave ( ), and -Audacity ( ).

4 Be sure to check out Chapter 17, "Creating Game Art and Sounds," to get some ideas on creating Sound API (3) - Opening a Sound file Load a Sound file with Java Sound using the AudioSystem class. The AudioSystem class contains several static functions and provides several getAudioInputStream() methods to open an audio file from the file system or other source, such as the Internet. These methods return an AudioInputStream object. With an AudioInputStream object, you can read the samples of a Sound without having to mess with the Sound file header or other extra information in the file.

5 Query the format of the Sound by calling the getFormat() method:8 File file = new File(" ");AudioInputStream stream = (file);AudioFormat format = (); Sound API (3) - Opening a Sound file The AudioFormat class provides a way to get information about the format of the Sound , such as the sample rate and number of channels. Also, it provides a way to get the frame size, which is the number of bytes required for every sample for every channel. For 16-bit stereo Sound , the frame size is four, or 2 bytes for each sample (left and right). This can be useful if you want to find out how many bytes it takes to store a Sound in memory.

6 For example, a three-second-long Sound with an audio format of 16-bit samples, stereo, 44,100Hz would be 44,100x3x4 bytes, or about 517KB. Using mono instead of stereo would cut the size in Sound API (4) - Using a Line A Line is an interface to send or receive audio from the Sound system. The Line interface has several subinterfaces. The main Line subinterface used here is a SourceDataLine, which enables you to write audio data to the Sound system. Lines are created by using AudioSystem's getLine() method. You pass this method a object, which specifies the type of Line you want to create.

7 Has a subclass, which you'll use to create your Lines because it contains information on the line's audio format. Besides SourceDataLine, we'll touch on another Line called a Clip. A Clip does a lot of work for you, loading samples into memory from an AudioInputStream and feeding them to the audio system automatically. 10 Java Sound API (4) - Using a Line Here is how you would extend the AudioInputStream to play it using a Clip:11// specify what kind of line we want to info = new ( , format);// create the lineClip clip = (Clip) (info);// load the samples from the (stream);// begin playback of the Sound (); Clips are convenient and easy to use, and are similar to AudioClips introduced in Java SDK But Clips have some drawbacks.

8 Java Sound has a limit to the number of Lines you can have open at the same time, which is usually a maximum of 32 Lines. Also, although several Clips can play simultaneously, each Clip can play only one Sound at a time. For example, if you want two or three explosions to play simultaneously, you'll need a Clip for each a Sound Create a SimpleSoundPlayer to play Sound . This class loads samples from an AudioInputStream into a byte array. It also plays Sound from any InputStream by copying data from it to a Line. In the SimpleSoundPlayer example, the samples loaded are converted to an InputStream by using a ByteArrayInputStream.

9 This enables us to read samples from memory instead of from disk. Because you're using a ByteArrayInputStream wrapped around a byte array, you can create as many ByteArrayInputStreams for the same Sound as you want, so you can play multiple copies of the same Sound code: a Sound (2) To loop Sound , no changes to the SimpleSoundPlayer are necessary. Instead of using a ByteArrayInputStream, we create a LoopingByteInputStream, which works similarly to ByteArrayInputStream. The only difference is that LoopingByteInputStream indefinitely reads the byte array in a loop until its close() method is code: LoopingByteInputStream extends ByteArrayInputStream, and whenever the end of the stream is reached, it calls the reset() method to start reading from the beginning of the array a Real-Time Sound Filter Architecture Sound filters are simple audio processors that can modify existing Sound samples, usually in real time.

10 Sound filters, also known as digital signal processors, are used in audio production all the time for example, to add distortion to a guitar or an echo to a voice. Sound filters can make your game more dynamic. -Game in which the player is wandering around a cave, an echo would be appropriate. -Or, if a rocket is whizzing past the player, you could make the Sound shift from the left to right speaker. In this section, you'll create a real-time Sound filter architecture and create two filters: an echo filter and a simulated 3D Sound a Real-Time Sound Filter Architecture (2) First, we create the architecture.


Related search queries