Notify sounds (via their groups) when the base gain changes.
git-svn-id: svn+ssh://src.earth.threerings.net/nenya/trunk@980 ed5b42cb-e716-0410-a449-f6a68f950b19
This commit is contained in:
@@ -89,10 +89,8 @@ public class Sound
|
|||||||
*/
|
*/
|
||||||
public void setGain (float gain)
|
public void setGain (float gain)
|
||||||
{
|
{
|
||||||
if (_source != null) {
|
|
||||||
_source.setGain(gain * _group.getBaseGain());
|
|
||||||
}
|
|
||||||
_gain = gain;
|
_gain = gain;
|
||||||
|
updateSourceGain();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -366,7 +364,7 @@ public class Sound
|
|||||||
// configure the source with our ephemera
|
// configure the source with our ephemera
|
||||||
_source.setPosition(_px, _py, _pz);
|
_source.setPosition(_px, _py, _pz);
|
||||||
_source.setVelocity(_vx, _vy, _vz);
|
_source.setVelocity(_vx, _vy, _vz);
|
||||||
_source.setGain(_gain * _group.getBaseGain());
|
updateSourceGain();
|
||||||
_source.setSourceRelative(_sourceRelative);
|
_source.setSourceRelative(_sourceRelative);
|
||||||
_source.setMinGain(_minGain);
|
_source.setMinGain(_minGain);
|
||||||
_source.setMaxGain(_maxGain);
|
_source.setMaxGain(_maxGain);
|
||||||
@@ -389,6 +387,16 @@ public class Sound
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Updates the source gain according to our configured gain and the base gain.
|
||||||
|
*/
|
||||||
|
protected void updateSourceGain ()
|
||||||
|
{
|
||||||
|
if (_source != null) {
|
||||||
|
_source.setGain(_gain * _group.getBaseGain());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called by the {@link SoundGroup} when it wants to reclaim our source.
|
* Called by the {@link SoundGroup} when it wants to reclaim our source.
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -69,6 +69,9 @@ public class SoundGroup
|
|||||||
pooled.source.delete();
|
pooled.source.delete();
|
||||||
}
|
}
|
||||||
_sources.clear();
|
_sources.clear();
|
||||||
|
|
||||||
|
// remove from the manager
|
||||||
|
_manager.removeGroup(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -91,6 +94,9 @@ public class SoundGroup
|
|||||||
_manager = manager;
|
_manager = manager;
|
||||||
_provider = provider;
|
_provider = provider;
|
||||||
|
|
||||||
|
// register with the manager
|
||||||
|
_manager.addGroup(this);
|
||||||
|
|
||||||
// if we were unable to initialize the sound system at all, just
|
// if we were unable to initialize the sound system at all, just
|
||||||
// stop here and we'll behave as if we have no available sources
|
// stop here and we'll behave as if we have no available sources
|
||||||
if (!_manager.isInitialized()) {
|
if (!_manager.isInitialized()) {
|
||||||
@@ -139,6 +145,20 @@ public class SoundGroup
|
|||||||
return _manager.getBaseGain();
|
return _manager.getBaseGain();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called by the manager when the base gain has changed.
|
||||||
|
*/
|
||||||
|
protected void baseGainChanged (float gain)
|
||||||
|
{
|
||||||
|
// notify any sound currently holding a source
|
||||||
|
for (int ii = 0, nn = _sources.size(); ii < nn; ii++) {
|
||||||
|
Sound holder = _sources.get(ii).holder;
|
||||||
|
if (holder != null) {
|
||||||
|
holder.updateSourceGain();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/** Used to track which sources are in use. */
|
/** Used to track which sources are in use. */
|
||||||
protected static class PooledSource
|
protected static class PooledSource
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ package com.threerings.openal;
|
|||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import java.nio.IntBuffer;
|
import java.nio.IntBuffer;
|
||||||
|
|
||||||
@@ -114,7 +115,15 @@ public class SoundManager
|
|||||||
*/
|
*/
|
||||||
public void setBaseGain (float gain)
|
public void setBaseGain (float gain)
|
||||||
{
|
{
|
||||||
|
if (_baseGain == gain) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
_baseGain = gain;
|
_baseGain = gain;
|
||||||
|
|
||||||
|
// alert the groups
|
||||||
|
for (int ii = 0, nn = _groups.size(); ii < nn; ii++) {
|
||||||
|
_groups.get(ii).baseGainChanged(gain);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -316,6 +325,23 @@ public class SoundManager
|
|||||||
_streams.remove(stream);
|
_streams.remove(stream);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds a group to the list maintained by the manager. Called by groups when they are created.
|
||||||
|
*/
|
||||||
|
protected void addGroup (SoundGroup group)
|
||||||
|
{
|
||||||
|
_groups.add(group);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Removes a group from the list maintained by the manager. Called by groups when they are
|
||||||
|
* disposed.
|
||||||
|
*/
|
||||||
|
protected void removeGroup (SoundGroup group)
|
||||||
|
{
|
||||||
|
_groups.remove(group);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called when a source has been finalized.
|
* Called when a source has been finalized.
|
||||||
*/
|
*/
|
||||||
@@ -406,6 +432,9 @@ public class SoundManager
|
|||||||
/** The list of active streams. */
|
/** The list of active streams. */
|
||||||
protected ArrayList<Stream> _streams = Lists.newArrayList();
|
protected ArrayList<Stream> _streams = Lists.newArrayList();
|
||||||
|
|
||||||
|
/** The list of active groups. */
|
||||||
|
protected List<SoundGroup> _groups = Lists.newArrayList();
|
||||||
|
|
||||||
/** The list of sources to be deleted. */
|
/** The list of sources to be deleted. */
|
||||||
protected int[] _finalizedSources;
|
protected int[] _finalizedSources;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user