mirror of
https://github.com/2OOP/pism.git
synced 2026-02-04 10:54:51 +00:00
Hotfix for loading clip volume issue (#174)
This commit is contained in:
@@ -44,7 +44,7 @@ public class SoundEffectManager implements org.toop.framework.audio.interfaces.S
|
|||||||
}
|
}
|
||||||
|
|
||||||
asset.play();
|
asset.play();
|
||||||
// TODO: Volume of Sound Effect isn't set when loading. When loading an effect it will be full volume.
|
|
||||||
logger.debug("Playing sound: {}", asset.getFile().getName());
|
logger.debug("Playing sound: {}", asset.getFile().getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -15,6 +15,8 @@ import static javax.sound.sampled.LineEvent.Type.STOP;
|
|||||||
public class SoundEffectAsset extends BaseResource implements LoadableResource, AudioResource {
|
public class SoundEffectAsset extends BaseResource implements LoadableResource, AudioResource {
|
||||||
private final Clip clip = AudioSystem.getClip();
|
private final Clip clip = AudioSystem.getClip();
|
||||||
|
|
||||||
|
private double volume = 100; // TODO: Find a better way to set volume on clip load
|
||||||
|
|
||||||
public SoundEffectAsset(final File audioFile) throws LineUnavailableException {
|
public SoundEffectAsset(final File audioFile) throws LineUnavailableException {
|
||||||
super(audioFile);
|
super(audioFile);
|
||||||
}
|
}
|
||||||
@@ -54,6 +56,7 @@ public class SoundEffectAsset extends BaseResource implements LoadableResource,
|
|||||||
if (baseFormat.getSampleSizeInBits() > 16)
|
if (baseFormat.getSampleSizeInBits() > 16)
|
||||||
inputStream = downSampleAudio(inputStream, baseFormat);
|
inputStream = downSampleAudio(inputStream, baseFormat);
|
||||||
this.clip.open(inputStream); // ^ Clip can only run 16 bit and lower, thus downsampling necessary.
|
this.clip.open(inputStream); // ^ Clip can only run 16 bit and lower, thus downsampling necessary.
|
||||||
|
this.updateVolume(this.volume);
|
||||||
this.isLoaded = true;
|
this.isLoaded = true;
|
||||||
} catch (LineUnavailableException | UnsupportedAudioFileException | IOException e) {
|
} catch (LineUnavailableException | UnsupportedAudioFileException | IOException e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
@@ -79,6 +82,7 @@ public class SoundEffectAsset extends BaseResource implements LoadableResource,
|
|||||||
@Override
|
@Override
|
||||||
public void updateVolume(double volume) {
|
public void updateVolume(double volume) {
|
||||||
{
|
{
|
||||||
|
this.volume = volume;
|
||||||
if (clip.isControlSupported(FloatControl.Type.MASTER_GAIN)) {
|
if (clip.isControlSupported(FloatControl.Type.MASTER_GAIN)) {
|
||||||
FloatControl volumeControl =
|
FloatControl volumeControl =
|
||||||
(FloatControl) clip.getControl(FloatControl.Type.MASTER_GAIN);
|
(FloatControl) clip.getControl(FloatControl.Type.MASTER_GAIN);
|
||||||
|
|||||||
Reference in New Issue
Block a user