resonance 1.0.1
Loading...
Searching...
No Matches
midi_main.h
Go to the documentation of this file.
1#pragma once
2
3#include <stdint.h>
4#include <vector>
5
6#include <libsdr.h>
7#include <sifrpc.h>
8
9#include "os/hxstr.h"
11
33
48void SynthCommand(int nCommand);
49
58extern sceSifClientData gCd;
59
72
99int SubmitSoundDriverRequest(int nSelector, uintptr_t nArgument);
100
114int ezTransToIOP(int nIopAddress, const void *pSource, int nLength);
115
118
133 int mBankAddress; // +0x00 where the bank lives on the IOP; the chunk path clears it
134 int mStagingAddress; // +0x04 buffer the chunk was moved to; the bank path never writes it
135 int mLength; // +0x08
136 int mDest; // +0x0c where the driver writes the data
137 int mTag; // +0x10 copied from g_nSynthXferTag
138 char mPayload[kSoundDriverCommandPayloadSize]; // +0x14 the path for a bank, cleared for a chunk
139};
140
148
150constexpr int kIopStagingBufferCount = 2;
151
162
169extern int g_nIopStagingIndex;
170
180extern int g_nBankIopAddress;
181
193struct BankSlot {
194 int mTag; // +0x00
195 int mDest; // +0x04 the region in sound memory this bank claims, which the walks match on
196 int mIopAddress; // +0x08 zero for a slot that claims nothing
197};
198
205extern std::vector<BankSlot> g_bankSlots;
206
220void RegisterBankSlot(int nTag, int nDest, int nIopAddress);
221
234void ReleaseBankSlotAt(int nDest);
235
247
259
279void LoadSoundBank(const char *pszBdPath, const char *pszHdPath, int nTag, int nPlacement);
280
282constexpr int kBankBufferAlignment = 0x40;
283
294
306char *FourCcToString(const void *pFourCc);
307
321int XferBankFromMemory(const void *pData, int nLength);
322
335int StartBdBankXfer(const char *pszPath);
336
351int StartHdBankXfer(const char *pszPath, int nPlacement);
352
359extern HxStr g_bdBankName;
360
367extern HxStr g_hdBankName;
368
370constexpr int kBankFixedDestAddress = 0x5010;
371
374
376constexpr int kBankPlacementRotate = 3;
377
383constexpr int kHdBankPathSize = 0x80;
384
386constexpr int kBankDestBufferCount = 2;
387
395
402extern int g_nBankDestIndex;
403
410constexpr int kBankIopAddressCount = 3;
411
419
426extern int g_nBankIopIndex;
427
437extern char g_szHdBankPath[];
438
448extern int g_nBankDestAddress;
449
458extern int g_nSynthXferTag;
459
468extern void (*g_pfnBankLoadProgress)();
469
477void SetBankLoadProgressHook(void (*pfnProgress)());
478
488extern int g_nHdXferInFlight;
489
501
508extern void *g_pHdXferBuffer;
509
519extern void *g_pBdXferBuffer;
520
535void DumpSynthVoices(int bActiveOnly);
536
551
574void ConfigureSpu2Effects(int bEnable);
575
589
600
612void SetSynthStreamBar(int nBar);
613
626
637
649
666void SendMidiToDriver(unsigned char nStatus, unsigned char nData1, unsigned char nData2);
667
680void SubmitDriverSetMono(int bMono);
681
694void SubmitDriverSetRemix(int bRemix);
695
707void SubmitDriverSetPaused(int bPaused);
708
719
732
747void StartSoundBankMovie(const char *pszPath);
748
758
Receiver that streams a BD sound bank into the sound driver one chunk at a time.
Definition callbackxferbdtoiop.h:25
Heap-allocated NUL-terminated string.
Definition hxstr.h:41
void InitSynthDriver()
Bring the voice and bank driver up.
int g_nBankIopAddress
Address on the IOP a sound bank is moved to.
void SetBankLoadProgressHook(void(*pfnProgress)())
Install the bank-load progress hook.
int SubmitSoundDriverRequest(int nSelector, uintptr_t nArgument)
Submit one command to the sound driver.
void InitSpu2Cores()
Bind libsdr and bring both SPU2 cores up.
void DumpSynthVoices(int bActiveOnly)
Report the state of both SPU2 cores and all 48 voices to the log.
SoundDriverCommand g_bankCommand
Block that describes a whole bank, submitted under selector 0x1050 when the last chunk lands.
int StartHdBankXfer(const char *pszPath, int nPlacement)
Start an HD bank transfer.
constexpr int kIopStagingBufferCount
Staging buffers on the IOP that chunk transfers alternate between.
Definition midi_main.h:150
CallbackXferBdToIop * g_pBdXfer
Transfer currently streaming a BD bank, or null.
void * g_pHdXferBuffer
Buffer the HD bank transfer read into, released once the transfer reports.
void(* g_pfnBankLoadProgress)()
Called once after every chunk is submitted and once when a bank transfer finishes.
void SubmitDriverSetMono(int bMono)
Switch the sound driver between mono and stereo output.
int g_nSynthXferTag
Word every command block is stamped with at +0x10.
int g_nHdXferInFlight
Non-zero while an HD bank transfer occupies the shared command block.
std::vector< BankSlot > g_bankSlots
Every bank currently claiming sound memory.
constexpr int kBankDestBufferCount
Destination buffers the rotating placement alternates between.
Definition midi_main.h:386
constexpr int kBankIopAddressCount
Addresses on the IOP a bank may go to.
Definition midi_main.h:410
constexpr int kSoundDriverCommandPayloadSize
Bytes of payload a command block has above its five-word header.
Definition midi_main.h:117
int g_nIopStagingIndex
Staging buffer the next chunk transfer will use.
void LoadSoundBank(const char *pszBdPath, const char *pszHdPath, int nTag, int nPlacement)
Load a BD and HD bank pair and record the claim.
void ps2_InitMSin()
Bind the MIDI stream input of Sony's component sound library.
int g_anIopStagingAddress[kIopStagingBufferCount]
Addresses of the staging buffers on the IOP.
void ReleaseBankSlotAt(int nDest)
Release the bank claiming a region of sound memory.
int StartBdBankXfer(const char *pszPath)
Start a chunked BD bank transfer and report the bank's size.
void StopSoundBankMovie()
Destroy the sound-bank movie, if one is open, and clear the pointer.
void WaitForBankTransfers()
Wait until no bank transfer is outstanding.
int XferBankFromMemory(const void *pData, int nLength)
Move a bank that is already in memory to the IOP and report it complete.
void ShutdownSynthDriver()
Take the voice and bank driver down.
constexpr int kBankFixedDestAddress
Destination in sound memory a placement of 0 or 1 selects.
Definition midi_main.h:370
sceSifClientData gCd
Client of the game's sound driver on the IOP, bound by ezMidiInit().
constexpr int kBankPlacementFirstBuffer
Placement that selects the first destination buffer.
Definition midi_main.h:373
HxStr g_hdBankName
Path of the HD bank currently loaded.
int ezMidiInit()
Bind gCd to the sound driver's RPC server.
int g_anBankIopAddress[kBankIopAddressCount]
Addresses on the IOP a bank may go to.
void PollSynthStream()
Advance the streaming voice buffers.
constexpr int kBankPlacementRotate
Placement that rotates through the destination buffers and the IOP addresses.
Definition midi_main.h:376
SoundDriverCommand g_chunkCommand
Block that describes one chunk of a sound bank, submitted under selector 0x1070.
void SubmitDriverSetRemix(int bRemix)
Switch the remix mode of the sound driver.
void * g_pBdXferBuffer
Buffer the BD bank transfer reads into, released once the last chunk has been moved.
void SendMidiToDriver(unsigned char nStatus, unsigned char nData1, unsigned char nData2)
Move one MIDI message to the sound driver.
int IsBankXferBusy()
Report whether a bank transfer is still moving.
void ReleaseSoundBanks()
Release every loaded bank.
void SetSynthStreamBar(int nBar)
Move the streamed audio to the start of a bar.
void ConfigureSpu2Effects(int bEnable)
Apply the configured reverb to both SPU2 cores.
HxStr g_bdBankName
Path of the BD bank currently loaded.
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 ReleaseAllBankSlots()
Release every bank and empty g_bankSlots.
constexpr int kBankBufferAlignment
Boundary both bank read buffers are rounded up to.
Definition midi_main.h:282
char g_szHdBankPath[]
Path of the HD bank, copied in by StartHdBankXfer().
void SynthCommand(int nCommand)
Voice and sound-bank driver that Ps2HardSynth is a thin class over.
int g_anBankDestAddress[kBankDestBufferCount]
Destinations in sound memory a bank pair may go to.
int g_nBankIopIndex
Entry of g_anBankIopAddress the next rotating placement will use.
void RegisterBankSlot(int nTag, int nDest, int nIopAddress)
Record that a bank claims a region of sound memory, releasing whatever claimed it before.
void SubmitDriverSetPaused(int bPaused)
Pause or resume the sound driver.
void StartSoundBankMovie(const char *pszPath)
Open the sound-bank movie and start feeding its chunks to the driver.
constexpr int kHdBankPathSize
Bytes of g_szHdBankPath.
Definition midi_main.h:383
int g_nBankDestAddress
Address in sound memory a bank is written to.
char * FourCcToString(const void *pFourCc)
Copy a four-character code into a buffer it can be printed from.
int g_nBankDestIndex
Destination buffer the next rotating placement will use.
void PollSynthEvents()
Advance the driver's pending events.
void SubmitDriverAllNotesOff()
Silence every channel of the sound driver.
One loaded bank's claim on a region of sound memory.
Definition midi_main.h:193
int mTag
Definition midi_main.h:194
int mDest
Definition midi_main.h:195
int mIopAddress
Definition midi_main.h:196
Command block the sound driver reads a bank transfer out of.
Definition midi_main.h:132
char mPayload[kSoundDriverCommandPayloadSize]
Definition midi_main.h:138
int mTag
Definition midi_main.h:137
int mLength
Definition midi_main.h:135
int mDest
Definition midi_main.h:136
int mBankAddress
Definition midi_main.h:133
int mStagingAddress
Definition midi_main.h:134