When I find something useful to post about how audio works in the field script, I will place it here.
Let's start off by noting that there are actually three different functions used for setting sound effects in FF7 (Play Sound, Akao, and Akao2). Why? No-one knows. Play Sound (not to be confused with Play Music) is totally redundant. It isn't needed at all. More than likely it was added to be a simpler way of playing an effect. Setting a sound effect at full volume is very common (like when you collect an item). This operation is fully understood and is easy to use:
Argument 1/2: If not set to 0, these will decide the ID of the sound effect from a var.
Argument 3: ID of sound effect, if Argument 1 and 2 are set to 0.
Argument 4: Panning of the sound effect (where 63 is centred, 0 is left channel only, and 127 is right channel only).
Simple. Again, note that there is NO volume control with this operation.
For the most part, as I said, this operation is mainly used for simple "item gained" sound effects. It uses effect channel #1. So if you also use the Akao and Akao2 operations at the same time, you'll need to be mindful of that.
That brings us on to Akao and Akao2. They're identical except Akao uses 8-bit arguments and Akao2 uses 16-bit arguments. This is needed when, for example, your effect ID is over 255. Why they created two when only one is needed, we will never know. It's likely they were trying to save every byte. Perhaps because at the beginning they had no idea they'd have a surplus (CD media). I'll concentrate on Akao, but all of the following is relevant to akao2.
Akao is a one-size-fits-all operation. It can perform nearly every audio task in the game. It is used when the programmer needs more control over sound; for example, volume control, multiple sound effects, volume panning, tempo (useless in PC now because it uses streamed data, such as Vorbis).
When you first look at Akao in an editor such as Makou Reactor, you'll be struck by the number of arguments there are. Don't be frightened. Just remember that this operation is made to do everything. Because of that, you'll frequently note that many of the arguments are often set to 0. At this moment in time, the full functionality of this operation is unknown - there are many gaps. Still, let's look at some of the more useful findings:
The main thing to note about Akao is that argument 7 is the Sound Operation. This is the crucial part of the entire opcode. It sets the type of operation to be performed. So, instead of multiple opcodes, the programmer decided to create Akao and make it do all operations based on the ID placed here. Some of these operations are known, and some are not. Some do not work with the PC game at all, and some are completely useless. There are 4 channels available for sound effects, and one channel available for music. Each of the 4 sound effect channels have a corresponding operation for volume control and so on. In other words, you can change the volume and effect of channel 1 without affecting channels 2-4.
The main operations for sound effects in the PC game are:
40-43: Play sound effect on channel 1, 2, 3, 4
160-163: Volume for channel 1, 2, 3, 4
164-167: Volume transition (fading in / out) for channel 1, 2, 3, 4
168-171: Panning for channel 1, 2, 3, 4
172-175: Panning transition for channel 1, 2, 3, 4
As you can see, you can set a number of controls for the 4 channels. But once Argument 7 has been selected, the other arguments become important. This is currently the thing that makes Akao confusing. Documentation on this is scarce. Here's what I have found so far:
When playing a sound effect (Sound operation 40-43), Argument 8 is the sound effect ID, but only IF argument 9 is 0
. If argument 9 is non-0, this then changes
If argument 9 is non-0, it becomes the sound effect ID, and argument 8 then becomes the starting panning value (as above, this is 0 left, 63 centre, 127 right). I hope I have this right. However illogical, it does seem to be the case.
When setting Volume Control (Sound Operation 160-163), Argument 8 sets the volume (0-127). So, for example, if you want to set the volume of channel 2 to maximum, Argument 7 would be 161 and Argument 8 would be 127. Pretty simple.
When setting Volume Transition (Sound Operation 164-167), Argument 8 is the TIME it will take to reach a particular volume. The maximum is 255 [akao2 obviously allows for greater values] (longest time), and Argument 9 is the desired volume (again, 0-127). So, for example, if you want to fade channel 2 to volume 88 as fast as possible, you'd set Argument 7 to 165, Argument 8 to 1, and Argument 9 to 88.
I am currently unsure how the value of Time relates to actual time. That will need a peak at the assembly.
The panning and transition panning very likely work on the exact same basis.
Arguments 1-6 are used only when you wish to set the other arguments from a variable. I have not done any experimenting with this. If they are set to 0, they are ignored.