We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hi there. I have an array of identical samples for two bouncing orbs which are also in an array. A sample is to play each time a ball falls below a virtual water level. They trigger just fine, but there seems to be constant or random glitches in sample sounds at various other times when it has not crossed this threshold. The line in question where I set this threshold is contained within the orb_class. Perhaps this is completely wrong, but it triggers the samples at least:
void playSample(int arrayIndex){
if (orby < waterSurfaceHeight){
popsound[arrayIndex].rewind();
popsound[arrayIndex].play();
}
}
*Edit. The code is shortened to relevant code only an is quoted in a reply below this one.
Answers
the problem here is that we can't test your code unless we have osc and netp5. but the problem doesn't sound like it's related to those. you'd get more of an audience if you cut the code down to the bare minimum to reproduce the problem.
and if you cut out all the superfluous stuff and the problem goes away then you know it's in something you've removed...
Thanks, koogs. That makes sense. Thanks.
Here is the code paired back to the essentials.
The threshold checker is on line 83:
and the mp3?
Sorry, koogs. Hereis that mp3:
https://drive.google.com/file/d/1f0SVQGI2-_7s56yuABP8QKzeQ7MOqPFU/view?usp=sharing
add
println("Playing", arrayIndex);
after line 86, and tell me what you seeI see that it's always switching between one of the indices? I'm not sure what's going on here tbh. Is it because with the 'orby < waterSurfaceHeight', it will always be iterating through the indices while orby is below that value?
It is always playing and only gets a chance to play out the whole duration of sample when the orb dives below the water?
it's playing FAR too often
i'm guessing it should only play the sample when it hits the surface of the water, you have it playing every single frame that it's under the water.
Yeah I just want it to play only once for each time an orb initial hits surface of water. I never knew you could do that kind of printing to get info on what an area is doing. Any idea how I can fix this so it triggers only once? If I set it to = waterSurfaceHeight, nothing happens. Thanks.
it's probably never exactly waterSurfaceHeight.
so you need another variable, oldy to Orb_Class, containing the old value of y
you can remember the old value at the top of move(), before adding the increments, oldy = orby...
if the previous position was above the water and the new position is under the water then it's crossed the boundary...
it's debugging 101. don't guess what the code is doing, get it to tell you.
I'm reading your words, I'ms sure it makes sense, but I really don't know how to implement that in code. What do you mean by 'before adding the increments'?Perhaps in the processing examples folder or elsewhere there is an example I can look at. Does this old/new checking system have a particular name? Thanks.
Line 73 updates the position. You add the speed to the current position to give the new position.
So oldy = orby before that to store the old y position.
The condition now needs two clauses, and both have to be true. oldy must be above the waterline AND orby must be below for the condition to be true...
I'm so far failing. I'm sorry for exhausting your patience. I just don't get how to apply it. Thanks all the same.
sorry, it got late where i am
the old test is good as it is but you need to add the new test and they both have to be true
so something like this
where oldy is a new float added to the class and set to orby in the frst line of move.
(currently untested)
how can both line 37 and line 47 be The Ocean?
yes, that's confusing. the condition needs to be the other way up because y is 0 at the top of the screen and height at the bottom.
Sorry for the delay, koogs. Thanks for your help :)