|
resonance 1.0.1
|
#include <stdint.h>#include <vector>#include <libsdr.h>#include <sifrpc.h>#include "os/hxstr.h"#include "synth/callbackxferbdtoiop.h"

Go to the source code of this file.
Classes | |
| struct | SoundDriverCommand |
| Command block the sound driver reads a bank transfer out of. More... | |
| struct | BankSlot |
| One loaded bank's claim on a region of sound memory. More... | |
Functions | |
| void | SynthCommand (int nCommand) |
| Voice and sound-bank driver that Ps2HardSynth is a thin class over. | |
| int | ezMidiInit () |
| Bind gCd to the sound driver's RPC server. | |
| int | SubmitSoundDriverRequest (int nSelector, uintptr_t nArgument) |
| Submit one command to the sound driver. | |
| int | ezTransToIOP (int nIopAddress, const void *pSource, int nLength) |
| Move a buffer from main memory into the sound driver's memory on the IOP. | |
| void | RegisterBankSlot (int nTag, int nDest, int nIopAddress) |
| Record that a bank claims a region of sound memory, releasing whatever claimed it before. | |
| void | ReleaseBankSlotAt (int nDest) |
| Release the bank claiming a region of sound memory. | |
| void | ReleaseAllBankSlots () |
| Release every bank and empty g_bankSlots. | |
| int | IsBankXferBusy () |
| Report whether a bank transfer is still moving. | |
| void | LoadSoundBank (const char *pszBdPath, const char *pszHdPath, int nTag, int nPlacement) |
| Load a BD and HD bank pair and record the claim. | |
| char * | FourCcToString (const void *pFourCc) |
| Copy a four-character code into a buffer it can be printed from. | |
| int | XferBankFromMemory (const void *pData, int nLength) |
| Move a bank that is already in memory to the IOP and report it complete. | |
| int | StartBdBankXfer (const char *pszPath) |
| Start a chunked BD bank transfer and report the bank's size. | |
| int | StartHdBankXfer (const char *pszPath, int nPlacement) |
| Start an HD bank transfer. | |
| void | SetBankLoadProgressHook (void(*pfnProgress)()) |
| Install the bank-load progress hook. | |
| void | DumpSynthVoices (int bActiveOnly) |
| Report the state of both SPU2 cores and all 48 voices to the log. | |
| void | InitSpu2Cores () |
| Bind libsdr and bring both SPU2 cores up. | |
| void | ConfigureSpu2Effects (int bEnable) |
| Apply the configured reverb to both SPU2 cores. | |
| void | InitSynthDriver () |
| Bring the voice and bank driver up. | |
| void | PollSynthStream () |
| Advance the streaming voice buffers. | |
| void | SetSynthStreamBar (int nBar) |
| Move the streamed audio to the start of a bar. | |
| void | PollSynthEvents () |
| Advance the driver's pending events. | |
| void | WaitForBankTransfers () |
| Wait until no bank transfer is outstanding. | |
| void | ReleaseSoundBanks () |
| Release every loaded bank. | |
| void | SendMidiToDriver (unsigned char nStatus, unsigned char nData1, unsigned char nData2) |
| Move one MIDI message to the sound driver. | |
| void | SubmitDriverSetMono (int bMono) |
| Switch the sound driver between mono and stereo output. | |
| void | SubmitDriverSetRemix (int bRemix) |
| Switch the remix mode of the sound driver. | |
| void | SubmitDriverSetPaused (int bPaused) |
| Pause or resume the sound driver. | |
| void | SubmitDriverAllNotesOff () |
| Silence every channel of the sound driver. | |
| void | ps2_InitMSin () |
| Bind the MIDI stream input of Sony's component sound library. | |
| void | StartSoundBankMovie (const char *pszPath) |
| Open the sound-bank movie and start feeding its chunks to the driver. | |
| void | StopSoundBankMovie () |
| Destroy the sound-bank movie, if one is open, and clear the pointer. | |
| void | ShutdownSynthDriver () |
| Take the voice and bank driver down. | |
Variables | |
| sceSifClientData | gCd |
| Client of the game's sound driver on the IOP, bound by ezMidiInit(). | |
| constexpr int | kSoundDriverCommandPayloadSize = 0x6c |
| Bytes of payload a command block has above its five-word header. | |
| SoundDriverCommand | g_chunkCommand |
| Block that describes one chunk of a sound bank, submitted under selector 0x1070. | |
| constexpr int | kIopStagingBufferCount = 2 |
| Staging buffers on the IOP that chunk transfers alternate between. | |
| int | g_anIopStagingAddress [kIopStagingBufferCount] |
| Addresses of the staging buffers on the IOP. | |
| int | g_nIopStagingIndex |
| Staging buffer the next chunk transfer will use. | |
| int | g_nBankIopAddress |
| Address on the IOP a sound bank is moved to. | |
| std::vector< BankSlot > | g_bankSlots |
| Every bank currently claiming sound memory. | |
| constexpr int | kBankBufferAlignment = 0x40 |
| Boundary both bank read buffers are rounded up to. | |
| CallbackXferBdToIop * | g_pBdXfer |
| Transfer currently streaming a BD bank, or null. | |
| HxStr | g_bdBankName |
| Path of the BD bank currently loaded. | |
| HxStr | g_hdBankName |
| Path of the HD bank currently loaded. | |
| constexpr int | kBankFixedDestAddress = 0x5010 |
| Destination in sound memory a placement of 0 or 1 selects. | |
| constexpr int | kBankPlacementFirstBuffer = 2 |
| Placement that selects the first destination buffer. | |
| constexpr int | kBankPlacementRotate = 3 |
| Placement that rotates through the destination buffers and the IOP addresses. | |
| constexpr int | kHdBankPathSize = 0x80 |
| Bytes of g_szHdBankPath. | |
| constexpr int | kBankDestBufferCount = 2 |
| Destination buffers the rotating placement alternates between. | |
| int | g_anBankDestAddress [kBankDestBufferCount] |
| Destinations in sound memory a bank pair may go to. | |
| int | g_nBankDestIndex |
| Destination buffer the next rotating placement will use. | |
| constexpr int | kBankIopAddressCount = 3 |
| Addresses on the IOP a bank may go to. | |
| int | g_anBankIopAddress [kBankIopAddressCount] |
| Addresses on the IOP a bank may go to. | |
| int | g_nBankIopIndex |
| Entry of g_anBankIopAddress the next rotating placement will use. | |
| char | g_szHdBankPath [] |
| Path of the HD bank, copied in by StartHdBankXfer(). | |
| int | g_nBankDestAddress |
| Address in sound memory a bank is written to. | |
| int | g_nSynthXferTag |
| Word every command block is stamped with at +0x10. | |
| void(* | g_pfnBankLoadProgress )() |
| Called once after every chunk is submitted and once when a bank transfer finishes. | |
| int | g_nHdXferInFlight |
| Non-zero while an HD bank transfer occupies the shared command block. | |
| SoundDriverCommand | g_bankCommand |
| Block that describes a whole bank, submitted under selector 0x1050 when the last chunk lands. | |
| void * | g_pHdXferBuffer |
| Buffer the HD bank transfer read into, released once the transfer reports. | |
| void * | g_pBdXferBuffer |
| Buffer the BD bank transfer reads into, released once the last chunk has been moved. | |
| void SynthCommand | ( | int | nCommand | ) |
Voice and sound-bank driver that Ps2HardSynth is a thin class over.
Named after midi_main.cpp, the string at 0x0081cc98 that the module bills its heap releases to. The module spans 0x00461a88 through 0x00465200, the zone allocator ending just below it, and has the attested behaviour of the sound subsystem: the SPU2 voices, the sound banks, and the script-facing command dispatcher. Neither Synth nor Ps2HardSynth has any of it.
There is no voice table. Every routine here that reports or configures a voice queries the SPU2 itself through libsdr's remote-call trampoline, sceSdRemote(), with the rSd* function code and the SD_* entry encoding inline at the call site. The image has no sceSd* wrapper function, so the SDK release of this era supplied the whole API as macros over that one entry point. Correspondence is exact at both levels: the function codes are rSdInit, rSdSetParam, rSdGetParam, rSdGetSwitch, rSdSetAddr, rSdGetAddr, rSdSetCoreAttr, rSdGetCoreAttr and rSdSetEffectAttr, and the entries carry libsd's 0x80 core-level flag on exactly the core-level registers.
The two bank transfers are classes rather than routines. CallbackXferBdToIop streams a BD bank in 0x2000-byte chunks and CallbackXferHdToIop moves an HD bank in one go, and both derive from AsyncCallback. The globals below are what the two share with the rest of the module. Run one script-facing synth command.
Three command numbers are recognised. Command 0 does nothing. Command 1 reports the voices through DumpSynthVoices(). Command 2 submits driver selector 0xd0 with no command block. Anything else reports Unrecognized synth cmd d, and the command number is retained in its second argument register from entry so that the report can print it.
The script layer exposes this as synth_cmd, which is the one attested title in the module.
| nCommand | The command to run. |
| int ezMidiInit | ( | ) |
Bind gCd to the sound driver's RPC server.
Initialises the SIF RPC layer, then binds server 0x12346 until the server reports ready, spinning 9999 iterations between attempts. A failed bind reports error: sceSifBindRpc and hangs. The server is the game's own IOP driver rather than libsdr's. InitSynthDriver() is the one caller.
| int SubmitSoundDriverRequest | ( | int | nSelector, |
| uintptr_t | nArgument ) |
Submit one command to the sound driver.
Every routine in the module funnels through this, twenty call sites in all, each passing a selector word and either a command block or nothing. Observed selectors are 0xd0 from SynthCommand() and from the tail of DumpSynthVoices(), 0x1070 and 0x1050 from a bank transfer, 0x10e0 from ConfigureSpu2Effects(), 0x8010 from InitSynthDriver(), and 0x8130 from 0x004642c8.
Two bits of the selector steer the send. Bit 0x1000 ships a whole 0x80-byte SoundDriverCommand from the caller's argument, read as an address; without it the argument travels as the single word of a 0x10-byte request, read as a value. Bit 0x8000 skips the busy flag and sends a different mode. On entry the routine spins until the previous request has been collected.
The title comes from what the twenty call sites have in common rather than from any one of them.
| nSelector | The command selector. |
| nArgument | One machine word whose meaning the selector decides. A selector with bit 0x1000 set takes the address of a SoundDriverCommand, 0x8130 takes a bank's tag, and 0xd0 takes nothing and is passed zero. The parameter is a word rather than a pointer because only half its callers pass one. |
| int ezTransToIOP | ( | int | nIopAddress, |
| const void * | pSource, | ||
| int | nLength ) |
Move a buffer from main memory into the sound driver's memory on the IOP.
Fills the descriptor at 0x008e5be8 with the three arguments and a zero fourth word, then issues the transfer and spins until it reports completion.
| nIopAddress | The destination on the IOP. |
| pSource | The source in main memory. |
| nLength | The number of bytes to move. |
| void RegisterBankSlot | ( | int | nTag, |
| int | nDest, | ||
| int | nIopAddress ) |
Record that a bank claims a region of sound memory, releasing whatever claimed it before.
A slot whose mDest matches takes the new tag, and its previous tag is submitted under selector 0x8130 first when it claimed anything. A slot already using the new tag under a different destination is released. A destination with no slot is appended.
| nTag | The bank's tag. |
| nDest | The region in sound memory. |
| nIopAddress | Where the bank lives on the IOP. |
| void ReleaseBankSlotAt | ( | int | nDest | ) |
Release the bank claiming a region of sound memory.
The walk stops at the first slot whose mDest matches, whether or not that slot claimed anything.
The image has no reference to this routine. LoadSoundBank() reaches the same body inline, so the out-of-line copy exists and nothing calls it.
| nDest | The region in sound memory. |
| void ReleaseAllBankSlots | ( | ) |
Release every bank and empty g_bankSlots.
Each slot that claims sound memory has its tag submitted under selector 0x8130. The slots are not reset one by one, because the vector is emptied straight afterwards. ReleaseSoundBanks() is the one caller.
| int IsBankXferBusy | ( | ) |
Report whether a bank transfer is still moving.
An HD transfer counts whenever g_nHdXferInFlight is set. A BD transfer counts while g_pBdXfer exists and has bytes left to move. MetRenderer's front-end poll is the one caller.
| void LoadSoundBank | ( | const char * | pszBdPath, |
| const char * | pszHdPath, | ||
| int | nTag, | ||
| int | nPlacement ) |
Load a BD and HD bank pair and record the claim.
Performs no work when both paths already match what is loaded. The placement argument selects where the pair goes: a negative value leaves both destinations as they are, 0 or 1 selects kBankFixedDestAddress and the first IOP address, 2 selects the first destination buffer, and 3 rotates through both destination buffers and through the IOP addresses. Anything above 3 behaves like a negative value and leaves both the destination and the IOP address as they are.
A placement other than 3 restores the destination the call found, so only the rotating placement leaves the choice behind for the next caller.
| pszBdPath | The BD bank. |
| pszHdPath | The HD bank. |
| nTag | The tag both banks are recorded and stamped with. |
| nPlacement | Where the pair goes. |
| char * FourCcToString | ( | const void * | pFourCc | ) |
Copy a four-character code into a buffer it can be printed from.
The scratch buffer is eight bytes and only the first four are ever written, so the second word terminates the string. Nothing writes that word, which is what makes the result printable.
| pFourCc | The code to copy. |
| int XferBankFromMemory | ( | const void * | pData, |
| int | nLength ) |
Move a bank that is already in memory to the IOP and report it complete.
There is no file, no asynchronous read, and no chunking: the whole buffer goes across in one transfer. The claim on the current destination is released, the IOP address rotates, and the bank block is filled with a zero length and an empty payload, because an in-memory bank has no path.
| pData | The bank. |
| nLength | The bank's length. |
| int StartBdBankXfer | ( | const char * | pszPath | ) |
Start a chunked BD bank transfer and report the bank's size.
Fills the bank block, measures the file, then opens it and queues the first chunk against a new CallbackXferBdToIop. The measured length reaches the block whether or not the measurement succeeded.
| pszPath | The bank to read. |
| int StartHdBankXfer | ( | const char * | pszPath, |
| int | nPlacement ) |
Start an HD bank transfer.
Unlike the BD transfer this queues the whole file as one read against g_hdXfer. It selects the IOP address the same way LoadSoundBank() selects a destination, and reports Can't alloc heap when the selected address is negative, which is what a failed allocation on the IOP side leaves there. The read buffer is the bank's size plus 0x40, rounded up to a 64-byte boundary.
| pszPath | The bank to read. |
| nPlacement | Where the bank goes on the IOP. |
| void SetBankLoadProgressHook | ( | void(* | pfnProgress )() | ) |
Install the bank-load progress hook.
| pfnProgress | The hook, which may be null. |
| void DumpSynthVoices | ( | int | bActiveOnly | ) |
Report the state of both SPU2 cores and all 48 voices to the log.
Writes one Core %2.2d: MMix x eff d vmix L x x R x x end x line per core, one Voice %2.2d at x env x - end d mix d d d d line per voice, and finally Using d voices total. Every value is read back from the hardware, so the report is the live mixer state rather than anything the driver retains. A voice counts towards the total when its ENDX bit is clear, which is the sample not having run out.
| bActiveOnly | Non-zero to report only the voices whose ENDX bit is clear. SynthCommand() passes 1, and zero reports all 24 voices of each core. |
| void InitSpu2Cores | ( | ) |
Bind libsdr and bring both SPU2 cores up.
Sets the two mixer routings, silences the effect send, opens both master volumes fully, and gives each core a 128 KB effect work area at the top of sound RAM, core 0 taking the highest block. Core 1's mixer routing takes the external input that core 0's does not, which is what chains the two cores.
InitSynthDriver() is the only caller.
| void ConfigureSpu2Effects | ( | int | bEnable | ) |
Apply the configured reverb to both SPU2 cores.
Per core, the routine enables the effect only when the argument is non-zero and the configuration also enables it for that core; otherwise it clears both effect volumes and turns the core attribute off. Either way it then reopens both master volumes fully. When effects are enabled it fills a sceSdEffectAttr from five configuration values, ORs SD_EFFECT_MODE_CLEAR into the mode, and both depths are the configured value shifted left by eight.
Enabling also submits a further command block to the sound driver under selector 0x10e0, built from eleven more configuration values. Every value is read through QueryConfigFlag() and QueryConfigValue() from the templates RegisterHardEffectCommands() registers.
In the PAL build the block also includes the driver's two error logs when the level specifies an error file through current_level.ps2_hsyn_error_file(). A file with a new path is opened for writing and receives a heading, and the open file is flushed when the path is unchanged. Without a path the log fields are cleared.
| bEnable | Zero to force the effect off on both cores. |
| void InitSynthDriver | ( | ) |
Bring the voice and bank driver up.
CreatePs2HardSynth() calls this immediately after construction, which is the seam between the Synth class and this module.
In the PAL build the routine also takes the two IOP buffers of the driver's error logs from the IOP heap.
| void PollSynthStream | ( | ) |
Advance the streaming voice buffers.
Performs no work while the stream at 0x006e9c58 is absent. MainLoop::Poll() drives this once per frame.
| void SetSynthStreamBar | ( | int | nBar | ) |
Move the streamed audio to the start of a bar.
Stores the bar scaled by 19200 as the frame PollSynthStream() passes to the stream, and does nothing while the stream at 0x006e9c58 is absent. Gamer's per-bar update is one caller and the routine at 0x00157578 the other. The title is inferred.
| nBar | The bar. |
| void PollSynthEvents | ( | ) |
Advance the driver's pending events.
One of MainLoop's two periodic timers drives this.
In the PAL build every sixteenth call also writes each non-empty error log to the open error file and empties the log.
| void WaitForBankTransfers | ( | ) |
Wait until no bank transfer is outstanding.
Pumps the async completion queue for as long as IsBankXferBusy() reports a transfer, which it expands inline.
| void ReleaseSoundBanks | ( | ) |
Release every loaded bank.
Submits selector 0xc0, releases every bank slot, deletes the BD transfer, clears both references to it, and assigns the empty string to both stored bank paths so that the next LoadSoundBank() cannot match what was resident. It does not wait for the transfers in flight.
| void SendMidiToDriver | ( | unsigned char | nStatus, |
| unsigned char | nData1, | ||
| unsigned char | nData2 ) |
Move one MIDI message to the sound driver.
Retains the program each channel holds in the table at 0x006e9bd8 and the bank each channel holds in the table at 0x006e9c18, and returns without submitting anything when a program change or a bank select (controller 0x20) repeats what the channel already holds. Otherwise it packs the status into the low byte, the first data byte into the second, and the second data byte into the third, and puts that word on port 0 of the MIDI stream input through sceMSIn_PutMsg().
| nStatus | The status byte. |
| nData1 | The first data byte. |
| nData2 | The second data byte. |
| void SubmitDriverSetMono | ( | int | bMono | ) |
Switch the sound driver between mono and stereo output.
Submits selector 0x110, the driver's mono command. Ps2HardSynth::SetStereo() is the one caller and passes its argument inverted.
The body is one call to SubmitSoundDriverRequest().
| bMono | Nonzero for mono output, zero for stereo. |
| void SubmitDriverSetRemix | ( | int | bRemix | ) |
Switch the remix mode of the sound driver.
Submits selector 0x100, the driver's remix command. Ps2HardSynth::SetRemixMode() is the one caller.
The body is one call to SubmitSoundDriverRequest().
| bRemix | Nonzero to enter remix mode, zero to exit it. |
| void SubmitDriverSetPaused | ( | int | bPaused | ) |
Pause or resume the sound driver.
Submits selector 0xf0, the driver's pause command. Ps2HardSynth::SetPaused() is the one caller.
The body is one call to SubmitSoundDriverRequest().
| bPaused | Nonzero to pause, zero to resume. |
| void SubmitDriverAllNotesOff | ( | ) |
Silence every channel of the sound driver.
Submits selector 0xc0, the driver's all-notes-off command, with no command block. ReleaseSoundBanks() is the one caller.
| void ps2_InitMSin | ( | ) |
Bind the MIDI stream input of Sony's component sound library.
Builds the library context at 0x00894760 with two buffer groups, the second holding one 0x400-byte MIDI stream buffer, and passes it to sceMSIn_Init(). A failure logs sceMSIn_Init Error. Otherwise the routine puts the message 0xc0 on port 0 through sceMSIn_PutMsg(). InitSynthDriver() is the one caller.
| void StartSoundBankMovie | ( | const char * | pszPath | ) |
Open the sound-bank movie and start feeding its chunks to the driver.
A movie already open is destroyed first, and the stream frame returns to zero. The new movie is streamed, and a failure to open it logs Problem starting sndbank movie with the error code and continues with the movie as constructed. Track 15 receives the bank chunks. The movie's loop offset, and the word at 0x006e9dc4, both take the current song tick.
The title is inferred from the failure message.
| pszPath | The movie file. |
| void StopSoundBankMovie | ( | ) |
Destroy the sound-bank movie, if one is open, and clear the pointer.
The title is inferred as the counterpart of StartSoundBankMovie().
| void ShutdownSynthDriver | ( | ) |
Take the voice and bank driver down.
The body is a two-instruction bare return. Ps2HardSynth's destructor is the one caller, which is what identifies the routine as the counterpart of InitSynthDriver() rather than a stub of some other member.
|
extern |
Client of the game's sound driver on the IOP, bound by ezMidiInit().
SubmitSoundDriverRequest() calls through it.
|
constexpr |
Bytes of payload a command block has above its five-word header.
|
extern |
Block that describes one chunk of a sound bank, submitted under selector 0x1070.
|
constexpr |
Staging buffers on the IOP that chunk transfers alternate between.
|
extern |
Addresses of the staging buffers on the IOP.
The table itself may be longer. Only the first two entries are reachable, because the index below is masked to one bit.
|
extern |
Staging buffer the next chunk transfer will use.
|
extern |
Address on the IOP a sound bank is moved to.
CallbackXferHdToIop::Done() moves the whole bank there, and the routine that starts a BD transfer copies it into the first word of the bank-complete block.
|
extern |
Every bank currently claiming sound memory.
|
constexpr |
Boundary both bank read buffers are rounded up to.
|
extern |
Transfer currently streaming a BD bank, or null.
StartBdBankXfer() stores the object here and then reads it back to register it with g_hdXfer, which is why the same pointer is written twice.
|
extern |
Path of the BD bank currently loaded.
|
extern |
Path of the HD bank currently loaded.
|
constexpr |
Destination in sound memory a placement of 0 or 1 selects.
|
constexpr |
Placement that selects the first destination buffer.
|
constexpr |
Placement that rotates through the destination buffers and the IOP addresses.
|
constexpr |
Bytes of g_szHdBankPath.
Bounded by the next known object at 0x00894cc0 rather than measured.
|
constexpr |
Destination buffers the rotating placement alternates between.
|
extern |
Destinations in sound memory a bank pair may go to.
|
extern |
Destination buffer the next rotating placement will use.
|
constexpr |
Addresses on the IOP a bank may go to.
Three rather than two. The first is what a placement of 0 or 1 selects, and the rotation runs through all three once and then cycles between the second and the third.
|
extern |
Addresses on the IOP a bank may go to.
|
extern |
Entry of g_anBankIopAddress the next rotating placement will use.
|
extern |
Path of the HD bank, copied in by StartHdBankXfer().
Nothing recovered reads it. The size is bounded by the next known object at 0x00894cc0 rather than measured.
|
extern |
Address in sound memory a bank is written to.
The routine that starts a transfer copies it into the bank block's mDest, and a BD transfer takes its own starting destination from there and advances one chunk at a time.
|
extern |
Word every command block is stamped with at +0x10.
What the driver does with it is unrecovered, and the writer has not been identified.
|
extern |
Called once after every chunk is submitted and once when a bank transfer finishes.
Both call sites test the hook against null first. It takes no arguments.
|
extern |
Non-zero while an HD bank transfer occupies the shared command block.
CallbackXferBdToIop defers to it, and CallbackXferHdToIop::Done() clears it. The routine that sets it is unrecovered.
|
extern |
Block that describes a whole bank, submitted under selector 0x1050 when the last chunk lands.
The routine that starts a transfer fills it once, at the start, and the completion path submits it unchanged. Its payload is the bank's path, copied in with strcpy(), and the cache is flushed straight afterwards because the driver reads the block from the IOP side.
|
extern |
Buffer the HD bank transfer read into, released once the transfer reports.
|
extern |
Buffer the BD bank transfer reads into, released once the last chunk has been moved.
This is the allocation as it came back from the heap. The read itself uses the pointer rounded up to a 64-byte boundary, which CallbackXferBdToIop stores separately.