minicraft-plus-revived
minicraft-plus-revived copied to clipboard
Add multiple clip playing support
Fixes #93 This adds multiple sound playing support by storing sound raw data and playing the data with pointers on demand. However, if the algorithm is not handled appropriately, the sound level may be lowered for some cases (More Info). The original trial is to use arithmetic average of values for each stream, but even if it is root-mean-square or similar, the sound level cannot be considered. In the second trial, I tried to use the algorithm I found, which means to be useable, but not at all because some clipping can still be formed. Fortunately, I am able to write an algorithm based on an article talking about the base value should just be the average value of the values, but eventually with dynamic range compression. This can interestingly mix the signals in-range, and also with suitable compression factors on corresponding values, although the calculation is made more complicated.
Reference:
- https://stackoverflow.com/a/1854627 (Ways to do natively)
- https://stackoverflow.com/questions/26265575/playing-multiple-byte-arrays-simultaneously-in-java (Doing with SourceDataLine)
- https://stackoverflow.com/a/10058264 (Simple way to turn mono to stereo)
- https://stackoverflow.com/a/5626003 (Conversion between byte arrays and short arrays)
- https://stackoverflow.com/a/44468024 (First trial with SourceDataLine)
- https://stackoverflow.com/a/25102339 (Second trial with a new algorithm)
- https://stackoverflow.com/a/25102339 (Article about non-linear mixing algorithms)