Hey I have some trouble with my selfmade soundmanager.
I hear an echo of a previous played sound after running a few other sounds. I have checked the Java side and that particular sound is not being played when I hear it. So I am thinking its some buffer I havent cleared, or I am removing the sound in a wrong way. I have included som of the code, since othervise the post became too long. The poll method handles starting and stopping sounds
public void poll(float dt) {
System.out.println(_sourcesBeingPlayed.size());
//remove sounds that are done
Iterator I = _sourcesBeingPlayed.listIterator();
while(I.hasNext()){
SoundSource ss = (SoundSource)I.next();
//update play time for all sounds playing
ss._s._timeBeingPlayed+=dt;
//Update velocity and position
updateSourcePosition(ss);
updateSourceVelocity(ss);
if(_debug)
System.out.println("checking if sound with source idx "+ss._soundBufferidx+" is done" );
//is sound still playing?, if not KILL it
if(!(AL10.alGetSourcei(_soundSources.get(ss._soundBufferidx), AL10.AL_SOURCE_STATE) == AL10.AL_PLAYING)){
if(_debug)
System.out.println("Releasing Source"+ss._soundBufferidx );
//add source back to pool
_sourcePool.add(ss);
//set sound to not playing
ss._s._playing=false;
//remove reference
ss._s=null;
_soundSources.position(ss._soundBufferidx);
AL10.alDeleteSources(_soundSources);
//kill sound
I.remove();
}
}
//Update listener
createListener(_soundListener);
//Are there new sounds added? Simple FIFO que
if(_soundQue.size()>0 && _sourcePool.size()>0){
boolean done=false;
while(!done){
//sound Que is empty
if(_soundQue.size()==0)
done=true;
if(_sourcePool.size()>0 && !done){
if(_debug){
System.out.println("There are "+_sourcePool.size()+" sources left" );
System.out.println("There are "+_soundQue.size()+" sounds in QUE " );
}
Sound s = (Sound)_soundQue.get(0);
if(_debug)
System.out.println("working with sound " +s);
SoundSource ss =(SoundSource) _sourcePool.get(0);
int sourceBufidx = ss.get_soundBufferidx();
//assign sound to source
ss.assignSound(s);
//create a new sound buffer
createNewBuffer(ss,sourceBufidx);
//Start playing source
AL10.alSourcePlay(_soundSources.get(sourceBufidx));
//add source to sources being played
_sourcesBeingPlayed.add(ss);
//set sound to playing
ss._s._playing=true;
_soundQue.remove(0);
_sourcePool.remove(0);
if(_debug){
System.out.println("There are now "+_sourcePool.size()+" sources left" );
System.out.println("There are "+_sourcesBeingPlayed.size()+" sounds being played " );
printSoundsBeingPlayed();
}
}else{ //no more sources
done=true;
}
//if there are sounds left to be played update their delay times
for(int i=0;i<_soundQue.size();i++){
Sound s = (Sound)_soundQue.get(i);
s._timeDelayed +=dt;
}
}
}
}
public void printSoundsBeingPlayed(){
//if there are sounds left to be played update their delay times
for(int i=0;i<_sourcesBeingPlayed.size();i++){
SoundSource s = (SoundSource)_sourcesBeingPlayed.get(i);
}
}
/**
* @param sound
*/
public void stopSound(Sound sound) {
Iterator I = _sourcesBeingPlayed.listIterator();
while(I.hasNext()){
SoundSource ss = (SoundSource)I.next();
if(ss._s==sound){
AL10.alSourceStop(_soundSources.get(ss._soundBufferidx));
ss._s=null;
_sourcePool.add(ss);
I.remove();
}
}
}
}