News: 11 March 2016 - Forum Rules
Current Moderators - DarkSol, KingMike, MathOnNapkins, Azkadellia, Danke

Author Topic: Final Fantasy IV - Music Editor (SPC)  (Read 9796 times)

Disch

  • Hero Member
  • *****
  • Posts: 2752
  • NES Junkie
    • View Profile
Re: Final Fantasy IV - Music Editor (SPC)
« Reply #20 on: October 18, 2016, 12:01:53 pm »
*shrug*  Okay

My existing SPC player was focusing on accuracy -- which we don't really need for this -- so I'll probably chop it up to make something faster and easier to use.

The music engine should be pretty easy for me to find once I start looking.  It's already in any SPC dump, with the PC pointing to where it's at -- then just take a chunk of it and Ctrl+F to find that chunk in the ROM.


So we'll want song playback (obviously), but are you going to want individual note previews as well?  Like when the user inputs a C#, maybe we want it to play a C# on just that one channel so they can hear it as they're composing it?

And we'll want instrument playback too.



Whatever -- I'm getting ahead of myself.  Let's start with whole song playback.  I'll whip something up and post it in this thread.  Should have something by this weekend.

Squall_FF8

  • Full Member
  • ***
  • Posts: 206
    • View Profile
Re: Final Fantasy IV - Music Editor (SPC)
« Reply #21 on: October 18, 2016, 12:20:31 pm »
Quote
My existing SPC player was focusing on accuracy -- which we don't really need for this -- so I'll probably chop it up to make something faster and easier to use.
In this case I would prefer accuracy, because if I'm the composer I will take decisions based on how it sounds, so not enough accuracy may lead me to getting wrong decisions. BUT whatever is easier for you, I'm eager to hear something :)

Quote
The music engine should be pretty easy for me to find once I start looking.  It's already in any SPC dump, with the PC pointing to where it's at -- then just take a chunk of it and Ctrl+F to find that chunk in the ROM.
Nice idea! From the little I know, people that do dumps use savestate on emulators.

No need for note playback. The whole song is ok.

I'm currently working on Instruments, Import/Export from FF4 ROM.
Welcome to the FF5 Den: https://discord.gg/AUqDF85

Disch

  • Hero Member
  • *****
  • Posts: 2752
  • NES Junkie
    • View Profile
Re: Final Fantasy IV - Music Editor (SPC)
« Reply #22 on: October 18, 2016, 12:49:00 pm »
In this case I would prefer accuracy, because if I'm the composer I will take decisions based on how it sounds, so not enough accuracy may lead me to getting wrong decisions. BUT whatever is easier for you, I'm eager to hear something :)

The difference won't be audible.  By accuracy I don't mean sound quality -- I mean things like allowing for BRR samples and echo buffer to be overridden by the engine -- which I'm pretty sure FF4 doesn't do.

So I can "cheat" by decoding BRR samples once and just play them back instead of decoding them constantly like the actual SPC does.  Less accurate but nobody will ever notice.

Quote
Nice idea! From the little I know, people that do dumps use savestate on emulators.

An SPC file IS a savestate.  It's just a memory and register dump.

Look at the 'PC' register in the SPC, then go to that address in its memory dump.  Copy 20 or 30 bytes from that address and Ctrl+F to look for them in the ROM, and that'll likely tell you where the engine is.

Quote
I'm currently working on Instruments, Import/Export from FF4 ROM.

Are you importing/exporting BRR blocks?  Or wav files?

Wav files would probably be more useful for most people, but would require BRR encoding/decoding -- which I figured you'd want me to do.

Squall_FF8

  • Full Member
  • ***
  • Posts: 206
    • View Profile
Re: Final Fantasy IV - Music Editor (SPC)
« Reply #23 on: October 18, 2016, 05:36:05 pm »
Quote
Are you importing/exporting BRR blocks?  Or wav files?
Wav files would probably be more useful for most people, but would require BRR encoding/decoding -- which I figured you'd want me to do.
Sorry, the way I worded it may lead to wrong conclusions :)
FF4 require additional table with instrument IDs a song will use. I find that unnecessary because each channel include "Instrument XX" command ... but it is what it is. I added an option in my program to do that.

The Import/Export part was about SPC data and used instrument IDs (not instrument samples) from FF4 ROM.
Welcome to the FF5 Den: https://discord.gg/AUqDF85

Disch

  • Hero Member
  • *****
  • Posts: 2752
  • NES Junkie
    • View Profile
Re: Final Fantasy IV - Music Editor (SPC)
« Reply #24 on: October 22, 2016, 10:55:34 pm »
Okay.  Basics in place.  I decided to just use my existing SPC player as-is rather than rip it up and optimize it.

So instead I embedded the audio streaming stuff in the DLL, which meant thread management and a bunch of other crap.  It was pretty ugly but I got it working.


Repo is here:
https://github.com/BenWenger/MiniSplischy

DLL is here:
https://github.com/BenWenger/MiniSplischy/blob/master/bin/MiniSplischy/Release_Win32/MiniSplischy.dll

Header file (so you can see what functions are available) is here:
https://github.com/BenWenger/MiniSplischy/blob/master/include/minisplischy.h


Right now it's just a simple init/load/play/pause/stop/destroy API.  Not enough to playback music as you're editing it... but working that in shouldn't be too difficult now that I have this running.

I verified the DLL to make sure the functions are being exported properly.  I didn't check with Pascal, though -- but I don't see why it wouldn't work.  Let me know if you have problems.  Maybe you could start by making a small program to load and playback an SPC file?  ;)


Squall_FF8

  • Full Member
  • ***
  • Posts: 206
    • View Profile
Re: Final Fantasy IV - Music Editor (SPC)
« Reply #25 on: October 24, 2016, 04:09:10 am »
Quote
Okay.  Basics in place.  I decided to just use my existing SPC player as-is rather than rip it up and optimize it.
I love basics :D
Yes pretty much that's what is needed: Initialize, Load, Play, Stop, Destroy - as you you have done it :thumbsup:

Few questions:
 - what type is spc param?
 - isnt it PASCAL defined already? and yes it is simply __stdcall
 - Can I use that DLL (after tests) for: this project
I wanted to add the music when you choose battle. I ended up playing mp3, but they are HUGE and quality much lower then .spc
Welcome to the FF5 Den: https://discord.gg/AUqDF85

Disch

  • Hero Member
  • *****
  • Posts: 2752
  • NES Junkie
    • View Profile
Re: Final Fantasy IV - Music Editor (SPC)
« Reply #26 on: October 24, 2016, 11:10:16 am »
I love basics :D
Yes pretty much that's what is needed: Initialize, Load, Play, Stop, Destroy - as you you have done it :thumbsup:

Yay.

Well if this is going to be use in an editor, I assume you'll need a way to swap out chunks of memory, too.  So I'll have to work that in.  :)

Quote
- what type is spc param?

It's just a generic pointer.  It is returned from spc_initialize.  Internally it holds the state of the SPC player.  You can think of it as an instantiation of the player.

I assume Pascal has a way to hold generic pointers.  If not, you should be able to treat it as a 4-byte integer and it'd work the same:

Code: [Select]
spcplayer := spc_initialize(100)
spc_load(spcplayer, "myfile.spc")
spc_play(spcplayer)

Quote
- isnt it PASCAL defined already? and yes it is simply __stdcall

It is not defined in the C/C++ language.  It's only defined by certain headers (notably <Windows.h>).

You don't have to manually define it if you include one of those headers -- but I don't like making assumptions when writing libraries.

Quote
- Can I use that DLL (after tests) for: this project

Sure.  :)





EDIT

I added an updated version to the github which allows for basic volume control (since normal playback volume seems a bit quiet).

100 = normal volume
200 = 2x volume
50 = half volume
etc


Now that I've done that, I'd like to start looking at FF4 specific stuff in particular to see if I can figure out what needs to get loaded into the SPC unit for proper playback.  Since you're making an editor, I assume you have information on where some of this info is stored in the ROM.

Can I get you to share your notes with me?  Any information you have would be helpful.

Thanks



EDIT 2

By examining and tinkering with the SPC files, I think I've figured out how the game partitions SPC memory:

Code: [Select]
RAM locations, add $100 for file offsets:


$0000-07FF = workspace RAM
$0800-1DFF = music engine code
$1E00-1EFF = Instrument pointer table A
$1F00-1FFF = Instrument pointer table B (changes per song?)
$2000-2FFF = Score Data
$3000-9BFF = Instrument Data B
$9C00-B2FF = ??? (more space for instrument data B?)
$B300-CA6F = ??? no idea, but seems to be fixed/unchanging between songs
$CA70-CFFF = Instrument Data A
$D000-F7FF = Echo buffer
$F800-FFFF = Some kind of data used by the engine (there's a lookup table that points to it)

The game seems to have 2 sets of instruments.  "Set A" seems to be instruments that are common to all songs (trumpet, strings, etc), whereas "Set B" seems to change between songs and I would guess also includes sound effects.


I'll look at the music engine later to see if I can find a stable entry point.  If I can find one, playing songs will just be a matter of filling in instrument data, score data, and hitting play.
« Last Edit: October 25, 2016, 03:10:21 pm by Disch »

Squall_FF8

  • Full Member
  • ***
  • Posts: 206
    • View Profile
Re: Final Fantasy IV - Music Editor (SPC)
« Reply #27 on: October 25, 2016, 03:32:03 pm »
Quote
I assume Pascal has a way to hold generic pointers.  If not, you should be able to treat it as a 4-byte integer
4 byte was my first choise too  :)

Quote
Can I get you to share your notes with me?  Any information you have would be helpful.
Pretty much all that I have about in ROM locations is in the second the post here

October 26, 2016, 09:17:45 am - (Auto Merged - Double Posts are not allowed before 7 days.)
Quote
The program can't start because MSVCP140.dll is missing ...
Is it possible to build the dll, so it doesnt need external dlls?
« Last Edit: October 26, 2016, 09:17:45 am by Squall_FF8 »
Welcome to the FF5 Den: https://discord.gg/AUqDF85

Disch

  • Hero Member
  • *****
  • Posts: 2752
  • NES Junkie
    • View Profile
Re: Final Fantasy IV - Music Editor (SPC)
« Reply #28 on: October 26, 2016, 10:48:27 am »
]Is it possible to build the dll, so it doesnt need external dlls?

Whoopsie.  I thought I statically linked those runtimes.

I reuploaded.

https://github.com/BenWenger/MiniSplischy/tree/master/bin/MiniSplischy/Release_Win32

You will still need DirectSound (at least version 8 ) installed -- I use that for the audio streaming.  Though I can't imagine that'd be an issue since that comes pre-installed on most computers these days.  But if that's an issue, let me know.  I might be able to switch to waveOut for streaming.  But I'd like to avoid that if possible.  waveOut is kind of a huge pain in the arse.

CrAzY

  • Jr. Member
  • **
  • Posts: 5
    • View Profile
Re: Final Fantasy IV - Music Editor (SPC)
« Reply #29 on: October 26, 2016, 09:10:37 pm »
I posted in rogue dawn's thread... Transported here? Interesting. Apologies.

Disch

  • Hero Member
  • *****
  • Posts: 2752
  • NES Junkie
    • View Profile
Re: Final Fantasy IV - Music Editor (SPC)
« Reply #30 on: October 26, 2016, 10:59:05 pm »
Woo-hoo!  I think I found a stable entry point!

I found the sweet spot right where the SPC driver stops accepting input from the SNES-CPU and starts prepping playback for the newly loaded song.

With this info, I should be able to create a "blank" SPC file that has the FF4 music engine loaded and ready to go.  From there, you'll just have to plug in some song-specific info and hit play.


Info you'll have to provide to get playback working

1)  The musical score.  I assume you already know where this is in the ROM since you're making an editor for it.  ;P.

2)  Song-specific instruments.  I haven't looked at the actual ROM, but I'm 99% sure there's a master list of BRR samples somewhere in it, as well as some kind of table specifying which instruments get loaded for which song.

3)  A few bytes of additional info related to individual instruments (apparently seeming to do with how they're tuned).


--------------
If you want to peek into any FF4 SPC file in a hex editor, you can see the data I'm talking about.

1)  Score data is between offset 0x2100 - 0x30FF
2)  Instrument data is between offset 0x3100 - 0xB400   (with a pointer table at 0x2000-0x20FF)
3)  Extra data is between offset 0x10040-0x100FF



I'll assume you have #1 wrapped up, and/or will be able to figure it out on your own.  #2 and especially #3 might be tricky, but I should be able to help out with it.


Do you have any info on how the game determines which instruments are used for which songs?



Squall_FF8

  • Full Member
  • ***
  • Posts: 206
    • View Profile
Re: Final Fantasy IV - Music Editor (SPC)
« Reply #31 on: October 27, 2016, 04:25:50 am »
Quote
Whoopsie.  I thought I statically linked those runtimes.
Thank, now works GREAT!
Since you were talking about optimizations I checked on my virtual PC & it was keeping 4-6% CPU usage.

If you decided to try Pascal, here is what you need in order to use your DLL:
Code: [Select]
const
  DLLName = 'MiniSplischy.dll';

type
  tSpcUnit = cardinal;

function  spc_Initialize(Latency: integer): tSpcUnit; stdcall; external DLLName name 'spc_initialize';
procedure spc_Destroy(SPC: tSpcUnit); stdcall; external DLLName name 'spc_destroy';
function  spc_LoadFile(SPC: tSpcUnit; const FileName: pchar): tSpcUnit; stdcall; external DLLName name 'spc_loadFile';
procedure spc_Play(SPC: tSpcUnit); stdcall; external DLLName name 'spc_play';
procedure spc_Pause(SPC: tSpcUnit); stdcall; external DLLName name 'spc_pause';
procedure spc_Stop(SPC: tSpcUnit); stdcall; external DLLName name 'spc_stop';
function  spc_IsPlaying(SPC: tSpcUnit): tSpcUnit; stdcall; external DLLName name 'spc_isPlaying';
function  spc_GetVolume(SPC: tSpcUnit): tSpcUnit; stdcall; external DLLName name 'spc_getVolume';
procedure spc_SetVolume(SPC: tSpcUnit; Volume: integer); stdcall; external DLLName name 'spc_setVolume';
Name part is not needed if the names of the function matches the name of dll function, but I want to have a flexibility  :)

Quote
I might be able to switch to waveOut for streaming.  But I'd like to avoid that if possible.
No need. Its been long time, since DirectX come installed with Windows  :)
Welcome to the FF5 Den: https://discord.gg/AUqDF85

Disch

  • Hero Member
  • *****
  • Posts: 2752
  • NES Junkie
    • View Profile
Re: Final Fantasy IV - Music Editor (SPC)
« Reply #32 on: October 27, 2016, 07:35:18 pm »
One more update.  Added a function to allow you to load from a block of binary data (so it doesn't have to read from an external file).

https://github.com/BenWenger/MiniSplischy/tree/master/bin/MiniSplischy/Release_Win32
https://github.com/BenWenger/MiniSplischy/blob/master/include/minisplischy.h

spc_loadData is the new function.  The given pointer must point to a block of memory that is at least 0x10180 bytes in size.  The data is structured the same as the SPC file format, outlined here:

https://github.com/BenWenger/MiniSplischy/blob/master/doc/spc_file_format.txt


Note that not all the information is needed.  The only information that's used is:

- "SPC700 Registers"  (PC, A, X, Y, PSW, SP)   ....offset [0x00025..0x0002B]
- 65536 64KB RAM   ... offset:  [0x00100..0x100FF]
- 128 DSP Registers  ...  offset:  [0x10100..0x1017F]


You can fill in most of this data with the "ff4_stable.spc" file I gave here:
https://github.com/BenWenger/MiniSplischy/tree/master/bin/MiniSplischy/Release_Win32

But in your editor you'll have to overwrite the score/instrument data (as briefly outlined in my previous post) before calling spc_loadData.


-------------

At this point I don't think there's much more work I can do without stepping on your toes and/or duplicating stuff you're already doing.  So I'm going to be less proactive and stop working on this until it's clear more is needed.

I'll keep my eye on this thread.  If you have questions or if there's something else you need me to do, let me know.

Squall_FF8

  • Full Member
  • ***
  • Posts: 206
    • View Profile
Re: Final Fantasy IV - Music Editor (SPC)
« Reply #33 on: October 28, 2016, 10:32:20 am »
Version 0.3 is out!!!

- Many internal changes;
- Instrument implementation
- ROM operations (save doesnt work properly yet)
- INI - the application could be customized from there. Not ALL options are there, but soon   :thumbsup:
*you need to download the ini file, which for now is a separate file.

P.S. Not many changes in the application appearance because I must implement Goto command and that ... require rewriting the channel outline ... I'm still not sure how to do it, so I can fit all in 1280 wide screen ...
Welcome to the FF5 Den: https://discord.gg/AUqDF85

chillyfeez

  • Hero Member
  • *****
  • Posts: 824
    • View Profile
Re: Final Fantasy IV - Music Editor (SPC)
« Reply #34 on: November 01, 2016, 12:31:54 am »
Basic functionality seems to be working nicely.  :)

I can't seem to get the following buttons to do anything:
-Import ROM
-Select Song
-Instruments

Are those not fully implemented yet, or do I simply not understand how to make them work?

My "wishlist" at this juncture is pretty short, though I have no idea how easy/difficult these things are to do:
-A copy/paste function, that is, the ability to highlight several commands within a track and copy them to paste either into another track, or again within the same track. This would make entering certain musical phrases a lot quicker, when chunks of notes are repeated (but when a loop or a goto is not a possibility)
-When a command or note is entered, currently that command or note remains in the input field. It would be nice if it remained, but was highlighted. That way, hitting "enter" would re-enter the command or note, but typing would simply overwrite it. This would make for easier rapid note entry.
-A functional Goto (I know, you're working on it  :thumbsup: )

There's also this, which I think I told you about once, but I never sent you a screenshot of it:
(sorry for the links, the site I normally use to host images that I embed into forum posts is acting up on me right now)
https://drive.google.com/open?id=0BzRWRbtm4qwcd0lPd2RQOW9HUVE

https://drive.google.com/open?id=0BzRWRbtm4qwcZTFVZGtlY09aMzg

Note how I can't see the bottom line of the track. It's like the window thinks it's taller than it actually is...
Ongoing project: "Final Fantasy IV: A Threat From Within"

Latest Demo

Squall_FF8

  • Full Member
  • ***
  • Posts: 206
    • View Profile
Re: Final Fantasy IV - Music Editor (SPC)
« Reply #35 on: November 01, 2016, 03:28:07 am »
Quote
I can't seem to get the following buttons to do anything
I suppose everything is blank? If that is the case you need to download the ini file and restart the tool. Import ROM work more like ... Load - it stay in the memory. In order to really import a song you need to choose Select Song (after Import). The reason for this is that you may want to work with more then one song in the same ROM.

Quote
There's also this, which I think I told you about once, but I never sent you a screenshot of it
Currently the main screen design require around 1200 width. If you reduce it it will show the scrollbars (and hide things on the right side). I can protect it so you cant make it lesser wide ... or if you think of how to make the interface to make smaller width?
Smaller width is preferable, because I need to widen each channel because of the Goto  :)

Quote
My "wishlist" at this juncture is pretty short, though I have no idea how easy/difficult these things are to do:
Will do  :thumbsup:
Welcome to the FF5 Den: https://discord.gg/AUqDF85

chillyfeez

  • Hero Member
  • *****
  • Posts: 824
    • View Profile
Re: Final Fantasy IV - Music Editor (SPC)
« Reply #36 on: November 01, 2016, 05:12:10 am »
The width isn't the problem. The left/right scrollbar works just fine. The problem is the height. Even with the up/down scrollbar all the way down, I can't see the bottom of the window content.
Ongoing project: "Final Fantasy IV: A Threat From Within"

Latest Demo

thepatrickinator

  • Restricted Access
  • Jr. Member
  • *
  • Posts: 62
    • View Profile
Re: Final Fantasy IV - Music Editor (SPC)
« Reply #37 on: December 08, 2016, 11:01:23 pm »
If you want to make Endless Memories useful for Final Fantasy IV romhacks, use the instruments and intro from the Giant Tower song. You'll have the base act like
the Giant Tower song, but will stay true to the original version of Endless Memories. You can make a new Lunar Core music patch out of this. It will replace the Giant Tower song in Lunar Core with the new version of Endless Memories.

vince94

  • Jr. Member
  • **
  • Posts: 62
    • View Profile
Re: Final Fantasy IV - Music Editor (SPC)
« Reply #38 on: March 12, 2018, 09:06:19 pm »
I just saw a link to this on Twitter. In case this is still being worked on, I think a good goal would be to get the interface looking like either this or (in a perfect world) OpenMPT. (hopefully you'll be able to make sense out of how this is coded. it's based around N-SPC, so the codes/parameters are different than Square's music data format, but this is essentially a game-specific SPC tracker.)
I'm not sure how to use the INI file in the OP, but here's hoping someone continues developing this in the future!
« Last Edit: March 12, 2018, 09:54:34 pm by vince94 »

Squall_FF8

  • Full Member
  • ***
  • Posts: 206
    • View Profile
Re: Final Fantasy IV - Music Editor (SPC)
« Reply #39 on: March 15, 2018, 07:37:12 am »
I just saw a link to this on Twitter.
Really? I wonder who made the twit, since this project is frozen for at least a year  :'(

I would love to continue working on this and finish it. Unfortunately I'm no musician, neither expert in SPC/FF4 SPC format. I'm software developer. The person that asked for the tool was holding my hand by guiding me, providing info, PM, tests. Unfortunately he drifted away for almost a year ... and obviously I can't do that alone. In short, these were the reason to freeze the project.

vince94, Thank you for the links. It gives me an interesting perspective. One thing that I noted is that in each channel, notes use virtually one column, while commands use another, so you can have a command and a note at the same time. The other thing as concept I saw is that all channels are synchronized by the time they will play together, note/command number. I'm sure that for an artist that way is much better, but maybe a challenge to implement (I wonder why the time line axis is 0, 6, 12, ... rather 1, 2, 3... Is that connected with how long a note will play?).

Quote
I'm not sure how to use the INI file in the OP, but here's hoping someone continues developing this in the future!
If you are talking about the INI of this tool, its for internal use, no need interaction with it. As I said I will gladly continue, if I have support from the community, especially artists and hackers/developers/FF4 SPC experts :beer:

P.S. vince94, as an artist what is your impression with the tool? I know that current interface is not very artist friendly, but is fast-pace command entering in a human understandable way (hopefully)  :laugh:
Welcome to the FF5 Den: https://discord.gg/AUqDF85