/** * Sets Gain value. Line should be opened before calling this method. Linear scale 0.0 <--> 1.0 Threshold Coef. : 1/2 to avoid saturation. * * @param fGain */ public void setGain(float fGain) { // if (line != null) // System.out.println(((FloatControl) // line.getControl(FloatControl.Type.MASTER_GAIN)).getValue()) // Set the value gain = fGain; // Better type if (line != null && line.isControlSupported(FloatControl.Type.MASTER_GAIN)) ( (FloatControl) line.getControl(FloatControl.Type.MASTER_GAIN) ).setValue((float) ( 20 * Math.log10(fGain <= 0.0 ? 0.0000 : fGain) )); // OR (Math.log(fGain == 0.0 ? 0.0000 : fGain) / Math.log(10.0)) // if (line != null) // System.out.println(((FloatControl) // line.getControl(FloatControl.Type.MASTER_GAIN)).getValue()) }
private void loadClip() { try { clip = AudioSystem.getClip(); InputStream in = getClass().getClassLoader().getResourceAsStream(filePath); BufferedInputStream bufferedIn = new BufferedInputStream(in); AudioInputStream audioIn = AudioSystem.getAudioInputStream(bufferedIn); clip.open(audioIn); volume = (FloatControl) clip.getControl(FloatControl.Type.MASTER_GAIN); } catch (LineUnavailableException | UnsupportedAudioFileException | IOException e) { e.printStackTrace(); System.exit(-1); } }
/** * Plays the clip with the specified volume. * @param volume the volume the play at * @param listener the line listener * @throws LineUnavailableException if a clip object is not available or * if the line cannot be opened due to resource restrictions */ public void start(float volume, LineListener listener) throws LineUnavailableException { Clip clip = getClip(); if (clip == null) return; // PulseAudio does not support Master Gain if (clip.isControlSupported(FloatControl.Type.MASTER_GAIN)) { // set volume FloatControl gainControl = (FloatControl) clip.getControl(FloatControl.Type.MASTER_GAIN); float dB = (float) (Math.log(volume) / Math.log(10.0) * 20.0); gainControl.setValue(dB); } if (listener != null) clip.addLineListener(listener); clip.setFramePosition(0); clip.start(); }
/** * Mute the Clip (because destroying it, won't stop it) */ public void mute() { try { Clip c = getClip(); if (c == null) { return; } float val = (float) (Math.log(Float.MIN_VALUE) / Math.log(10.0) * 20.0); if (val < -80.0f) { val = -80.0f; } ((FloatControl) c.getControl(FloatControl.Type.MASTER_GAIN)).setValue(val); } catch (IllegalArgumentException ignored) { } catch (LineUnavailableException e) { e.printStackTrace(); } }
private void play(String wavPath, float db) { if (!dnd && db > -40) { ClassLoader classLoader = getClass().getClassLoader(); try (AudioInputStream stream = AudioSystem.getAudioInputStream(classLoader.getResource(wavPath))) { Clip clip = AudioSystem.getClip(); clip.open(stream); if (db != 0.0) { FloatControl gainControl = (FloatControl) clip.getControl(FloatControl.Type.MASTER_GAIN); gainControl.setValue(db); } clip.start(); } catch (Exception e) { logger.error("Cannot start playing wav file: ", e); } } }
/** * Creates a new {@code PreloadedPlayback}. PreloadedPlayback objects will * always be created by their associated PreloadedAudio object. * <p> * IMPLEMENTATION NOTE: Originally, the fetching of a new {@code Line} was * done in the {@code run} method, however testing revealed that latency is * decreased if a {@code Line} is acquired ahead of time, here in the * constructor. * * @param audio * The {@code Audio} that created this {@code PreloadedPlayback}. * @param audioFormat * Specifies the particular arrangement of audio data. * @param audioBytes * Holds the audio data from which a {@code Clip} will be * created. * @param instanceID * The {@code instanceID} of this {@code PreloadedPlayback}. */ protected PreloadedPlayback(Audio audio, AudioFormat audioFormat, byte[] audioBytes, long instanceID) { super(audio, instanceID); DataLine.Info info = new DataLine.Info(Clip.class, audioFormat); try { clip = (Clip) AudioSystem.getLine(info); clip.open(audioFormat, audioBytes, 0, audioBytes.length); if (clip.isControlSupported(FloatControl.Type.MASTER_GAIN)) { volCtrl = (FloatControl) clip .getControl(FloatControl.Type.MASTER_GAIN); } else { logger.warning("Master-Gain control is not supported." + " Volume will be fixed at the default level."); } } catch (LineUnavailableException ex) { ex.printStackTrace(); } clip.addLineListener(this); }
/** * Creates a new {@code StreamingPlayback}. StreamingPlayback objects will * always be created by their associated StreamingAudio object. * * @param audio * The {@code Audio} that created this {@code StreamingPlayback}. * @param audioInStream * The {@code AudioInputStream} used by this * {@code StreamingPlayback}. * @param instanceID * The {@code instanceID} of this {@code StreamingPlayback}. */ protected StreamingPlayback(Audio audio, AudioInputStream audioInStream, long instanceID) { super(audio, instanceID); this.audioInStream = audioInStream; AudioFormat audioFormat = audioInStream.getFormat(); DataLine.Info info = new DataLine.Info(SourceDataLine.class, audioFormat); try { line = (SourceDataLine) AudioSystem.getLine(info); if (line != null) { line.open(audioFormat); } if (line.isControlSupported(FloatControl.Type.MASTER_GAIN)) { volCtrl = (FloatControl) line .getControl(FloatControl.Type.MASTER_GAIN); } else { logger.warning("Master-Gain control is not supported." + " Volume will be fixed at the default level."); } } catch (LineUnavailableException ex) { ex.printStackTrace(); } }
public SoundClip(String path) { try { InputStream audioSrc = getClass().getResourceAsStream(path); InputStream bufferedIn = new BufferedInputStream(audioSrc); AudioInputStream ais = AudioSystem.getAudioInputStream(bufferedIn); AudioFormat baseFormat = ais.getFormat(); AudioFormat decodeFormat = new AudioFormat( AudioFormat.Encoding.PCM_SIGNED, baseFormat.getSampleRate(), 16, baseFormat.getChannels(), baseFormat.getChannels() * 2, baseFormat.getSampleRate(), false); AudioInputStream dais = AudioSystem.getAudioInputStream(decodeFormat, ais); clip = AudioSystem.getClip(); clip.open(dais); gainControl = (FloatControl)clip.getControl(FloatControl.Type.MASTER_GAIN); } catch (Exception e) { e.printStackTrace(); } }
public void setPlayer(Wavefile af) throws Exception{ clip = af.getClip(); clip.open(); fullLength = clip.getFrameLength(); endPoint = fullLength; gainControl = (FloatControl) clip.getControl(FloatControl.Type.MASTER_GAIN); playing = false; clip.addLineListener(new LineListener(){ @Override public void update(LineEvent arg0) { while(playing){ int tempframe = clip.getFramePosition(); MakamBoxAnalysis.positionSlide.setValue(tempframe); if (stopbutton!=null&&tempframe == fullLength){ stopbutton.doClick(); } else if(stopbutton!=null && tempframe>=endPoint){ playAgain(); } else if (tempframe == fullLength){ stop(); } } } }); }
@Override public void invokeAction(final PiAction action) throws RaspberryPiAppException { final String soundFile = baseSoundDirectory + action.getValue(); LOGGER.debug("Playing sound file: '{}'", soundFile); try { final AudioInputStream audioInputStream = AudioSystem.getAudioInputStream( new File(soundFile)); final Clip clip = AudioSystem.getClip(); clip.open(audioInputStream); // play at maximum volume final FloatControl gainControl = (FloatControl) clip.getControl(FloatControl.Type.MASTER_GAIN); gainControl.setValue(gainControl.getMaximum()); clip.start(); } catch (Exception e) { throw new RaspberryPiAppException(e.getMessage(), e); } }
/** * Constructor that starts off the VNSound tool with a sound at a certain volume. Will not loop. * * @param file - the file path and name of the audio to play * @param volume - volume to play the file at */ public VNSound(File file, float volume) { try { audio = AudioSystem.getAudioInputStream(file); clip = AudioSystem.getClip(); clip.open(audio); volumeControl = (FloatControl) clip.getControl(FloatControl.Type.MASTER_GAIN); setVolume(volume); clip.start(); } catch(UnsupportedAudioFileException uae) { System.out.println(uae); } catch(IOException ioe) { System.out.println(ioe); } catch(LineUnavailableException lua) { System.out.println(lua); } }
/** * Opens a new sound and replaces the old one. If object is set to loop the sound (isLoop = true) then it will loop * * @param file - the file path and name of the audio to play */ public void open(File file) { try { clip.stop(); clip.close(); audio = AudioSystem.getAudioInputStream(file); clip.open(audio); volumeControl = (FloatControl)clip.getControl(FloatControl.Type.MASTER_GAIN); clip.start(); if(isLoop) clip.loop(Clip.LOOP_CONTINUOUSLY); else clip.loop(0); } catch(UnsupportedAudioFileException uae) { System.out.println(uae); } catch(IOException ioe) { System.out.println(ioe); System.out.println(file); } catch(LineUnavailableException lua) { System.out.println(lua); } }
/** * Will open a new file for a certain volume. * * @param file - File of audio to open * @param volume - Volume of audio to play from 100 to 0 */ public void open(File file, float volume) { try { clip.stop(); clip.close(); audio = AudioSystem.getAudioInputStream(file); clip.open(audio); volumeControl = (FloatControl)clip.getControl(FloatControl.Type.MASTER_GAIN); setVolume(volume); clip.start(); if(isLoop) clip.loop(Clip.LOOP_CONTINUOUSLY); else clip.loop(0); } catch(UnsupportedAudioFileException uae) { System.out.println(uae); } catch(IOException ioe) { System.out.println(ioe); System.out.println(file); } catch(LineUnavailableException lua) { System.out.println(lua); } }
/** * Sets the volume. * * @param vol the volume */ private void setVolume(final int vol) { int volume = vol; if (volume < 0) { volume = MAX_VOLUME; } float gainDb = 0.0f; final FloatControl gain = (FloatControl) clip.getControl(FloatControl.Type.MASTER_GAIN); if (volume == 0) { gainDb = gain.getMinimum(); } else if (volume < MAX_VOLUME) { // The volume algorithm is subtractive: The implementation assumes that // the sound is already at maximum volume, so we avoid distortion by // making the amplitude values // The scaling factor for the volume would be 20 normally, but // it seems that 13 is better gainDb = (float) (Math.log10(MAX_VOLUME - volume) * 13.0); } gain.setValue(-gainDb); }
private void init(AudioFormat baseFormat) throws LineUnavailableException { decodedFormat = new AudioFormat(AudioFormat.Encoding.PCM_SIGNED, baseFormat.getSampleRate(), 16, baseFormat.getChannels(), baseFormat.getChannels() * 2, baseFormat.getSampleRate(), false); DataLine.Info info = new DataLine.Info(SourceDataLine.class, decodedFormat); line = (SourceDataLine) AudioSystem.getLine(info); line.open(decodedFormat); volumeControl = (FloatControl) line.getControl(FloatControl.Type.MASTER_GAIN); minGainDB = volumeControl.getMinimum(); ampGainDB = ((10.0f / 20.0f) * volumeControl.getMaximum()) - volumeControl.getMinimum(); cste = Math.log(10.0) / 20; //for stations we want to set the initial volume to 0 volumeControl.setValue((float) minGainDB); line.start(); //App.logger.d("prefix + WebPlayer SourceDataLine started!", null); }
private void init(AudioFormat baseFormat) throws LineUnavailableException { decodedFormat = new AudioFormat(AudioFormat.Encoding.PCM_SIGNED, baseFormat.getSampleRate(), 16, baseFormat.getChannels(), baseFormat.getChannels() * 2, baseFormat.getSampleRate(), false); DataLine.Info info = new DataLine.Info(SourceDataLine.class, decodedFormat); line = (SourceDataLine) AudioSystem.getLine(info); line.open(decodedFormat); volumeControl = (FloatControl) line.getControl(FloatControl.Type.MASTER_GAIN); minGainDB = volumeControl.getMinimum(); ampGainDB = ((10.0f / 20.0f) * volumeControl.getMaximum()) - volumeControl.getMinimum(); cste = Math.log(10.0) / 20; line.start(); //App.logger.d("prefix + WebPlayer SourceDataLine started!", null); }
private void init() { AudioFormat speexFormat = new AudioFormat(16000, 16, 1, true, false); DataLine.Info sourceLineInfo = new DataLine.Info(SourceDataLine.class, speexFormat, bufferSize); speexDecoder.init(1, 16000, 1, false); try { line = (SourceDataLine) AudioSystem.getLine(sourceLineInfo); line.open(speexFormat, bufferSize); volumeControl = (FloatControl) line.getControl(FloatControl.Type.MASTER_GAIN); minGainDB = volumeControl.getMinimum(); ampGainDB = ((10.0f / 20.0f) * volumeControl.getMaximum()) - volumeControl.getMinimum(); cste = Math.log(10.0) / 20; volumeControl.setValue((float) minGainDB); line.start(); } catch (LineUnavailableException e) { App.logger.w("Failed to create voice player (type: " + type + " id: " + playerId + "):" , e); if (!exit) close(false); } }
/** * Plays the clip with the specified volume. * @param volume the volume the play at * @param listener the line listener * @throws LineUnavailableException if a clip object is not available or * if the line cannot be opened due to resource restrictions */ public void start(float volume, LineListener listener) throws LineUnavailableException { Clip clip = getClip(); if (clip == null) return; // PulseAudio does not support Master Gain if (clip.isControlSupported(FloatControl.Type.MASTER_GAIN)) { // set volume FloatControl gainControl = (FloatControl) clip.getControl(FloatControl.Type.MASTER_GAIN); float dB = (float) (Math.log(volume) / Math.log(10.0) * 20.0); gainControl.setValue(Utils.clamp(dB, gainControl.getMinimum(), gainControl.getMaximum())); } else if (clip.isControlSupported(FloatControl.Type.VOLUME)) { // The docs don't mention what unit "volume" is supposed to be, // but for PulseAudio it seems to be amplitude FloatControl volumeControl = (FloatControl) clip.getControl(FloatControl.Type.VOLUME); float amplitude = (float) Math.sqrt(volume) * volumeControl.getMaximum(); volumeControl.setValue(Utils.clamp(amplitude, volumeControl.getMinimum(), volumeControl.getMaximum())); } if (listener != null) clip.addLineListener(listener); clip.setFramePosition(0); clip.start(); }
public void setVolume(float volume) { float max = ((FloatControl)check.getControl(FloatControl.Type.MASTER_GAIN)).getMaximum(); float min = ((FloatControl)check.getControl(FloatControl.Type.MASTER_GAIN)).getMinimum(); volume = todB(volume); if (volume > max) { volume = max; } if (volume < min) { volume = min; } this.volume = volume; ((FloatControl)check.getControl(FloatControl.Type.MASTER_GAIN)).setValue(volume); ((FloatControl)call.getControl(FloatControl.Type.MASTER_GAIN)).setValue(volume); ((FloatControl)allin.getControl(FloatControl.Type.MASTER_GAIN)).setValue(volume); ((FloatControl)bet.getControl(FloatControl.Type.MASTER_GAIN)).setValue(volume); ((FloatControl)fold.getControl(FloatControl.Type.MASTER_GAIN)).setValue(volume); ((FloatControl)win.getControl(FloatControl.Type.MASTER_GAIN)).setValue(volume); ((FloatControl)lose.getControl(FloatControl.Type.MASTER_GAIN)).setValue(volume); ((FloatControl)raise.getControl(FloatControl.Type.MASTER_GAIN)).setValue(volume); }
/** * Plays the Clip. If the sound is off, the volume is set to the minimum. * @param name The name of the Clip to play. */ public void play(String name) { Clip c = get(name); if(c != null) { c.stop(); c.flush(); c.setFramePosition(0); if(!on) { FloatControl volume = (FloatControl)c.getControl(FloatControl.Type.MASTER_GAIN); volume.setValue(volume.getMinimum()); } c.start(); } }
/** * Loops the Clip. If the sound is off, the volume is set to the minimum. * @param name The name of the Clip to loop. */ public void loop(String name) { Clip c = get(name); if(c != null) { c.stop(); c.flush(); c.setFramePosition(0); if(!on) { FloatControl volume = (FloatControl)c.getControl(FloatControl.Type.MASTER_GAIN); volume.setValue(volume.getMinimum()); } c.loop(Clip.LOOP_CONTINUOUSLY); } }
/** * * Automatically called on construction and game setting change to match clip volume to * user defined levels. * * @param value * percentage to set music volume to * */ private void setSoundVolume(int value) { if (value == 0) { soundOff = true; return; } soundOff = false; float decibelLevelOffset = SoundUtils.resolveDecibelOffsetFromPercentage(value); System.out.println("Decibel offset for sound: " + decibelLevelOffset); for (GameSoundEffect effect : GameSoundEffect.values() ) { Optional<Clip> clip = sounds.get(effect); if (clip.isPresent() ) { FloatControl gainControl = (FloatControl) clip.get().getControl(FloatControl.Type.MASTER_GAIN); gainControl.setValue(decibelLevelOffset); } } }
/** @invisible * * Prints the available controls and their ranges to the console. Not all * Controllers have all of the controls available on them so this is a way to find * out what is available. * */ public void printControls() { if (controls.length > 0) { System.out.println("Available controls are:"); for (int i = 0; i < controls.length; i++) { Control.Type type = controls[i].getType(); System.out.print(" " + type.toString()); if (type == VOLUME || type == GAIN || type == BALANCE || type == PAN) { FloatControl fc = (FloatControl) controls[i]; String shiftSupported = "does"; if (fc.getUpdatePeriod() == -1) { shiftSupported = "doesn't"; } System.out.println(", which has a range of " + fc.getMaximum() + " to " + fc.getMinimum() + " and " + shiftSupported + " support shifting."); } else { System.out.println(""); } } } else { System.out.println("There are no controls available."); } }
private float getValue(FloatControl.Type type) { float v = 0; if (hasControl(type)) { FloatControl c = (FloatControl) getControl(type); v = c.getValue(); } else { Minim.error(type.toString() + " is not supported."); } return v; }
private void setValue(FloatControl.Type type, float v) { if (hasControl(type)) { FloatControl c = (FloatControl) getControl(type); if (v > c.getMaximum()) v = c.getMaximum(); else if (v < c.getMinimum()) v = c.getMinimum(); c.setValue(v); } else { Minim.error(type.toString() + " is not supported."); } }
public AudioPlayer(InputStream in, Listener listener) throws Exception { this.in = in; this.listener = listener; AudioFormat format = new AudioFormat(AudioFormat.Encoding.PCM_SIGNED, 44100.0F, 16, 2, 4, 44100.0F, true); line = AudioSystem.getSourceDataLine(format); line.open(format); LOG.debug("Opened line " + line); if (line.isControlSupported(FloatControl.Type.MASTER_GAIN)) { gainControl = (FloatControl) line.getControl(FloatControl.Type.MASTER_GAIN); setGain(DEFAULT_GAIN); } new AudioDataWriter(); }
final public float getVolume(int intPvolumePercentage) throws Throwable { if (this.objGclip != null && this.objGclip.isControlSupported(FloatControl.Type.MASTER_GAIN)) { final FloatControl objLvolumeFloatControl = (FloatControl) this.objGclip.getControl(FloatControl.Type.MASTER_GAIN); final float fltLrange = (objLvolumeFloatControl.getMaximum() - objLvolumeFloatControl.getMinimum()) * 1.2F; return Math.min(fltLrange * Math.max(0, intPvolumePercentage) / 100.0F + objLvolumeFloatControl.getMinimum(), objLvolumeFloatControl.getMaximum()); } throw new Throwable(); }
final public void setBalance(int intPbalancePercentage) { if (this.objGclip != null && this.objGclip.isControlSupported(FloatControl.Type.PAN)) { try { final FloatControl objLbalanceFloatControl = (FloatControl) this.objGclip.getControl(FloatControl.Type.PAN); objLbalanceFloatControl.setValue(Math.max(-100, Math.min(intPbalancePercentage, 100)) / 100.0F); } catch (final Throwable objPthrowable) { Tools.err("Error while setting sound balance : ", Constants.strS_FILE_SOUND_NAME_A[this.bytGsoundFileIndex]); } } }
final public void setVolume(int intPvolumePercentage) { try { final float fltLvolume = this.getVolume(intPvolumePercentage); final FloatControl objLvolumeFloatControl = (FloatControl) this.objGclip.getControl(FloatControl.Type.MASTER_GAIN); objLvolumeFloatControl.setValue(fltLvolume); } catch (final Throwable objPthrowable) { Tools.err("Error while setting sound volume : ", Constants.strS_FILE_SOUND_NAME_A[this.bytGsoundFileIndex]); } }
private Gain() { super(FloatControl.Type.MASTER_GAIN, Toolkit.linearToDB(0.0f), Toolkit.linearToDB(2.0f), Math.abs(Toolkit.linearToDB(1.0f)-Toolkit.linearToDB(0.0f))/128.0f, -1, 0.0f, "dB", "Minimum", "", "Maximum"); }
public static void main(String args[]) throws Exception { boolean res = true; try { AudioInputStream ais = new AudioInputStream( new ByteArrayInputStream(new byte[2000]), new AudioFormat(8000.0f, 8, 1, false, false), 2000); // AudioFormat format = ais.getFormat(); DataLine.Info info = new DataLine.Info(Clip.class, format, ((int) ais.getFrameLength() * format .getFrameSize())); Clip clip = (Clip) AudioSystem.getLine(info); clip.open(); FloatControl rateControl = (FloatControl) clip.getControl( FloatControl.Type.SAMPLE_RATE); int c = 0; while (c++ < 10) { clip.stop(); clip.setFramePosition(0); clip.start(); for (float frq = 22000; frq < 44100; frq = frq + 100) { try { Thread.currentThread().sleep(20); } catch (Exception e) { break; } rateControl.setValue(frq); } } } catch (Exception ex) { ex.printStackTrace(); res = ex.getMessage().indexOf( "This method should not have been invoked!") < 0; } if (res) { System.out.println("Test passed"); } else { System.out.println("Test failed"); throw new Exception("Test failed"); } }
@Override public void setVolume(float volume) { FloatControl control = (FloatControl)this.controls.get("Master Gain"); float min = control.getMinimum(); float max = control.getMaximum(); float oldVal = control.getValue(); float newVal = volume < min ? min : (volume > max ? max : volume); control.setValue(newVal); this.trigger(AudioEvent.Type.VOLUME_CHANGED, oldVal, newVal); }
@Override public void setBalance(float balance) { FloatControl balanceControl = (FloatControl)this.controls.get("Balance"); float max = balanceControl.getMaximum(); float min = balanceControl.getMinimum(); balanceControl.setValue(balance < min ? min : (balance > max ? max : balance)); }
public void play() { if (clip != null) { if (progress != null) { progress.setMax((int) clip.getMicrosecondLength()); if (progressUpdateThread == null) { progressUpdateThread = new Thread("Progressbar Update Thread") { @Override public void run() { while (!Thread.interrupted()) { progress.setProgress((int) clip.getMicrosecondPosition()); // /1000000 } } }; progressUpdateThread.start(); } } float volume = Minecraft.getMinecraft().gameSettings.getSoundLevel(SoundCategory.RECORDS); FloatControl gainControl = (FloatControl) clip.getControl(FloatControl.Type.MASTER_GAIN); gainControl.setValue(20f * (float) Math.log10(volume)); Minecraft.getMinecraft().getSoundHandler().stopSounds(); if (isAlive()) { clip.start(); } else { start(); } } else { Minecraft mc = Minecraft.getMinecraft(); mc.getSoundHandler().stopSounds(); mc.getSoundHandler().playSound(listedSong.ps); start(); } }
/** * Sets Pan value. Line should be opened before calling this method. Linear scale : -1.0 ... +1.0 * * @param fPan * the new pan */ public void setPan(double fPan) { if (!hasControl(FloatControl.Type.PAN, panControl) || fPan < -1.0 || fPan > 1.0) return; logger.info(() -> "Pan : " + fPan); panControl.setValue((float) fPan); generateEvent(Status.PAN, getEncodedStreamPosition(), null); }
/** * Represents a control for the relative balance of a stereo signal between two stereo speakers. The valid range of values is -1.0 (left channel * only) to 1.0 (right channel only). The default is 0.0 (centered). * * @param fBalance * the new balance */ public void setBalance(float fBalance) { if (hasControl(FloatControl.Type.BALANCE, balanceControl) && fBalance >= -1.0 && fBalance <= 1.0) balanceControl.setValue(fBalance); else try { throw new StreamPlayerException(StreamPlayerException.PlayerException.BALANCE_CONTROL_NOT_SUPPORTED); } catch (StreamPlayerException ex) { logger.log(Level.WARNING, ex.getMessage(), ex); } }
public Sound(String dir) { try { URL url = getClass().getResource(dir); AudioInputStream audioInputStream = AudioSystem.getAudioInputStream(url); clip = AudioSystem.getClip(); clip.open(audioInputStream); gainControl = (FloatControl) clip.getControl(FloatControl.Type.MASTER_GAIN); } catch (Exception e) { } }