jombo23 / N64-Tools

N64 Tools
The Unlicense
239 stars 113 forks source link

Sng Format Export Errors #25

Open L-Spiro opened 2 years ago

L-Spiro commented 2 years ago

There seems to be some kind of error when calculating notes during Sng exports; most sets I have tried have at least 1 issue. You can hear it best here: https://www.youtube.com/watch?v=uz3xNEWEErs&list=PLWsnao9n727OPW5M2skoMqMSuczNBauZ7&index=15 You can find the same issue in Mario Tennis (U) track 00000000 (Koopa’s Stage), and it MIGHT be the same issue as in the strings here: https://www.youtube.com/watch?v=5sc6sTiR8x0 (compare to https://downloads.khinsider.com/game-soundtracks/album/micro-machines-64-turbo-1999-nintendo-64 ).

Notes seem to be flat or sharp by 1 or 2 notes.

I have researched BattleTanx: Global Assault the most so the following details are from that song (Champs Elysees (Corrupted)). The 2 most-offensive instruments are numbers 183/0xB7 (main melody part) and 87/0x57 (backing horn). The track is 000000F. Here is a recording of it with those instruments removed: https://www.dropbox.com/s/6bi6m827eu6dwhu/0000000F%2000761B88%202.wav?dl=0 You can hear that by around 00:25 the backing guitars also start to “creep” off into wrong notes. Those are instruments 155/0x9B and 48/0x30.

This is the case with the most-recent code/build. Tracks were not sorted by instrument, and were exported using N64 Midi Tool V2.

L-Spiro commented 2 years ago

Here is another example, from Gex: Enter the Gecko. These examples all sound basically fine: https://www.dropbox.com/s/3dhabnlfw0kmtdr/Game%20Over.wav?dl=0 https://www.dropbox.com/s/fu11o2stgj0eeya/Level%20Win.wav?dl=0 https://www.dropbox.com/s/q595q89imfvrju0/Gex%20Dies.wav?dl=0 https://www.dropbox.com/s/mvovoaridx495wg/Got%20Special%20Item.wav?dl=0

Compare to: https://downloads.khinsider.com/game-soundtracks/album/gex-64-enter-the-gecko-nintedo-64

But then I got to this song: https://www.dropbox.com/s/hausunp63zxkobh/Bonus%20Bonanza%20%28Aztec%202%20Step%29.wav?dl=0

The MIDI file (ZLib 00000000 003EB590) has no wobble, detune, or pitch-bending, so the only thing that I might be converting incorrectly is the sample detune. Only instruments 48 and 28 have sample detunes (of FD and FC respectively), while everything else is 0. So I made this recording with instruments 48 and 28 removed: https://www.dropbox.com/s/6gk1uofnor7j43t/Bonus%20Bonanza%20%28Aztec%202%20Step%29%20-48%2C28.wav?dl=0 It’s still off somehow.

The first 4 songs seem fine and are from bank 08 (which has to be manually added to …\N64 Soundbank Tool\Release\gameconfig.ini—a separate issue that needs to be resolved; banks 01-08 are all music). Then it moves into the ZLib files and bank 01, track 0, and suddenly it sounds all kinds of dissonance. Do different banks or songs use different musical scales? There doesn’t appear to be data anywhere that I can parse to correct this issue—it seems to be either incomplete export data or simply incorrect note exports.

L-Spiro commented 2 years ago

I am unable to record Buck Bumble due to this issue appearing in the very last song in the set: 00000013 00538E50 (Intro, bank 0x1D). There is no detune or wobble. Pitch-bending is present but applies to the bass drop late in the song, not to the incorrect notes throughout most of the song.

SubDrag commented 2 years ago

In Gex you say: "Only instruments 48 and 28 have sample detunes (of FD and FC respectively), while everything else is 0." All of the instruments have coarse and fine tune. The base key (unity tone) is adjusted by the coarse tune and fine tune is also applied. Most instruments are -18. All are negative coarse tune. Some are even larger negative.

The midi has no adjustments anywhere...perhaps this is a key midi to focus on if you can tell me what's off...is center tone the wrong direction adjusted or something?

The N64WavPtr2 games are adjusted via (this goes into soundbank dls file): keyBase = 0x3C - (signed char)coarseTune; fineTune = (signed char)fineTune;

Maybe if you manually correct the DLS, and it fixes that one song, it will clearly see why. I don't see how midi is off there is no transpose, nothing. Well, let me know if you see the connection.

L-Spiro commented 2 years ago

This is the file for bank 01, used by the song in question. ExtractedSoundbank_01.dlsDebug.txt Is the debug data wrong? That would cause problems for me, and I know that there have been differences between the debug data and what the tool displays (Perfect Dark 1.1 sample 02 shows a “Sample Vol” of 64 in the tool but no such volume appears in the debug file: image

Instrument 02
[Not in DLS] Bend Range C8
Number Sounds 0001
Sound 0000
Sampling Rate 22050.000000
Attack 80000000 Decay 7FFFFFFF Sustain 03E80000 Release E4D4F803 (Attack Volume 7F Decay Volume 7F)
Loop Count 00000001 Start 00000003 Length 0000042F
Key Base 23 Fine Tune 0000 Volume Attenuation 00000000
Key Low 00 Key High 7F Vel Low 00 Vel High 7F

In this case, the debug file is correct; I am not sure why the tool displays “64” there).

Back to Gex: Enter the Gecko, this is the full list of instruments used by the song “ZLib 00000000 003EB590” (bank 01, the file posted above): Total: 11 15, //(0F) 19, //(13) 25, //(19) 28, //(1C) 29, //(1D) 30, //(1E) 35, //(23) 36, //(24) 48, //(30) 50, //(32) 86, //(56)

My comments about instruments 48 and 28 being the only ones with detunes should have said, “the only ones the song uses that have detunes.”

I have tried to make corrections to get things to sound correct, but it is not possible. I have tried about 70 different interpretations of the “Fine Tune” attribute, but when one of them begins to sound correct, others become more incorrect. Also, the amount of incorrect is larger than the distance “Fine Tune” can cover, it seems. More than 1 note, at least in some cases, though I haven’t been able to measure this accurately. Additionally, in the case of Champs Elysees (BattleTanx: Global Assault), the notes begin fine and then drift off into wrong, suggesting that the way the notes are calculated is somehow incomplete. It also means I can’t make adjustments to the data to get correctness.

SubDrag commented 2 years ago

Yeah but Gex is really simple, and just coarse/fine tune. Midi has no changes to anything, no transposition. I guess unless you figure out some kind of reason for the difference in terms of debug sound or midi file, I really don't have a clue.

jombo23 commented 2 years ago

@L-Spiro Mind you theres a large number of features that the ingame formats support/specify that midi/sf2/dls straightup dont. Also, note http://n64devkit.square7.ch/qa/audio/soundtools.htm#04 which supports this statement. Not saying that this is impossible, just that some things are really not 'feasible'

Didn't entirely read everything, so sorry if this has been addressed

L-Spiro commented 2 years ago

@SubDrag My best idea so far has been that the game loads a frequency table for different songs. I’ve noticed that in a lot of cases the entire song sounds pitch-shifted, even when it otherwise sounds correct. In Gex: Enter the Gecko, the first 4 songs sound exactly correct, but then in the ZLib songs most of the song sounds pitch-shifted, but either not all by the same amount, or just not all. So even if the notes are correct, could it be possible that some songs, or just some parts of songs, use some kind of custom frequency table rather than the standard “equal temperament” scale? Here is a list of example scales: Equal Temperament, Pure Major, Pure Minor, Werckmeister, Kirnberger, Vallotti & Young, 1/4 shift, 1/4 tone, 1/8 tone, Indian, Arabic 1, Arabic 2, Arabic 3.

@jombo23 I wrote my own tools to parse and use all of the game’s MIDI data, including the custom data. First it loads the .MID file, then it loads the debug file, and it inserts SysEx commands into the MIDI data to replicate all of the custom functionality of the Sng format that is otherwise missing from the .MID format. I record using a Yamaha MONTAGE 8, Yamaha’s flagship synthesizer, which supports all of the custom functionality of the Sng format and much more. Similarly, I don’t use SoundFonts or DLS, I use .X3A, which is the sound bank format for Yamaha MONTAGE—basically like a SoundFont but more advanced and fully featured.

So as long as the data is there I can use it, and the more data exported the better. Even if the game uses a custom scale, I can create custom scales on my hardware to match it.

Do you guys think there could be any kind of look-up data—such as a note table or a frequency table—that could be causing this?

jombo23 commented 2 years ago

Ah ok sorry. I was on my phone before.

Why not have a look at the parser ingame and evaluate how it handles it? It should be fairly elementary given that I'm sure you can get the os function pointers for all the sequencer routines through that n64sym tool. I might take a peek later but ive been wrapped up with stuff, so no promises.

edit* jesus that battletanx one sounds bad