I plan to build a music keyboard with sampled sound, recorded previously from piano, for example.
My initial idea is to use multi-thread lib like scoop or freeRtos.
One thread/task keep checking which key has been pressed. Once it monitors some key pressed, it change some global variable to inform the sound generator.
A sound generator thread/task keep checking the global variable and will play the sound wave file.
The problem is that. Playing sound wave file is blocking. if one release the pressed key, the sound play should stop immediately. I don't find a way to do this.
A discussion on the mutiplexing doesn't help: