Games4 - Sound Effects and Music Chapter 4 of Developing Games in Java Friday Opening sounds fles • Use the AudioSystem class • getAudioStream

Info iconThis preview shows pages 1–6. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Sound Effects and Music Chapter 4 of Developing Games in Java Friday, October 28, 2011 Opening sounds fles • Use the AudioSystem class • getAudioStream methods used to get an AudioInputStream object From a fle File file = new File("sound.wav"); AudioInputStream stream = AudioSystem.getAudioInputStreamFile(file); AudioFormat format = stream.getFormat( ); • AudioFormat class provides a way to get inFo about the stream -- sample rate, number oF channels, bytes per sample, etc. • UseFul For determining memory requirements, i.e. a 1 second mono sound with 16-bit samples, 44,100KHz would be 44,100 × 1 × 2 = ~88K bytes. Friday, October 28, 2011 Lines • A line is an interface to send audio to the sound sub-system • The Line interface supports several sub-interfaces • We use a SourceDataLine • Allows audio data to be written to the sound system • See Chapter 4 of Game Development in Java for a discussion of clips. Clips are more limited that SourceDateLine s in the number that can be open and the number of sounds they can play at a time Friday, October 28, 2011 Playing a sound • Look at program SimpleSoundPlayer.java • Loads sample from AudioInputStream • Converted to an InputStream /** Opens a sound from a Fle. */ public SimpleSoundPlayer(String Flename) { try { // open the audio input stream AudioInputStream stream = AudioSystem.getAudioInputStream( new File(flename)); ¡ormat = stream.getFormat(); // get the audio samples samples = getSamples(stream); } catch (UnsupportedAudio¡ileException ex) { ex.printStackTrace(); } catch (IOException ex) { ex.printStackTrace(); } } samples is a byte array Friday, October 28, 2011 getSamples /** Gets the samples from an AudioInputStream as an array of bytes....
View Full Document

This note was uploaded on 02/19/2012 for the course ECE 462 taught by Professor Samuelmidkiff during the Fall '11 term at Purdue University-West Lafayette.

Page1 / 13

Games4 - Sound Effects and Music Chapter 4 of Developing Games in Java Friday Opening sounds fles • Use the AudioSystem class • getAudioStream

This preview shows document pages 1 - 6. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online