@krikor sorry, not had time to look at this... since to give you a proper answer would require me to decipher you patch.
this could be execution order, but if you are using table/load (or using an object which uses the same logic) it could also be down to the fact that the load is done asynchronously with respect to the audio thread. this is because its a very big no no to do IO (e.g. access sdcard) in the audio thread, as it can block it and cause audio glitches.
so what could be happening is your asking it to be loaded, and then triggering the sample before it has completed loading.
Ive been meaning to add a 'loaded' output on the table/load so patches know when its fully loaded.
practically (as in its not theoretically correct, but should work), you can workaround this by using two tables, that you alternate between i.e. you load into one, whilst doing playback on the other, and then switch this around. (often referred to as double buffering) you'll have to use a 'guestimate' delay to decide when to switch buffers, due to the table/load not telling you when loading is complete.
it would actually be quite trivial to create a new object which does this 'behind the scenes' if you know c++.
what do you mean by flush? you mean set all samples to zero?
this is trivial to do, but its probably not the right solution, as it wastes cpu cycles.
I assume your use cases are
a) to have an empty buffer... but in this case, you just need to know the buffer should be empty, and not play it
b) because the new sample is shorter than the old sample
I guess this is the main case...
again, set the whole buffer to zero before hand is wasteful, there are two solutions to this
after the load, we could set the remaining bytes of the table to zero... (so less bytes that doing entire buffer), but better still would be to report the end position after table/load such that when you playback a sample, you don't ever playback past the endpoint (this saves even more cpu cycles)
ive actually been meaning to add the 'end position' to table/load as well, but again, not been a pressing priority for me, so not got around to it. (honestly, i don't do much sample playback)