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
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139
| public void poll(float dt) { System.out.println(_sourcesBeingPlayed.size()); Iterator I = _sourcesBeingPlayed.listIterator(); while(I.hasNext()){ SoundSource ss = (SoundSource)I.next(); ss._s._timeBeingPlayed+=dt; updateSourcePosition(ss); updateSourceVelocity(ss); if(_debug) System.out.println("checking if sound with source idx "+ss._soundBufferidx+" is done" ); if(!(AL10.alGetSourcei(_soundSources.get(ss._soundBufferidx), AL10.AL_SOURCE_STATE) == AL10.AL_PLAYING)){ if(_debug) System.out.println("Releasing Source"+ss._soundBufferidx ); _sourcePool.add(ss); ss._s._playing=false; ss._s=null; _soundSources.position(ss._soundBufferidx); AL10.alDeleteSources(_soundSources); I.remove(); } } createListener(_soundListener); if(_soundQue.size()>0 && _sourcePool.size()>0){ boolean done=false; while(!done){ 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(); ss.assignSound(s); createNewBuffer(ss,sourceBufidx);
AL10.alSourcePlay(_soundSources.get(sourceBufidx)); _sourcesBeingPlayed.add(ss); 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{ done=true; } for(int i=0;i<_soundQue.size();i++){ Sound s = (Sound)_soundQue.get(i); s._timeDelayed +=dt; }
} } } public void printSoundsBeingPlayed(){ for(int i=0;i<_sourcesBeingPlayed.size();i++){ SoundSource s = (SoundSource)_sourcesBeingPlayed.get(i); } }
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(); } } } } |