/* * Copyright (C) 1996-1997 Intel Corporation * All Rights Reserved * * A royalty-free copyright license to copy, modify and compile this source * code and to distribute it in your own products in source and binary forms * is hereby granted, so long as this copyright notice and this copyright * license appear in all source code copies. No other rights or licenses * are granted. The Intel name or other trademarks may not be used to * endorse or promote products using this header file without Intel's prior * written permission. * * THIS SOURCE CODE IS PROVIDED "AS IS" WITH NO WARRANTIES WHATSOEVER, * INCLUDING ANY WARRANTY OF MERCHANTABILITY, NONINFRINGEMENT, OR FITNESS * FOR ANY PARTICULAR PURPOSE. Intel disclaims all liability, including * liability for infringement of any proprietary rights, relating to use * of this source code. */ import java.applet.*; import java.awt.*; import spatialAudio.*; public class SettingUp extends java.applet.Applet { /* * the spatialAudio environment */ Environment env = null; /* * the direct listener through which we hear the sounds */ DirectListener listener = null; /* * the sound source which produces the sound we hear */ CachedSoundSource soundSource = null; String soundName; public void init() { System.out.println("Initializing applet SettingUp...."); setBackground(Color.white); /* * Get the sound name. * You can make the applet use your own sound files by providing * the names in the HTML file. The sound files need to be in the * same directory as the HTML file. */ soundName = getParameter("SOUND"); if (soundName == null) soundName = "id20.wav"; /* * Initialize the audio */ /* * First, create the environment */ try { env = SpatialAudio.createEnvironment(); System.out.println("Created the environment"); } catch (SpatialAudioException e) { System.out.println("Failed to create the environment"); env = null; return; } /* * Next, create the listener. */ try { listener = env.createDirectListener(); System.out.println("Created the listener..."); } catch (SpatialAudioException e) { System.out.println("Failed to create the listener"); listener = null; return; } /* * Here we create the sound source from a String that represents an URL. * You must provide the fully qualified URL; file URL's are okay */ /* * First, we construct the complete URL for an audio file which is * located in the same directory as the HTML page which loaded this * applet */ String docBase = this.getDocumentBase().toString(); int lastSlash = docBase.lastIndexOf('/'); if (lastSlash != -1) docBase = docBase.substring(0, lastSlash+1); /* * Now, we create the SoundSource (audio emitter) */ try { soundSource = env.createCachedSoundSource(docBase + soundName); System.out.println("Created the sound source"); } catch (Exception e) { System.out.println("Failed to create the sound source"); soundSource = null; } System.out.println("Done initializing the audio!"); } // init() public void start() { System.out.println("Starting applet SettingUp...."); /* * We need to connect the direct listener to the audio device * each time the applet starts, and disconnect it when the applet * stops. This frees up the audio device for other applets and * applications when the applet isn't running. */ if (listener != null) listener.connect(); /* * Tell the sound to play, looping continuously. */ if (soundSource != null) soundSource.setPlayState(MediaState.AUDIO_PLAY); } // start() public void stop() { System.out.println("Stopping applet SettingUp...."); /* * Disconnect the listener from the audio device. * This will free the audio device for use by other applets * and applications when the applet isn't running, and make * the sounds stop playing. */ if (listener != null) listener.disconnect(); /* * The exception is that MIDI files are handled differently * and must be explicitly stopped. This will explicitly stop * the sound source playback. */ if (soundSource != null) soundSource.setPlayState(MediaState.AUDIO_STOP); } // stop() public void destroy() { System.out.println("Destroying applet Validate...."); /* * Release all resources */ if (soundSource != null) { soundSource.release(); soundSource = null; } if (listener != null) { listener.release(); listener = null; } if (env != null) { env.release(); env = null; } } // destroy() } // Validate class