I am writing a soundtrack for my module in Neverwinter Nights. This soundtrack is inspired by a few other soundtracks, and it *might* contain some elements of those copyrighted songs. After reading a lot on the laws regarding copyrighted music, I am confused. I know that one must obtain a mechanical license to release a cover to a copyrighted song. However, where does "cover" start and "free composing" ends?
For example, I really like this song from Planescape: Torment:
https://www.youtube.com/watch?v=HCpk7HIryK0
Now, suppose I want to write a song based on this song, but not quite copying it. I want to take the entire flute party, change it a little bit in a few places and write a completely new orchestration, with different instruments and different tracks. It will sound completely different, but someone who has heard this song will be able to recognize the reference.
Would it be legal to write such a composition and release it as a part of my module for public royalty free access? Or do I still need to obtain some kind of license? Where is the border of what is allowed and what is not without obtaining the owner's permission?
I understand it is probably a better idea to ask this on some forum for lawyers, but perhaps someone here has encountered a similar question and knows something about it?