dakrk / manatools

Collection of tools for Dreamcast audio and music formats
GNU General Public License v3.0
6 stars 0 forks source link

Determine tone sample rate from start/end/base note and FNS/OCT #16

Open dakrk opened 3 months ago

dakrk commented 3 months ago

Currently 22050Hz is littered around the code of anything that exports or plays back tone data, however this is not always the case, as some tones may be expecting to be played back at 44100Hz for example. As such, sample rate should be determined from the start/end/base note values on the current split.

dakrk commented 1 month ago

This is even more important for OSB. Thankfully OSB seems to provide more information to do this, as it utilises the AICA OCT/FNS registers, and provides what note number it shall play at. Not sure how to calculate to and from that yet, though.

Below is data from numerous sample rates:

dakrk commented 1 month ago

Changing OCT/FNS in the file seems to have no audible effect, at least on version 2 as I have not tested version 1. It might affect envelopes and FX, however. (That should really be confirmed.)

A large part in determining sample rate is based on the base note. With the expression 44100 * (2 ** ((60 - BASE_NOTE) / 12)), base notes of 60 and 72 give the resultant sample rates 44100Hz and 22050Hz respectively.

However, for more "finer" sample rates, such as 32768Hz in the previous post, using the base note of 65 gives a result of 33037.67Hz, which is inaccurate. In cases like these, OSB files store a byte after the base note which seems to be used to "fine tune" this, to give an exact result.

What that byte stores however, I am not yet sure about, and it seems to be different between version 1 and 2.