Author Topic: FF7 PSX sound effects format  (Read 273 times)

Phanoo

  • Fast newbie
  • *
  • Posts: 23
  • Karma: 5
  • Musician & Programmer
    • View Profile
    • FM Composer
FF7 PSX sound effects format
« on: 2018-04-16 03:20:36 »
Hello

This always puzzled me, the PC version using hundred of megabytes worth of wave files for sound effects, while the PSX version only used a tiny 50Kb file (EFFECT.ALL).
After some searches, there seems to be nobody interested into reverse engineering this, please correct me if I'm wrong ?

I just did an attempt this evening, to get a better understaning of this format. I'm interested in sound synthesis, in fact I'm the developer of a music software called FM Composer.

So, here's my findings.


The data from byte 8 to 2829 is an offset table for each individual sounds. Each entry is 2-byte long. Some entries are "0xFFFF", I don't know why, let's say we ignore them. After byte #2829 there is an empty block made of 0xFF bytes then the actual sound data. Following this table I can extract 936 sounds from the file.
You can extract them with this little code I made, you need to put EFFECT.ALL in the same dir and create an 'out' folder. Compiled version here : http://sdamo.io/ff7sfx.zip
Or all the sounds directly extracted here : http://sdamo.io/ff7/out.zip
Code: [Select]
int main()
{
FILE *fp=fopen("EFFECT.ALL", "rb");
fseek(fp,8,SEEK_SET);
vector<int> offsets;

offsets.push_back(0);
unsigned short temp;

printf("Analyzing...\n");

int endcount=0;
do
{
fread((char*)&temp,2,1,fp);

if (temp == 0xFFFF) {
endcount++;
continue;
}
else
endcount=0;

offsets.push_back(temp);

}while (endcount<3);

printf("%d sounds found.\n",offsets.size());
printf("Extracting...\n");

fseek(fp,4096,SEEK_SET);

char *sound_data;

for (unsigned i = 0; i < offsets.size()-1; i++)
{

int size=offsets[i+1]-offsets[i];
if (size<=0)
continue;


sound_data = (char*)malloc(size);

fread(sound_data,size,1,fp);

FILE *fp2=fopen(string("out/"+to_string(i)).c_str(), "wb");
fwrite(sound_data, size, 1,fp2);
fclose(fp2);
free(sound_data);

}

fclose(fp);
printf("Done.\n");
}


All sounds seems to finish with an '0xA0' byte.

Okay it's nice but the hardest part is to figure how the format works. I've messed with the first sound of the file (which is the menu beep sound), by modifying random bytes directly in the ISO image, then restarting the game with an emulator, and yeah I've got more or less interesting results !

Check this : http://sdamo.io/ff7/sounds.zip It's the altered beep sounds, depending on which bytes i modified (naming : chk-[bytes modified])

Some results are really interesting, with some delays, pitch or noises...

Anyone interested in helping me to find how those parameters works ? (basically, which bytes/values affects which sound parameter).
« Last Edit: 2018-04-16 17:13:05 by Phanoo »

DLPB

  • No life
  • *
  • Posts: 9023
  • Karma: 271
  • For I realized that God's a young man, too.
    • View Profile
Re: FF7 PSX sound effects format
« Reply #1 on: 2018-04-16 16:18:02 »
I am very interested in this....  Been waiting for someone to tackle it, as I am sadly at a loss.  No idea where to start with it.  But kudos for you delving in.

It's amazing that after all these years the effects data file in psx version is so poorly understood.


Phanoo

  • Fast newbie
  • *
  • Posts: 23
  • Karma: 5
  • Musician & Programmer
    • View Profile
    • FM Composer
Re: FF7 PSX sound effects format
« Reply #2 on: 2018-04-16 17:12:01 »
Yes, i'm really surprised nobody wrote some tools to deal with them.

Some more investigation with the menu beep sound, here's its contents :
Code: [Select]
A1 01 A5 05 A4 05 0F B1 2C 81 A0 A1 00 A5 06 B1 2E A4 08 0C 08 A0
As I said, A0 is the end marker for each sound, but this one has an A0 right in the middle. It means the final sound is made of two sounds layered (played at the same time) :

Code: [Select]
A1 01 A5 05 A4 05 0F B1 2C 81 A0... creates this sound : http://sdamo.io/ff7/beep_1st.wav

Code: [Select]
A1 00 A5 06 B1 2E A4 08 0C 08 A0... creates this sound : http://sdamo.io/ff7/beep_2nd.wav

About this A0 byte, it seems to follow the opcodes discovered here for the AKAO frames : http://archive.is/0PE01

The page lists other opcodes, which may help :
Code: [Select]
0xA0 (Finish Channel)
0xA1 (Load Instrument)
0xA3 (Volume Modifier)
0xA5 (Pitch Divider)
0xA8 (Channel Volume)
0xAA (Channel Pan)
0xC8 (Loop Point)
0xCA (Return to Loop Point)
0xE8 (Tempo)
0xEA (Reverb Depth)
0xC2 (Turn On Reverb)

Maybe the SFX engine and music engine share the same code, the SFX simply having more advanced opcodes for doing complex time-based things and modulations.
« Last Edit: 2018-04-16 17:21:04 by Phanoo »

DLPB

  • No life
  • *
  • Posts: 9023
  • Karma: 271
  • For I realized that God's a young man, too.
    • View Profile
Re: FF7 PSX sound effects format
« Reply #3 on: 2018-04-16 17:19:51 »
the problem ishow do you faithfully recreate the sounds from that alone. the psx sound chip needs emulating too?

Phanoo

  • Fast newbie
  • *
  • Posts: 23
  • Karma: 5
  • Musician & Programmer
    • View Profile
    • FM Composer
Re: FF7 PSX sound effects format
« Reply #4 on: 2018-04-16 17:29:39 »
ATM i'm directly replacing the hex contents in my FF7 iso image, then run the game from an emulator (ePSXe) so I can hear how my changes affects the sound.

If we manage to guess the whole format, I dunno how hard it would be to create some rough emulation so a software could play the sounds. In fact i didnt thought about emulation, more like a little sound engine written from scratch (not sounding perfect but just to give an idea), with an editor allowing to have fun with parameters and a save feature. I know nothing about emulators, but i'm not bad at dealing with MIDI, sound synthesis and such things
« Last Edit: 2018-04-16 17:33:44 by Phanoo »

Phanoo

  • Fast newbie
  • *
  • Posts: 23
  • Karma: 5
  • Musician & Programmer
    • View Profile
    • FM Composer
Re: FF7 PSX sound effects format
« Reply #5 on: 2018-04-16 21:19:17 »
Mappings for the A1 xx command which is the waveform select  :)

Some of them points to INSTR.ALL samples while some others appears to be synthsized, or stored elsewhere. I've recorded those 'custom' waveforms as wave files. Samples from INSTRL.ALL can be extracted with PSound !

Code: [Select]
A1 00 => sine
A1 01 => bright_sine
A1 02 => pulse02.wav
A1 03 => pulse02-3.wav
A1 04 => INSTR.ALL_0000
A1 05 => INSTR.ALL_0001
A1 06 => INSTR.ALL_0002
A1 07 => INSTR.ALL_0003
A1 08 => pulse5.wav
A1 09 => INSTR.ALL_0004
A1 0A => INSTR.ALL_0005
A1 0B => same as 02
A1 0C => pulse3
A1 0D => pulse4
A1 0E => INSTR.ALL_0006
A1 0F => INSTR.ALL_0007
A1 10 => INSTR.ALL_0008
A1 11 => INSTR.ALL_0009
A1 12 => INSTR.ALL_0010
A1 13 => smooth_square.wav
A1 14 => smooth_saw.wav
A1 15 => smooth_triangle.wav
A1 16 => smooth_pulse.wav
A1 17 => INSTR.ALL_0011
A1 18 => INSTR.ALL_0012
A1 19 => INSTR.ALL_0013

Values greater than 19 doesn't seems to exist in the file, although i didnt checked them all.
« Last Edit: 2018-04-16 21:26:30 by Phanoo »

DLPB

  • No life
  • *
  • Posts: 9023
  • Karma: 271
  • For I realized that God's a young man, too.
    • View Profile
Re: FF7 PSX sound effects format
« Reply #6 on: 2018-04-16 21:37:15 »
This is impressive work :)   I can't remember if PSX was able to synth sounds...  I bet it could do simple sine etc

Phanoo

  • Fast newbie
  • *
  • Posts: 23
  • Karma: 5
  • Musician & Programmer
    • View Profile
    • FM Composer
Re: FF7 PSX sound effects format
« Reply #7 on: 2018-04-18 19:02:23 »
Ok the format is complex, it's a bit inspired from MIDI since I discovered there are Running Status commands. That means, if you choose the command 0xB1 for example, you can put after as much parameters as you want until you put another command byte.

Eg : B1 52 34 65 02 31.... will play some notes with the select waveform.

It's a nice thing to save space.

The VERY annoying thing is that several parameters are merged into ONE byte. A single byte after the B1 command is enough to set the pitch, the duration and the release rate. It makes the thing quite annoying to reverse engineer  ;D

For the octave selection (A5 command), it has some annoying things too. When you reach a high pitch the next value isn't making it higher again, instead it starts from a lower note, and the next values produce other various pitches. I think maybe the note frequency is bit-shifted or something, making strange results at some point.

I may not success at writing a program that replays and allow to edit the sounds from the PSX game. But i'll release a document with my findings anyway.

The guy who developed this system can be proud of him, it's very clever work. I wonder how was the editor that Square used to design all the sounds.
« Last Edit: 2018-04-18 19:06:35 by Phanoo »

DLPB

  • No life
  • *
  • Posts: 9023
  • Karma: 271
  • For I realized that God's a young man, too.
    • View Profile
Re: FF7 PSX sound effects format
« Reply #8 on: 2018-04-18 22:16:14 »
That's the million dollar question....  how did they create these sounds.  I mean... is it possible they had something that could convert a real sound of a fire into code? Akao created this sound system and he clearly intended to make it as small as possible because his experience was with small cartridges and not CD.  In early ff7 days it was going to be on N64.

It makes sense now that he's used every bit.

Phanoo

  • Fast newbie
  • *
  • Posts: 23
  • Karma: 5
  • Musician & Programmer
    • View Profile
    • FM Composer
Re: FF7 PSX sound effects format
« Reply #9 on: 2018-04-18 23:40:26 »
Yes it clearly seems designed for a low memory system, such optimization makes no sense for a CD-Rom game. I guess they re-used some code they made for the SNES.

I don't think they had a tool converting real sounds into synthesized ones, it's a very, very complicated task. The pitch variations are often complex in the sounds, maybe they had a way to draw the lines that get converted into the appropriate commands..

luksy

  • Insane poster
  • *
  • Posts: 372
  • Karma: 46
    • View Profile
Re: FF7 PSX sound effects format
« Reply #10 on: 2018-04-19 19:42:10 »
The SNES SPU was manufactured by Sony, in fact the PS1 and SNES SPUs are quite similar so I'm guessing Akao just ported a lot of his existing code straight over.

Phanoo

  • Fast newbie
  • *
  • Posts: 23
  • Karma: 5
  • Musician & Programmer
    • View Profile
    • FM Composer
Re: FF7 PSX sound effects format
« Reply #11 on: Yesterday at 13:24:53 »
Work in progress  :)



It can already play some sounds, although most of them are garbage since not all commands are understood at this point.

Phanoo

  • Fast newbie
  • *
  • Posts: 23
  • Karma: 5
  • Musician & Programmer
    • View Profile
    • FM Composer
Re: FF7 PSX sound effects format
« Reply #12 on: Today at 13:37:31 »
I was wondering why most of the noise-based sounds in my engine didn't sounded like the original ones, it's because FF7 sound engine is able to use the noise generator from the sound chip, instead of simply using the sampled noise-like waveform in INSTR.ALL. The one from the sound chip has a very low-fi sound to it, because it's 4-bit resolution (=16 steps) and the frequency only changes the rate at which the new random value is generated. Fortunately it's easy to emulate, using the standard C rand() function creates identical sounds !

I've also added the support for LFO (low frequency oscillator), it's triggered with the B4 command, and is quite complex because it uses several patterns.. They are all 32-steps lengths, i've implemented the first seven of them. Magic sounds makes heavy use of them !

The first version of the sfx player will be soon available... it's not accurate but already quite fun.

There are still commands I don't understand at all. All the Cx commands. They seems to be related to some looping or re-triggering of other commands. Weird.



Green highlighted parts are the understood commands :) (more or less accurately since the engine is written from scratch from my guessings, it's not an emulation)


EDIT : found what C8 and C9 means :)  C9 jumps to C8 like a loop point. The number of time it repeats depends on the parameter just after C9 !
« Last Edit: Today at 18:13:16 by Phanoo »

luksy

  • Insane poster
  • *
  • Posts: 372
  • Karma: 46
    • View Profile
Re: FF7 PSX sound effects format
« Reply #13 on: Today at 19:30:21 »
This is some cool stuff, looking forward to seeing (& hearing) the player!