arm7: run clang-format on SND_*

This commit is contained in:
Michael Panzlaff 2021-08-03 18:44:55 +02:00
parent 6482eb6e2a
commit d72270d4bd
30 changed files with 1752 additions and 1294 deletions

View File

@ -9,4 +9,4 @@ void SND_SetupAlarm(s32 idx, OSTick tick, OSTick period, u32 id);
void SND_StartAlarm(s32 idx);
void SND_StopAlarm(s32 idx);
#endif //GUARD_SND_ALARM_H
#endif // GUARD_SND_ALARM_H

View File

@ -1,11 +1,17 @@
#ifndef GUARD_SND_BANK_H
#define GUARD_SND_BANK_H
#include "nitro/SND_bank_shared.h"
#include "nitro/types.h"
#include "nitro/SND_bank_shared.h"
BOOL SND_ReadInstData(const struct SNDBankData *bankData, s32 program, s32 midiKey, struct SNDInstData *instData);
BOOL SND_ReadInstData(
const struct SNDBankData *bankData, s32 program, s32 midiKey, struct SNDInstData *instData);
const struct SNDWaveData *SND_GetWaveDataAddress(const struct SNDWaveArc *waveArc, s32 wave);
BOOL SND_NoteOn(struct SNDExChannel *chn, s32 midiKey, s32 velocity, s32 length, const struct SNDBankData *bankData, const struct SNDInstData *instData);
BOOL SND_NoteOn(struct SNDExChannel *chn,
s32 midiKey,
s32 velocity,
s32 length,
const struct SNDBankData *bankData,
const struct SNDInstData *instData);
#endif //GUARD_SND_BANK_H
#endif // GUARD_SND_BANK_H

View File

@ -3,7 +3,8 @@
#include "nitro/types.h"
void SND_SetupCapture(int idx, int format, void *captureData, int size, BOOL loop, int capCtrlSrc, int capCtrlDst);
void SND_SetupCapture(
int idx, int format, void *captureData, int size, BOOL loop, int capCtrlSrc, int capCtrlDst);
BOOL SND_IsCaptureActive(int idx);
#endif //GUARD_SND_CAPTURE_H
#endif // GUARD_SND_CAPTURE_H

View File

@ -3,8 +3,7 @@
#include "nitro/types.h"
void SND_SetupChannelPcm(
int chnIdx,
void SND_SetupChannelPcm(int chnIdx,
const void *data,
int format,
int loop,
@ -13,25 +12,11 @@ void SND_SetupChannelPcm(
int volume,
int volumeDiv,
int timer,
int pan
);
int pan);
void SND_SetupChannelPsg(
int chnIdx,
int waveDuty,
int volume,
int volumeDiv,
int timer,
int pan
);
void SND_SetupChannelPsg(int chnIdx, int waveDuty, int volume, int volumeDiv, int timer, int pan);
void SND_SetupChannelNoise(
int chnIdx,
int volume,
int volumeDiv,
int timer,
int pan
);
void SND_SetupChannelNoise(int chnIdx, int volume, int volumeDiv, int timer, int pan);
void SND_StopChannel(int chnIdx, int hold);
@ -44,4 +29,4 @@ void SND_SetMasterPan(int pan);
u32 SND_GetChannelControl(int idx);
void SNDi_SetSurroundDecay(int decay);
#endif //GUARD_SND_CHANNEL_H
#endif // GUARD_SND_CHANNEL_H

View File

@ -6,4 +6,4 @@
void SND_CommandInit(void);
void SND_CommandProc(void);
#endif //GUARD_SND_COMMAND_H
#endif // GUARD_SND_COMMAND_H

View File

@ -9,7 +9,8 @@
void SND_ExChannelInit(void);
void SND_UpdateExChannel(void);
void SND_ExChannelMain(BOOL step);
BOOL SND_StartExChannelPcm(struct SNDExChannel *chn, const struct SNDWaveParam *wave, const void *data, s32 length);
BOOL SND_StartExChannelPcm(
struct SNDExChannel *chn, const struct SNDWaveParam *wave, const void *data, s32 length);
BOOL SND_StartExChannelPsg(struct SNDExChannel *chn, s32 duty, s32 length);
BOOL SND_StartExChannelNoise(struct SNDExChannel *chn, s32 length);
s32 SND_UpdateExChannelEnvelope(struct SNDExChannel *chn, BOOL step);
@ -19,7 +20,11 @@ void SND_SetExChannelSustain(struct SNDExChannel *chn, s32 sustain);
void SND_SetExChannelRelease(struct SNDExChannel *chn, s32 release);
void SND_ReleaseExChannel(struct SNDExChannel *chn);
BOOL SND_IsExChannelActive(struct SNDExChannel *chn);
struct SNDExChannel *SND_AllocExChannel(u32 channelMask, int priority, u32 flags, SNDExChannelCallback callback, void *callbackUserData);
struct SNDExChannel *SND_AllocExChannel(u32 channelMask,
int priority,
u32 flags,
SNDExChannelCallback callback,
void *callbackUserData);
void SND_FreeExChannel(struct SNDExChannel *chn);
void SND_InvalidateWave(const void *start, const void *end);
@ -35,4 +40,4 @@ void SND_StartLfo(struct SNDLfo *lfo);
void SND_UpdateLfo(struct SNDLfo *lfo);
int SND_GetLfoValue(struct SNDLfo *lfo);
#endif //GUARD_SND_EXCHANNEL_H
#endif // GUARD_SND_EXCHANNEL_H

View File

@ -9,6 +9,7 @@ void SND_Shutdown(void);
void SND_BeginSleep(void);
void SND_EndSleep(void);
void SND_SetMasterVolume(int vol);
void SND_SetOutputSelector(int leftOutputFrom, int rightOutputFrom, int outputCh1ToMixer, int outputCh3ToMixer);
void SND_SetOutputSelector(
int leftOutputFrom, int rightOutputFrom, int outputCh1ToMixer, int outputCh3ToMixer);
#endif //GUARD_SND_GLOBAL_H
#endif // GUARD_SND_GLOBAL_H

View File

@ -5,4 +5,4 @@
#include "nitro/SND_exChannel_shared.h"
#endif //GUARD_SND_LFO_H
#endif // GUARD_SND_LFO_H

View File

@ -13,4 +13,4 @@ void SND_SendWakeupMessage(void);
void SNDi_LockMutex(void);
void SNDi_UnlockMutex(void);
#endif //GUARD_SND_MAIN_H
#endif // GUARD_SND_MAIN_H

View File

@ -21,4 +21,4 @@ void SND_SetTrackAllocatableChannel(int player, u32 trackMask, u32 channelMask);
void SND_InvalidateSeq(const void *start, const void *end);
void SND_InvalidateBank(const void *start, const void *end);
#endif //GUARD_SND_SEQ_H
#endif // GUARD_SND_SEQ_H

View File

@ -13,4 +13,4 @@ u16 SND_CalcTimer(int timer, int pitch);
extern const s16 SNDi_DecibelSquareTable[128];
#endif //GUARD_SND_UTIL_H
#endif // GUARD_SND_UTIL_H

View File

@ -10,4 +10,4 @@ void SND_SetPlayerLocalVariable(int player, int var, s16 value);
void SND_SetPlayerGlobalVariable(int var, s16 value);
void SND_UpdateSharedWork(void);
#endif //GUARD_SND_WORK_H
#endif // GUARD_SND_WORK_H

View File

@ -1,23 +1,27 @@
#include "SND_alarm.h"
#include "SND_work.h"
#include "OS_alarm.h"
#include "OS_tick.h"
#include "PXI_fifo.h"
#include "SND_work.h"
static void AlarmHandler(void *msg);
void SND_AlarmInit(void) {
for (s32 i = 0; i < SND_ALARM_COUNT; i++) {
void SND_AlarmInit(void)
{
for (s32 i = 0; i < SND_ALARM_COUNT; i++)
{
SNDi_Work.alarms[i].enable = 0;
SNDi_Work.alarms[i].id = 0;
}
}
void SND_SetupAlarm(s32 idx, OSTick tick, OSTick period, u32 id) {
void SND_SetupAlarm(s32 idx, OSTick tick, OSTick period, u32 id)
{
struct SNDAlarm *alarm = &SNDi_Work.alarms[idx];
if (alarm->enable) {
if (alarm->enable)
{
OS_CancelAlarm(&alarm->alarm);
alarm->enable = 0;
}
@ -27,13 +31,15 @@ void SND_SetupAlarm(s32 idx, OSTick tick, OSTick period, u32 id) {
alarm->id = (u8)id;
}
void SND_StartAlarm(s32 idx) {
void SND_StartAlarm(s32 idx)
{
OSTick tick;
OSTick period;
struct SNDAlarm *alarm = &SNDi_Work.alarms[idx];
if (alarm->enable != 0) {
if (alarm->enable != 0)
{
OS_CancelAlarm(&alarm->alarm);
alarm->enable = 0;
}
@ -44,27 +50,34 @@ void SND_StartAlarm(s32 idx) {
OS_CreateAlarm(&alarm->alarm);
if (period == 0) {
if (period == 0)
{
OS_SetAlarm(&alarm->alarm, tick, AlarmHandler, (void *)arg);
} else {
}
else
{
OS_SetPeriodicAlarm(&alarm->alarm, tick + OS_GetTick(), period, AlarmHandler, (void *)arg);
}
alarm->enable = 1;
}
void SND_StopAlarm(s32 idx) {
void SND_StopAlarm(s32 idx)
{
struct SNDAlarm *alarm = &SNDi_Work.alarms[idx];
if (alarm->enable != 0) {
if (alarm->enable != 0)
{
OS_CancelAlarm(&alarm->alarm);
alarm->id++;
alarm->enable = 0;
}
}
static void AlarmHandler(void *msg) {
while (PXI_SendWordByFifo(7, (u32)msg, 0) < 0) {
static void AlarmHandler(void *msg)
{
while (PXI_SendWordByFifo(7, (u32)msg, 0) < 0)
{
// nothing
}
}

View File

@ -1,13 +1,16 @@
#include "SND_bank.h"
#include "SND_main.h"
#include "SND_exChannel.h"
#include "SND_main.h"
#include "mmap.h"
static const struct SNDWaveData *GetWaveData(const struct SNDBankData *bankData, s32 waveArc, s32 wave);
static const struct SNDWaveData *GetWaveData(
const struct SNDBankData *bankData, s32 waveArc, s32 wave);
BOOL SND_ReadInstData(const struct SNDBankData *bankData, s32 program, s32 midiKey, struct SNDInstData *instData) {
BOOL SND_ReadInstData(
const struct SNDBankData *bankData, s32 program, s32 midiKey, struct SNDInstData *instData)
{
s32 i;
struct SNDDrumSet *drumSet;
struct SNDKeySplit *keySplit;
@ -16,10 +19,11 @@ BOOL SND_ReadInstData(const struct SNDBankData *bankData, s32 program, s32 midiK
if (program < 0)
return FALSE;
SNDi_LockMutex();
if (program >= bankData->instCount) {
if (program >= bankData->instCount)
{
SNDi_UnlockMutex();
return FALSE;
}
@ -27,60 +31,69 @@ BOOL SND_ReadInstData(const struct SNDBankData *bankData, s32 program, s32 midiK
off = bankData->instOffsets[program];
instData->type = SND_INST_OFFSET_TYPE(off);
switch (instData->type) {
case SND_INST_PCM:
case SND_INST_PSG:
case SND_INST_NOISE:
case SND_INST_DIRECTPCM:
case SND_INST_DUMMY:
instData->param = *SND_INST_OFFSET_NORMAL(bankData, off);
break;
case SND_INST_DRUM_TABLE:
drumSet = SND_INST_OFFSET_DRUMS(bankData, off);
switch (instData->type)
{
case SND_INST_PCM:
case SND_INST_PSG:
case SND_INST_NOISE:
case SND_INST_DIRECTPCM:
case SND_INST_DUMMY:
instData->param = *SND_INST_OFFSET_NORMAL(bankData, off);
break;
case SND_INST_DRUM_TABLE:
drumSet = SND_INST_OFFSET_DRUMS(bankData, off);
// seperate variables needed for matching
maxKey = drumSet->maxKey;
minKey = drumSet->minKey;
// seperate variables needed for matching
maxKey = drumSet->maxKey;
minKey = drumSet->minKey;
if (midiKey < minKey || midiKey > maxKey) {
SNDi_UnlockMutex();
return FALSE;
}
*instData = drumSet->instruments[midiKey - drumSet->minKey];
break;
case SND_INST_KEY_SPLIT:
i = 0;
keySplit = SND_INST_OFFSET_KEYSPL(bankData, off);
while (midiKey > keySplit->key[i]) {
i++;
if (i >= SND_INST_MAX_KEYSPLIT) {
if (midiKey < minKey || midiKey > maxKey)
{
SNDi_UnlockMutex();
return FALSE;
}
}
*instData = keySplit->instruments[i];
break;
case SND_INST_ILLEGAL:
default:
SNDi_UnlockMutex();
return FALSE;
*instData = drumSet->instruments[midiKey - drumSet->minKey];
break;
case SND_INST_KEY_SPLIT:
i = 0;
keySplit = SND_INST_OFFSET_KEYSPL(bankData, off);
while (midiKey > keySplit->key[i])
{
i++;
if (i >= SND_INST_MAX_KEYSPLIT)
{
SNDi_UnlockMutex();
return FALSE;
}
}
*instData = keySplit->instruments[i];
break;
case SND_INST_ILLEGAL:
default:
SNDi_UnlockMutex();
return FALSE;
}
SNDi_UnlockMutex();
return TRUE;
}
const struct SNDWaveData *SND_GetWaveDataAddress(const struct SNDWaveArc *waveArc, s32 wave) {
const struct SNDWaveData *SND_GetWaveDataAddress(const struct SNDWaveArc *waveArc, s32 wave)
{
SNDi_LockMutex();
const struct SNDWaveData *retval = (const struct SNDWaveData *)waveArc->waveOffsets[wave];
if (retval != NULL) {
if ((u32)retval < HW_MAIN_MEM) {
if (retval != NULL)
{
if ((u32)retval < HW_MAIN_MEM)
{
retval = (const struct SNDWaveData *)((u32)waveArc + (u32)retval);
}
} else {
}
else
{
retval = NULL;
}
@ -89,47 +102,66 @@ const struct SNDWaveData *SND_GetWaveDataAddress(const struct SNDWaveArc *waveAr
return retval;
}
BOOL SND_NoteOn(struct SNDExChannel *chn, s32 midiKey, s32 velocity, s32 length, const struct SNDBankData *bankData, const struct SNDInstData *instData) {
BOOL SND_NoteOn(struct SNDExChannel *chn,
s32 midiKey,
s32 velocity,
s32 length,
const struct SNDBankData *bankData,
const struct SNDInstData *instData)
{
const struct SNDWaveData *waveData;
u8 release;
BOOL success;
release = instData->param.envRelease;
if (release == 0xFF) {
if (release == 0xFF)
{
length = -1;
release = 0;
}
switch (instData->type) {
case SND_INST_PCM:
case SND_INST_DIRECTPCM:
if (instData->type == SND_INST_PCM) {
waveData = GetWaveData(bankData, instData->param.wave[1], instData->param.wave[0]);
} else {
waveData = (const struct SNDWaveData *)((instData->param.wave[1] << 16) | instData->param.wave[0]);
}
switch (instData->type)
{
case SND_INST_PCM:
case SND_INST_DIRECTPCM:
if (instData->type == SND_INST_PCM)
{
waveData = GetWaveData(bankData, instData->param.wave[1], instData->param.wave[0]);
}
else
{
waveData = (const struct SNDWaveData *)((instData->param.wave[1] << 16) |
instData->param.wave[0]);
}
if (waveData == NULL) {
if (waveData == NULL)
{
success = FALSE;
}
else
{
success =
SND_StartExChannelPcm(chn, &waveData->param, waveData->sampleData, length);
}
break;
case SND_INST_PSG:
success = SND_StartExChannelPsg(chn, instData->param.wave[0], length);
break;
case SND_INST_NOISE:
success = SND_StartExChannelNoise(chn, length);
break;
default:
success = FALSE;
} else {
success = SND_StartExChannelPcm(chn, &waveData->param, waveData->sampleData, length);
}
break;
case SND_INST_PSG:
success = SND_StartExChannelPsg(chn, instData->param.wave[0], length);
break;
case SND_INST_NOISE:
success = SND_StartExChannelNoise(chn, length);
break;
default:
success = FALSE;
break;
break;
}
if (success == FALSE) {
if (success == FALSE)
{
return FALSE;
} else {
}
else
{
chn->midiKey = (u8)midiKey;
chn->rootMidiKey = instData->param.rootKey;
chn->velocity = (u8)velocity;
@ -142,14 +174,21 @@ BOOL SND_NoteOn(struct SNDExChannel *chn, s32 midiKey, s32 velocity, s32 length,
}
}
static const struct SNDWaveData *GetWaveData(const struct SNDBankData *bankData, s32 waveArc, s32 wave) {
static const struct SNDWaveData *GetWaveData(
const struct SNDBankData *bankData, s32 waveArc, s32 wave)
{
const struct SNDWaveArc *arcPtr = bankData->waveArcLinks[waveArc].waveArc;
if (arcPtr == NULL) {
if (arcPtr == NULL)
{
return NULL;
} else if (wave < arcPtr->waveCount) {
}
else if (wave < arcPtr->waveCount)
{
return SND_GetWaveDataAddress(arcPtr, wave);
} else {
}
else
{
return NULL;
}
}

View File

@ -2,18 +2,24 @@
#include "registers.h"
enum SNDLoop {
SND_CAP_LOOP = 0, SND_CAP_ONESHOT = 1
enum SNDLoop
{
SND_CAP_LOOP = 0,
SND_CAP_ONESHOT = 1
};
void SND_SetupCapture(int idx, int format, void *captureData, int size, BOOL loop, int capCtrlSrc, int capCtrlDst) {
void SND_SetupCapture(
int idx, int format, void *captureData, int size, BOOL loop, int capCtrlSrc, int capCtrlDst)
{
int off = idx * 8;
reg_SNDCAPxCNT(idx) = (u8)((format << 3) | ((loop ? SND_CAP_LOOP : SND_CAP_ONESHOT) << 2) | (capCtrlSrc << 1) | capCtrlDst);
reg_SNDCAPxCNT(idx) = (u8)((format << 3) | ((loop ? SND_CAP_LOOP : SND_CAP_ONESHOT) << 2) |
(capCtrlSrc << 1) | capCtrlDst);
*(vu32 *)(0x4000510 + off) = (u32)captureData;
*(vu16 *)(0x4000514 + off) = (u16)size;
}
BOOL SND_IsCaptureActive(int idx) {
BOOL SND_IsCaptureActive(int idx)
{
return (reg_SNDCAPxCNT(idx) & 0x80) != 0;
}

View File

@ -1,7 +1,7 @@
#include "SND_channel.h"
#include "registers.h"
#include "SND_work.h"
#include "registers.h"
static int sMasterPan = -1;
@ -11,50 +11,67 @@ static int sSurroundDecay;
static int CalcSurroundDecay(int vol, int pan);
void SND_SetupChannelPcm(int chnIdx, const void *data, int format, int loop, int loopStart, int loopLength, int volume, int volumeDiv, int timer, int pan) {
void SND_SetupChannelPcm(int chnIdx,
const void *data,
int format,
int loop,
int loopStart,
int loopLength,
int volume,
int volumeDiv,
int timer,
int pan)
{
int off = chnIdx * 0x10;
sOrgPan[chnIdx] = (u8)pan;
if (sMasterPan >= 0)
pan = sMasterPan;
sOrgVolume[chnIdx] = (u8)volume;
if (sSurroundDecay > 0 && (1 << chnIdx) & 0xFFF5) {
if (sSurroundDecay > 0 && (1 << chnIdx) & 0xFFF5)
{
volume = CalcSurroundDecay(volume, pan);
}
reg_SOUNDoffCNT(off) = (u32)((format << 29) | (loop << 27) | (pan << 16) | (volumeDiv << 8) | (volume));
reg_SOUNDoffCNT(off) =
(u32)((format << 29) | (loop << 27) | (pan << 16) | (volumeDiv << 8) | (volume));
reg_SOUNDoffTMR(off) = (u16)(0x10000 - timer);
reg_SOUNDoffPNT(off) = (u16)loopStart;
reg_SOUNDoffLEN(off) = (u32)loopLength;
reg_SOUNDoffSAD(off) = (u32)data;
}
void SND_SetupChannelPsg(int chnIdx, int duty, int volume, int volumeDiv, int timer, int pan) {
void SND_SetupChannelPsg(int chnIdx, int duty, int volume, int volumeDiv, int timer, int pan)
{
int off = chnIdx * 0x10;
sOrgPan[chnIdx] = (u8)pan;
if (sMasterPan >= 0)
pan = sMasterPan;
sOrgVolume[chnIdx] = (u8)volume;
if (sSurroundDecay > 0 && (1 << chnIdx) & 0xFFF5) {
if (sSurroundDecay > 0 && (1 << chnIdx) & 0xFFF5)
{
volume = CalcSurroundDecay(volume, pan);
}
reg_SOUNDoffCNT(off) = (u32)(0x60000000 | (duty << 24) | (pan << 16) | (volumeDiv << 8) | volume);
reg_SOUNDoffCNT(off) =
(u32)(0x60000000 | (duty << 24) | (pan << 16) | (volumeDiv << 8) | volume);
reg_SOUNDoffTMR(off) = (u16)(0x10000 - timer);
}
void SND_SetupChannelNoise(int chnIdx, int volume, int volumeDiv, int timer, int pan) {
void SND_SetupChannelNoise(int chnIdx, int volume, int volumeDiv, int timer, int pan)
{
int off = chnIdx * 0x10;
sOrgPan[chnIdx] = (u8)pan;
if (sMasterPan >= 0)
pan = sMasterPan;
sOrgVolume[chnIdx] = (u8)volume;
if (sSurroundDecay > 0 && (1 << chnIdx) & 0xFFF5) {
if (sSurroundDecay > 0 && (1 << chnIdx) & 0xFFF5)
{
volume = CalcSurroundDecay(volume, pan);
}
@ -62,7 +79,8 @@ void SND_SetupChannelNoise(int chnIdx, int volume, int volumeDiv, int timer, int
reg_SOUNDoffTMR(off) = (u16)(0x10000 - timer);
}
void SND_StopChannel(int idx, int hold) {
void SND_StopChannel(int idx, int hold)
{
vu32 *reg = &reg_SOUNDxCNT(idx);
u32 v = *reg;
@ -77,10 +95,12 @@ void SND_StopChannel(int idx, int hold) {
*reg = v;
}
void SND_SetChannelVolume(int chnIdx, int vol, int volDiv) {
void SND_SetChannelVolume(int chnIdx, int vol, int volDiv)
{
sOrgVolume[chnIdx] = (u8)vol;
if (sSurroundDecay > 0 && (1 << chnIdx) & 0xFFF5) {
if (sSurroundDecay > 0 && (1 << chnIdx) & 0xFFF5)
{
int pan = reg_SOUNDxCNT_PAN(chnIdx);
vol = CalcSurroundDecay(vol, pan);
}
@ -88,64 +108,85 @@ void SND_SetChannelVolume(int chnIdx, int vol, int volDiv) {
reg_SOUNDxCNT_VOLS(chnIdx) = (u16)((volDiv << 8) | vol);
}
void SND_SetChannelTimer(int chnIdx, int timer) {
void SND_SetChannelTimer(int chnIdx, int timer)
{
reg_SOUNDxTMR(chnIdx) = (u16)(0x10000 - timer);
}
void SND_SetChannelPan(int chnIdx, int pan) {
void SND_SetChannelPan(int chnIdx, int pan)
{
sOrgPan[chnIdx] = (u8)pan;
if (sMasterPan >= 0) {
if (sMasterPan >= 0)
{
pan = sMasterPan;
}
reg_SOUNDxCNT_PAN(chnIdx) = (u8)pan;
if (sSurroundDecay > 0 && (1 << chnIdx) & 0xFFF5) {
if (sSurroundDecay > 0 && (1 << chnIdx) & 0xFFF5)
{
reg_SOUNDxCNT_VOL(chnIdx) = (u8)CalcSurroundDecay(sOrgVolume[chnIdx], pan);
}
}
BOOL SND_IsChannelActive(int chnIdx) {
BOOL SND_IsChannelActive(int chnIdx)
{
return (reg_SOUNDxCNT_STAT(chnIdx) & 0x80) != 0;
}
void SND_SetMasterPan(int pan) {
void SND_SetMasterPan(int pan)
{
sMasterPan = pan;
if (pan >= 0) {
for (int i = 0; i < SND_CHANNEL_COUNT; i++) {
if (pan >= 0)
{
for (int i = 0; i < SND_CHANNEL_COUNT; i++)
{
reg_SOUNDxCNT_PAN(i) = (u8)pan;
}
} else {
for (int i = 0; i < SND_CHANNEL_COUNT; i++) {
}
else
{
for (int i = 0; i < SND_CHANNEL_COUNT; i++)
{
reg_SOUNDxCNT_PAN(i) = sOrgPan[i];
}
}
}
u32 SND_GetChannelControl(int chnIdx) {
u32 SND_GetChannelControl(int chnIdx)
{
return reg_SOUNDxCNT(chnIdx);
}
void SNDi_SetSurroundDecay(int decay) {
void SNDi_SetSurroundDecay(int decay)
{
sSurroundDecay = decay;
for (int i = 0; i < SND_CHANNEL_COUNT; i++) {
for (int i = 0; i < SND_CHANNEL_COUNT; i++)
{
// do not process channel 1+3 (capture playback channels)
if ((1 << i) & 0xFFF5) {
if ((1 << i) & 0xFFF5)
{
int pan = reg_SOUNDxCNT_PAN(i);
reg_SOUNDxCNT_VOL(i) = (u8)CalcSurroundDecay(sOrgVolume[i], pan);
}
}
}
static int CalcSurroundDecay(int vol, int pan) {
if (pan < 24) {
static int CalcSurroundDecay(int vol, int pan)
{
if (pan < 24)
{
return vol * (sSurroundDecay * (pan + 40) + ((0x7FFF - sSurroundDecay) << 6)) >> 21;
} else if (pan <= 104) {
}
else if (pan <= 104)
{
return vol;
} else {
}
else
{
return vol * (-sSurroundDecay * (pan - 40) + ((sSurroundDecay + 0x7FFF) << 6)) >> 21;
}
}

View File

@ -1,15 +1,15 @@
#include "SND_command.h"
#include "registers.h"
#include "mmap.h"
#include "registers.h"
#include "MI_memory.h"
#include "PXI_fifo.h"
#include "OS_message.h"
#include "OS_system.h"
#include "SND_channel.h"
#include "PXI_fifo.h"
#include "SND_alarm.h"
#include "SND_capture.h"
#include "SND_channel.h"
#include "SND_exChannel.h"
#include "SND_global.h"
#include "SND_main.h"
@ -29,164 +29,167 @@ static void SetChannelVolume(u32 channelMask, int vol, int shift);
static void SetChannelPan(u32 channelMask, int pan);
static void ReadDriverInfo(struct SNDDriverInfo *driverInfo);
void SND_CommandInit(void) {
void SND_CommandInit(void)
{
OS_InitMessageQueue(&sMsgQueue, sMsgArray, SND_MSG_ARRAY_SIZE);
InitPXI();
SNDi_SharedWork = NULL;
}
void SND_CommandProc(void) {
void SND_CommandProc(void)
{
struct SNDCommand cmd;
struct SNDCommand *cmd_ptr;
OSMessage msg;
while (OS_ReceiveMessage(&sMsgQueue, &msg, 0)) {
while (OS_ReceiveMessage(&sMsgQueue, &msg, 0))
{
// casting it directly below doesn't appear to match
cmd_ptr = (struct SNDCommand *)msg;
while (cmd_ptr) {
while (cmd_ptr)
{
cmd = *cmd_ptr;
switch (cmd.id) {
case SND_CMD_START_SEQ:
SND_StartSeq((int)cmd.arg[0], (const void *)cmd.arg[1], cmd.arg[2], (struct SNDBankData *)cmd.arg[3]);
break;
case SND_CMD_STOP_SEQ:
SND_StopSeq((int)cmd.arg[0]);
break;
case SND_CMD_PREPARE_SEQ:
SND_PrepareSeq((int)cmd.arg[0], (const void *)cmd.arg[1], cmd.arg[2], (struct SNDBankData *)cmd.arg[3]);
break;
case SND_CMD_START_PREPARED_SEQ:
SND_StartPreparedSeq((int)cmd.arg[0]);
break;
case SND_CMD_PAUSE_SEQ:
SND_PauseSeq((int)cmd.arg[0], (BOOL)cmd.arg[1]);
break;
case SND_CMD_SKIP_SEQ:
SND_SkipSeq((int)cmd.arg[0], cmd.arg[1]);
break;
case SND_CMD_PLAYER_PARAM:
SNDi_SetPlayerParam((int)cmd.arg[0], cmd.arg[1], cmd.arg[2], (int)cmd.arg[3]);
break;
case SND_CMD_TRACK_PARAM:
SNDi_SetTrackParam((int)cmd.arg[0] & 0xFFFFFF, cmd.arg[1], cmd.arg[2], cmd.arg[3], (u8)(cmd.arg[0] >> 24));
break;
case SND_CMD_MUTE_TRACK:
SND_SetTrackMute((int)cmd.arg[0], cmd.arg[1], (BOOL)cmd.arg[2]);
break;
case SND_CMD_ALLOCATABLE_CHANNEL:
SND_SetTrackAllocatableChannel((int)cmd.arg[0], cmd.arg[1], cmd.arg[2]);
break;
case SND_CMD_PLAYER_LOCAL_VAR:
SND_SetPlayerLocalVariable((int)cmd.arg[0], (int)cmd.arg[1], (s16)cmd.arg[2]);
break;
case SND_CMD_PLAYER_GLOBAL_VAR:
SND_SetPlayerGlobalVariable((int)cmd.arg[0], (s16)cmd.arg[1]);
break;
case SND_CMD_START_TIMER:
StartTimer(cmd.arg[0], cmd.arg[1], cmd.arg[2], (int)cmd.arg[3]);
break;
case SND_CMD_STOP_TIMER:
StopTimer(cmd.arg[0], cmd.arg[1], cmd.arg[2], (int)cmd.arg[3]);
break;
case SND_CMD_SETUP_CAPTURE:
SND_SetupCapture(
(int)(cmd.arg[2] >> 31u) & 1,
(int)(cmd.arg[2] >> 30u) & 1,
(void *)cmd.arg[0],
(int)cmd.arg[1],
(BOOL)(cmd.arg[2] >> 29u) & 1,
(int)(cmd.arg[2] >> 28u) & 1,
(int)(cmd.arg[2] >> 27u) & 1
);
break;
case SND_CMD_SETUP_ALARM:
SND_SetupAlarm(
(int)cmd.arg[0],
cmd.arg[1],
cmd.arg[2],
cmd.arg[3]
);
break;
case SND_CMD_CHANNEL_TIMER:
SetChannelTimer(cmd.arg[0], (int)cmd.arg[1]);
break;
case SND_CMD_CHANNEL_VOLUME:
SetChannelVolume(cmd.arg[0], (int)cmd.arg[1], (int)cmd.arg[2]);
break;
case SND_CMD_CHANNEL_PAN:
SetChannelPan(cmd.arg[0], (int)cmd.arg[1]);
break;
case SND_CMD_SETUP_CHANNEL_PCM:
SND_SetupChannelPcm(
(int)cmd.arg[0] & 0xFFFF,
(void *)(cmd.arg[1] & 0x7FFFFFFu),
(int)(cmd.arg[3] >> 24u) & 0x3,
(int)(cmd.arg[3] >> 26u) & 0x3,
(int)cmd.arg[3] & 0xFFFF,
(int)cmd.arg[2] & 0x3FFFFF,
(int)(cmd.arg[2] >> 24u) & 0x7F,
(int)(cmd.arg[2] >> 22u) & 0x3,
(int)(cmd.arg[0] >> 16u) & 0xFFFF,
(int)(cmd.arg[3] >> 16u) & 0x7F
);
break;
case SND_CMD_SETUP_CHANNEL_PSG:
SND_SetupChannelPsg(
(int)cmd.arg[0],
(int)cmd.arg[3],
(int)cmd.arg[1] & 0x7F,
(int)(cmd.arg[1] >> 8u) & 0x3,
(int)(cmd.arg[2] >> 8u) & 0xFFFF,
(int)cmd.arg[2] & 0x7F
);
break;
case SND_CMD_SETUP_CHANNEL_NOISE:
SND_SetupChannelNoise(
(int)cmd.arg[0],
(int)cmd.arg[1] & 0x7F,
(int)(cmd.arg[1] >> 8u) & 0x3,
(int)(cmd.arg[2] >> 8u) & 0xFFFF,
(int)cmd.arg[2] & 0x7F
);
break;
case SND_CMD_SURROUND_DECAY:
SNDi_SetSurroundDecay((int)cmd.arg[0]);
break;
case SND_CMD_MASTER_VOLUME:
SND_SetMasterVolume((int)cmd.arg[0]);
break;
case SND_CMD_MASTER_PAN:
SND_SetMasterPan((int)cmd.arg[0]);
break;
case SND_CMD_OUTPUT_SELECTOR:
SND_SetOutputSelector((int)cmd.arg[0], (int)cmd.arg[1], (int)cmd.arg[2], (int)cmd.arg[3]);
break;
case SND_CMD_LOCK_CHANNEL:
SND_LockChannel(cmd.arg[0], cmd.arg[1]);
break;
case SND_CMD_UNLOCK_CHANNEL:
SND_UnlockChannel(cmd.arg[0], cmd.arg[1]);
break;
case SND_CMD_STOP_UNLOCKED_CHANNEL:
SND_StopUnlockedChannel(cmd.arg[0], cmd.arg[1]);
break;
case SND_CMD_INVALIDATE_SEQ:
SND_InvalidateSeq((void *)cmd.arg[0], (void *)cmd.arg[1]);
break;
case SND_CMD_INVALIDATE_BANK:
SND_InvalidateBank((void *)cmd.arg[0], (void *)cmd.arg[1]);
break;
case SND_CMD_INVALIDATE_WAVE:
SND_InvalidateWave((void *)cmd.arg[0], (void *)cmd.arg[1]);
break;
case SND_CMD_SET_SHARED_WORK:
SNDi_SharedWork = (struct SNDSharedWork *)cmd.arg[0];
break;
case SND_CMD_READ_DRIVER_INFO:
ReadDriverInfo((struct SNDDriverInfo *)cmd.arg[0]);
break;
switch (cmd.id)
{
case SND_CMD_START_SEQ:
SND_StartSeq((int)cmd.arg[0],
(const void *)cmd.arg[1],
cmd.arg[2],
(struct SNDBankData *)cmd.arg[3]);
break;
case SND_CMD_STOP_SEQ:
SND_StopSeq((int)cmd.arg[0]);
break;
case SND_CMD_PREPARE_SEQ:
SND_PrepareSeq((int)cmd.arg[0],
(const void *)cmd.arg[1],
cmd.arg[2],
(struct SNDBankData *)cmd.arg[3]);
break;
case SND_CMD_START_PREPARED_SEQ:
SND_StartPreparedSeq((int)cmd.arg[0]);
break;
case SND_CMD_PAUSE_SEQ:
SND_PauseSeq((int)cmd.arg[0], (BOOL)cmd.arg[1]);
break;
case SND_CMD_SKIP_SEQ:
SND_SkipSeq((int)cmd.arg[0], cmd.arg[1]);
break;
case SND_CMD_PLAYER_PARAM:
SNDi_SetPlayerParam((int)cmd.arg[0], cmd.arg[1], cmd.arg[2], (int)cmd.arg[3]);
break;
case SND_CMD_TRACK_PARAM:
SNDi_SetTrackParam((int)cmd.arg[0] & 0xFFFFFF,
cmd.arg[1],
cmd.arg[2],
cmd.arg[3],
(u8)(cmd.arg[0] >> 24));
break;
case SND_CMD_MUTE_TRACK:
SND_SetTrackMute((int)cmd.arg[0], cmd.arg[1], (BOOL)cmd.arg[2]);
break;
case SND_CMD_ALLOCATABLE_CHANNEL:
SND_SetTrackAllocatableChannel((int)cmd.arg[0], cmd.arg[1], cmd.arg[2]);
break;
case SND_CMD_PLAYER_LOCAL_VAR:
SND_SetPlayerLocalVariable((int)cmd.arg[0], (int)cmd.arg[1], (s16)cmd.arg[2]);
break;
case SND_CMD_PLAYER_GLOBAL_VAR:
SND_SetPlayerGlobalVariable((int)cmd.arg[0], (s16)cmd.arg[1]);
break;
case SND_CMD_START_TIMER:
StartTimer(cmd.arg[0], cmd.arg[1], cmd.arg[2], (int)cmd.arg[3]);
break;
case SND_CMD_STOP_TIMER:
StopTimer(cmd.arg[0], cmd.arg[1], cmd.arg[2], (int)cmd.arg[3]);
break;
case SND_CMD_SETUP_CAPTURE:
SND_SetupCapture((int)(cmd.arg[2] >> 31u) & 1,
(int)(cmd.arg[2] >> 30u) & 1,
(void *)cmd.arg[0],
(int)cmd.arg[1],
(BOOL)(cmd.arg[2] >> 29u) & 1,
(int)(cmd.arg[2] >> 28u) & 1,
(int)(cmd.arg[2] >> 27u) & 1);
break;
case SND_CMD_SETUP_ALARM:
SND_SetupAlarm((int)cmd.arg[0], cmd.arg[1], cmd.arg[2], cmd.arg[3]);
break;
case SND_CMD_CHANNEL_TIMER:
SetChannelTimer(cmd.arg[0], (int)cmd.arg[1]);
break;
case SND_CMD_CHANNEL_VOLUME:
SetChannelVolume(cmd.arg[0], (int)cmd.arg[1], (int)cmd.arg[2]);
break;
case SND_CMD_CHANNEL_PAN:
SetChannelPan(cmd.arg[0], (int)cmd.arg[1]);
break;
case SND_CMD_SETUP_CHANNEL_PCM:
SND_SetupChannelPcm((int)cmd.arg[0] & 0xFFFF,
(void *)(cmd.arg[1] & 0x7FFFFFFu),
(int)(cmd.arg[3] >> 24u) & 0x3,
(int)(cmd.arg[3] >> 26u) & 0x3,
(int)cmd.arg[3] & 0xFFFF,
(int)cmd.arg[2] & 0x3FFFFF,
(int)(cmd.arg[2] >> 24u) & 0x7F,
(int)(cmd.arg[2] >> 22u) & 0x3,
(int)(cmd.arg[0] >> 16u) & 0xFFFF,
(int)(cmd.arg[3] >> 16u) & 0x7F);
break;
case SND_CMD_SETUP_CHANNEL_PSG:
SND_SetupChannelPsg((int)cmd.arg[0],
(int)cmd.arg[3],
(int)cmd.arg[1] & 0x7F,
(int)(cmd.arg[1] >> 8u) & 0x3,
(int)(cmd.arg[2] >> 8u) & 0xFFFF,
(int)cmd.arg[2] & 0x7F);
break;
case SND_CMD_SETUP_CHANNEL_NOISE:
SND_SetupChannelNoise((int)cmd.arg[0],
(int)cmd.arg[1] & 0x7F,
(int)(cmd.arg[1] >> 8u) & 0x3,
(int)(cmd.arg[2] >> 8u) & 0xFFFF,
(int)cmd.arg[2] & 0x7F);
break;
case SND_CMD_SURROUND_DECAY:
SNDi_SetSurroundDecay((int)cmd.arg[0]);
break;
case SND_CMD_MASTER_VOLUME:
SND_SetMasterVolume((int)cmd.arg[0]);
break;
case SND_CMD_MASTER_PAN:
SND_SetMasterPan((int)cmd.arg[0]);
break;
case SND_CMD_OUTPUT_SELECTOR:
SND_SetOutputSelector(
(int)cmd.arg[0], (int)cmd.arg[1], (int)cmd.arg[2], (int)cmd.arg[3]);
break;
case SND_CMD_LOCK_CHANNEL:
SND_LockChannel(cmd.arg[0], cmd.arg[1]);
break;
case SND_CMD_UNLOCK_CHANNEL:
SND_UnlockChannel(cmd.arg[0], cmd.arg[1]);
break;
case SND_CMD_STOP_UNLOCKED_CHANNEL:
SND_StopUnlockedChannel(cmd.arg[0], cmd.arg[1]);
break;
case SND_CMD_INVALIDATE_SEQ:
SND_InvalidateSeq((void *)cmd.arg[0], (void *)cmd.arg[1]);
break;
case SND_CMD_INVALIDATE_BANK:
SND_InvalidateBank((void *)cmd.arg[0], (void *)cmd.arg[1]);
break;
case SND_CMD_INVALIDATE_WAVE:
SND_InvalidateWave((void *)cmd.arg[0], (void *)cmd.arg[1]);
break;
case SND_CMD_SET_SHARED_WORK:
SNDi_SharedWork = (struct SNDSharedWork *)cmd.arg[0];
break;
case SND_CMD_READ_DRIVER_INFO:
ReadDriverInfo((struct SNDDriverInfo *)cmd.arg[0]);
break;
} // end switch
cmd_ptr = cmd.llNext;
@ -196,15 +199,19 @@ void SND_CommandProc(void) {
} // end loop over receive message
}
static void PxiFifoCallback(PXIFifoTag tag, u32 data, BOOL error) {
static void PxiFifoCallback(PXIFifoTag tag, u32 data, BOOL error)
{
(void)tag;
(void)error;
OSIntrMode intrMode = OS_DisableInterrupts();
if (data >= HW_MAIN_MEM) {
if (data >= HW_MAIN_MEM)
{
(void)OS_SendMessage(&sMsgQueue, (OSMessage)data, 0);
} else {
}
else
{
if (data == 0)
SND_SendWakeupMessage();
}
@ -212,52 +219,68 @@ static void PxiFifoCallback(PXIFifoTag tag, u32 data, BOOL error) {
(void)OS_RestoreInterrupts(intrMode);
}
static void InitPXI(void) {
static void InitPXI(void)
{
PXI_SetFifoRecvCallback(PXI_FIFO_TAG_SOUND, PxiFifoCallback);
}
static void SetChannelTimer(u32 channelMask, int timer) {
for (int i = 0; i < SND_CHANNEL_COUNT && channelMask != 0; i++, channelMask >>= 1) {
static void SetChannelTimer(u32 channelMask, int timer)
{
for (int i = 0; i < SND_CHANNEL_COUNT && channelMask != 0; i++, channelMask >>= 1)
{
if (channelMask & 1)
SND_SetChannelTimer(i, timer);
}
}
static void SetChannelVolume(u32 channelMask, int vol, int shift) {
for (int i = 0; i < SND_CHANNEL_COUNT && channelMask != 0; i++, channelMask >>= 1) {
static void SetChannelVolume(u32 channelMask, int vol, int shift)
{
for (int i = 0; i < SND_CHANNEL_COUNT && channelMask != 0; i++, channelMask >>= 1)
{
if (channelMask & 1)
SND_SetChannelVolume(i, vol, shift);
}
}
static void SetChannelPan(u32 channelMask, int pan) {
for (int i = 0; i < SND_CHANNEL_COUNT && channelMask != 0; i++, channelMask >>= 1) {
static void SetChannelPan(u32 channelMask, int pan)
{
for (int i = 0; i < SND_CHANNEL_COUNT && channelMask != 0; i++, channelMask >>= 1)
{
if (channelMask & 1)
SND_SetChannelPan(i, pan);
}
}
static void StartTimer(u32 channelMask, u32 captureMask, u32 alarmMask, s32 unused) {
static void StartTimer(u32 channelMask, u32 captureMask, u32 alarmMask, s32 unused)
{
(void)unused;
OSIntrMode intrMode = OS_DisableInterrupts();
for (int i = 0; i < SND_CHANNEL_COUNT && channelMask != 0; i++, channelMask >>= 1) {
for (int i = 0; i < SND_CHANNEL_COUNT && channelMask != 0; i++, channelMask >>= 1)
{
if (channelMask & 1)
reg_SOUNDxCNT_STAT(i) |= 0x80;
}
if (captureMask & 1) {
if (captureMask & 2) {
if (captureMask & 1)
{
if (captureMask & 2)
{
*(vu16 *)&reg_SNDCAPxCNT(0) |= 0x8080;
} else {
}
else
{
reg_SNDCAPxCNT(0) |= 0x80;
}
} else if (captureMask & 2) {
}
else if (captureMask & 2)
{
reg_SNDCAPxCNT(1) |= 0x80;
}
for (int i = 0; i < SND_ALARM_COUNT && alarmMask != 0; i++, alarmMask >>= 1) {
for (int i = 0; i < SND_ALARM_COUNT && alarmMask != 0; i++, alarmMask >>= 1)
{
if (alarmMask & 1)
SND_StartAlarm(i);
}
@ -266,15 +289,18 @@ static void StartTimer(u32 channelMask, u32 captureMask, u32 alarmMask, s32 unus
SND_UpdateSharedWork();
}
static void StopTimer(u32 channelMask, u32 captureMask, u32 alarmMask, s32 hold) {
static void StopTimer(u32 channelMask, u32 captureMask, u32 alarmMask, s32 hold)
{
OSIntrMode intrMode = OS_DisableInterrupts();
for (int i = 0; i < SND_ALARM_COUNT && alarmMask != 0; i++, alarmMask >>= 1) {
for (int i = 0; i < SND_ALARM_COUNT && alarmMask != 0; i++, alarmMask >>= 1)
{
if (alarmMask & 1)
SND_StopAlarm(i);
}
for (int i = 0; i < SND_CHANNEL_COUNT && channelMask != 0; i++, channelMask >>= 1) {
for (int i = 0; i < SND_CHANNEL_COUNT && channelMask != 0; i++, channelMask >>= 1)
{
if (channelMask & 1)
SND_StopChannel(i, hold);
}
@ -288,12 +314,14 @@ static void StopTimer(u32 channelMask, u32 captureMask, u32 alarmMask, s32 hold)
SND_UpdateSharedWork();
}
static void ReadDriverInfo(struct SNDDriverInfo *driverInfo) {
static void ReadDriverInfo(struct SNDDriverInfo *driverInfo)
{
MI_CpuCopy32(&SNDi_Work, driverInfo, sizeof(SNDi_Work));
driverInfo->workPtr = &SNDi_Work;
for (int i = 0; i < SND_CHANNEL_COUNT; i++) {
for (int i = 0; i < SND_CHANNEL_COUNT; i++)
{
driverInfo->channelControls[i] = SND_GetChannelControl(i);
}

View File

@ -2,8 +2,8 @@
#include "SND_channel.h"
#include "SND_main.h"
#include "SND_work.h"
#include "SND_util.h"
#include "SND_work.h"
#include "registers.h"
@ -21,15 +21,18 @@ static int ExChannelSweepUpdate(struct SNDExChannel *chn, BOOL step);
static int ExChannelLfoUpdate(struct SNDExChannel *chn, BOOL step);
static void ExChannelStart(struct SNDExChannel *chn, int length);
static int ExChannelVolumeCmp(struct SNDExChannel *chn_a, struct SNDExChannel *chn_b);
static void ExChannelSetup(struct SNDExChannel *, SNDExChannelCallback callback, void *callbackUserData, int priority);
static void ExChannelSetup(
struct SNDExChannel *, SNDExChannelCallback callback, void *callbackUserData, int priority);
void SND_ExChannelInit(void) {
void SND_ExChannelInit(void)
{
struct SNDExChannel *chn;
s32 i;
for (i = 0; i < SND_CHANNEL_COUNT; i++) {
for (i = 0; i < SND_CHANNEL_COUNT; i++)
{
chn = &SNDi_Work.channels[i];
chn->id = (u8)i;
chn->flags.syncFlag = 0;
chn->flags.active = FALSE;
@ -39,11 +42,13 @@ void SND_ExChannelInit(void) {
sWeakLockedChannelMask = 0;
}
void SND_UpdateExChannel(void) {
void SND_UpdateExChannel(void)
{
struct SNDExChannel *chn;
s32 i;
for (i = 0; i < SND_CHANNEL_COUNT; i++) {
for (i = 0; i < SND_CHANNEL_COUNT; i++)
{
chn = &SNDi_Work.channels[i];
if (chn->flags.syncFlag == 0)
@ -51,69 +56,69 @@ void SND_UpdateExChannel(void) {
if (chn->flags.syncFlag & SND_CHN_SYNC_STOP)
SND_StopChannel(i, 0);
if (chn->flags.syncFlag & SND_CHN_SYNC_START) {
switch (chn->type) {
case SND_CHN_TYPE_PCM:
SND_SetupChannelPcm(
i,
chn->waveDataPtr,
chn->waveParam.format,
chn->waveParam.loopEnabled ? 1 : 2,
(s32)chn->waveParam.loopStart,
(s32)chn->waveParam.loopLength,
chn->volume & 0xFF,
chn->volume >> 8,
chn->timer,
chn->pan
);
break;
case SND_CHN_TYPE_PSG:
SND_SetupChannelPsg(
i,
chn->dutyCycle,
chn->volume & 0xFF,
chn->volume >> 8,
chn->timer,
chn->pan
);
break;
case SND_CHN_TYPE_NOISE:
SND_SetupChannelNoise(
i,
chn->volume & 0xFF,
chn->volume >> 8,
chn->timer,
chn->pan
);
break;
if (chn->flags.syncFlag & SND_CHN_SYNC_START)
{
switch (chn->type)
{
case SND_CHN_TYPE_PCM:
SND_SetupChannelPcm(i,
chn->waveDataPtr,
chn->waveParam.format,
chn->waveParam.loopEnabled ? 1 : 2,
(s32)chn->waveParam.loopStart,
(s32)chn->waveParam.loopLength,
chn->volume & 0xFF,
chn->volume >> 8,
chn->timer,
chn->pan);
break;
case SND_CHN_TYPE_PSG:
SND_SetupChannelPsg(i,
chn->dutyCycle,
chn->volume & 0xFF,
chn->volume >> 8,
chn->timer,
chn->pan);
break;
case SND_CHN_TYPE_NOISE:
SND_SetupChannelNoise(
i, chn->volume & 0xFF, chn->volume >> 8, chn->timer, chn->pan);
break;
}
} else {
if (chn->flags.syncFlag & SND_CHN_SYNC_TIMER) {
}
else
{
if (chn->flags.syncFlag & SND_CHN_SYNC_TIMER)
{
SND_SetChannelTimer(i, chn->timer);
}
if (chn->flags.syncFlag & SND_CHN_SYNC_VOLUME) {
if (chn->flags.syncFlag & SND_CHN_SYNC_VOLUME)
{
SND_SetChannelVolume(i, chn->volume & 0xFF, chn->volume >> 8);
}
if (chn->flags.syncFlag & SND_CHN_SYNC_PAN) {
if (chn->flags.syncFlag & SND_CHN_SYNC_PAN)
{
SND_SetChannelPan(i, chn->pan);
}
}
}
for (i = 0; i < SND_CHANNEL_COUNT; i++) {
for (i = 0; i < SND_CHANNEL_COUNT; i++)
{
chn = &SNDi_Work.channels[i];
if (!chn->flags.syncFlag)
continue;
if (chn->flags.syncFlag & SND_CHN_SYNC_START)
reg_SOUNDxCNT_STAT(i) |= 0x80;
chn->flags.syncFlag = 0;
}
}
void SND_ExChannelMain(BOOL step) {
void SND_ExChannelMain(BOOL step)
{
struct SNDExChannel *chn;
s32 i;
s32 vol;
@ -122,7 +127,8 @@ void SND_ExChannelMain(BOOL step) {
s32 lfo;
u16 newTimer;
for (i = 0; i < SND_CHANNEL_COUNT; i++) {
for (i = 0; i < SND_CHANNEL_COUNT; i++)
{
vol = 0;
pitch = 0;
pan = 0;
@ -130,11 +136,14 @@ void SND_ExChannelMain(BOOL step) {
if (!chn->flags.active)
continue;
if (chn->flags.start) {
if (chn->flags.start)
{
chn->flags.syncFlag |= SND_CHN_SYNC_START;
chn->flags.start = FALSE;
} else if (!SND_IsChannelActive(i)) {
}
else if (!SND_IsChannelActive(i))
{
if (chn->callback)
chn->callback(chn, 1, chn->callbackUserData);
else
@ -143,7 +152,7 @@ void SND_ExChannelMain(BOOL step) {
chn->flags.active = FALSE;
continue;
}
vol += SNDi_DecibelSquareTable[chn->velocity];
pitch += (chn->midiKey - chn->rootMidiKey) * 0x40;
@ -156,26 +165,29 @@ void SND_ExChannelMain(BOOL step) {
lfo = ExChannelLfoUpdate(chn, step);
switch (chn->lfo.param.target) {
case SND_LFO_VOLUME:
if (vol > -0x8000)
vol += lfo;
break;
case SND_LFO_PAN:
pan += lfo;
break;
case SND_LFO_PITCH:
pitch += lfo;
break;
switch (chn->lfo.param.target)
{
case SND_LFO_VOLUME:
if (vol > -0x8000)
vol += lfo;
break;
case SND_LFO_PAN:
pan += lfo;
break;
case SND_LFO_PITCH:
pitch += lfo;
break;
}
pan += chn->initPan;
if (chn->panRange != 127) {
if (chn->panRange != 127)
{
pan = (pan * chn->panRange + 0x40) >> 7;
}
pan += chn->userPan;
if (chn->envStatus == SND_ENV_RELEASE && vol <= -723) {
if (chn->envStatus == SND_ENV_RELEASE && vol <= -723)
{
chn->flags.syncFlag = SND_CHN_SYNC_STOP;
if (chn->callback)
chn->callback(chn, 1, chn->callbackUserData);
@ -183,28 +195,33 @@ void SND_ExChannelMain(BOOL step) {
chn->priority = 0;
chn->volume = 0;
chn->flags.active = 0;
} else {
}
else
{
vol = SND_CalcChannelVolume(vol);
newTimer = SND_CalcTimer(chn->waveParam.timer, pitch);
if (chn->type == SND_CHN_TYPE_PSG)
newTimer &= 0xFFFC;
pan += 0x40;
if (pan < 0)
pan = 0;
else if (pan > 127)
pan = 127;
if (vol != chn->volume) {
if (vol != chn->volume)
{
chn->volume = (u16)vol;
chn->flags.syncFlag |= SND_CHN_SYNC_VOLUME;
}
if (newTimer != chn->timer) {
if (newTimer != chn->timer)
{
chn->timer = (u16)newTimer;
chn->flags.syncFlag |= SND_CHN_SYNC_TIMER;
}
if (pan != chn->pan) {
if (pan != chn->pan)
{
chn->pan = (u8)pan;
chn->flags.syncFlag |= SND_CHN_SYNC_PAN;
}
@ -212,7 +229,9 @@ void SND_ExChannelMain(BOOL step) {
}
}
BOOL SND_StartExChannelPcm(struct SNDExChannel *chn, const struct SNDWaveParam *wave, const void *data, s32 length) {
BOOL SND_StartExChannelPcm(
struct SNDExChannel *chn, const struct SNDWaveParam *wave, const void *data, s32 length)
{
chn->type = SND_CHN_TYPE_PCM;
chn->waveParam = *wave;
chn->waveDataPtr = data;
@ -220,12 +239,18 @@ BOOL SND_StartExChannelPcm(struct SNDExChannel *chn, const struct SNDWaveParam *
return TRUE;
}
BOOL SND_StartExChannelPsg(struct SNDExChannel *chn, s32 duty, s32 length) {
if (chn->id < 8) {
BOOL SND_StartExChannelPsg(struct SNDExChannel *chn, s32 duty, s32 length)
{
if (chn->id < 8)
{
return FALSE;
} else if (chn->id > 13) {
}
else if (chn->id > 13)
{
return FALSE;
} else {
}
else
{
chn->type = SND_CHN_TYPE_PSG;
chn->dutyCycle = duty;
chn->waveParam.timer = 8006;
@ -234,12 +259,18 @@ BOOL SND_StartExChannelPsg(struct SNDExChannel *chn, s32 duty, s32 length) {
}
}
BOOL SND_StartExChannelNoise(struct SNDExChannel *chn, s32 length) {
if (chn->id < 14) {
BOOL SND_StartExChannelNoise(struct SNDExChannel *chn, s32 length)
{
if (chn->id < 14)
{
return FALSE;
} else if (chn->id > 15) {
}
else if (chn->id > 15)
{
return FALSE;
} else {
}
else
{
chn->type = SND_CHN_TYPE_NOISE;
chn->waveParam.timer = 8006;
ExChannelStart(chn, length);
@ -247,63 +278,75 @@ BOOL SND_StartExChannelNoise(struct SNDExChannel *chn, s32 length) {
}
}
s32 SND_UpdateExChannelEnvelope(struct SNDExChannel *chn, BOOL step) {
s32 SND_UpdateExChannelEnvelope(struct SNDExChannel *chn, BOOL step)
{
s32 sustain;
if (step) {
switch (chn->envStatus) {
case SND_ENV_ATTACK:
chn->envAttenuation = -((-chn->envAttenuation * chn->envAttack) >> 8);
if (chn->envAttenuation == 0)
chn->envStatus = SND_ENV_DECAY;
break;
case SND_ENV_DECAY:
sustain = SNDi_DecibelSquareTable[chn->envSustain] << 7;
chn->envAttenuation -= chn->envDecay;
if (chn->envAttenuation <= sustain) {
chn->envAttenuation = sustain;
chn->envStatus = SND_ENV_SUSTAIN;
}
break;
case SND_ENV_SUSTAIN:
break;
case SND_ENV_RELEASE:
chn->envAttenuation -= chn->envRelease;
break;
if (step)
{
switch (chn->envStatus)
{
case SND_ENV_ATTACK:
chn->envAttenuation = -((-chn->envAttenuation * chn->envAttack) >> 8);
if (chn->envAttenuation == 0)
chn->envStatus = SND_ENV_DECAY;
break;
case SND_ENV_DECAY:
sustain = SNDi_DecibelSquareTable[chn->envSustain] << 7;
chn->envAttenuation -= chn->envDecay;
if (chn->envAttenuation <= sustain)
{
chn->envAttenuation = sustain;
chn->envStatus = SND_ENV_SUSTAIN;
}
break;
case SND_ENV_SUSTAIN:
break;
case SND_ENV_RELEASE:
chn->envAttenuation -= chn->envRelease;
break;
}
}
return chn->envAttenuation >> 7;
}
void SND_SetExChannelAttack(struct SNDExChannel *chn, s32 attack) {
void SND_SetExChannelAttack(struct SNDExChannel *chn, s32 attack)
{
if (attack < 109)
chn->envAttack = (u8)(255 - attack);
else
chn->envAttack = sAttackCoeffTable[127 - attack];
}
void SND_SetExChannelDecay(struct SNDExChannel *chn, s32 decay) {
void SND_SetExChannelDecay(struct SNDExChannel *chn, s32 decay)
{
chn->envDecay = CalcDecayCoeff(decay);
}
void SND_SetExChannelSustain(struct SNDExChannel *chn, s32 sustain) {
void SND_SetExChannelSustain(struct SNDExChannel *chn, s32 sustain)
{
chn->envSustain = (u8)sustain;
}
void SND_SetExChannelRelease(struct SNDExChannel *chn, s32 release) {
void SND_SetExChannelRelease(struct SNDExChannel *chn, s32 release)
{
chn->envRelease = CalcDecayCoeff(release);
}
void SND_ReleaseExChannel(struct SNDExChannel *chn) {
void SND_ReleaseExChannel(struct SNDExChannel *chn)
{
chn->envStatus = SND_ENV_RELEASE;
}
BOOL SND_IsExChannelActive(struct SNDExChannel *chn) {
BOOL SND_IsExChannelActive(struct SNDExChannel *chn)
{
return chn->flags.active;
}
struct SNDExChannel *SND_AllocExChannel(u32 channelMask, int priority, u32 flags, SNDExChannelCallback callback, void *callbackUserData) {
struct SNDExChannel *SND_AllocExChannel(
u32 channelMask, int priority, u32 flags, SNDExChannelCallback callback, void *callbackUserData)
{
struct SNDExChannel *chnPrev;
int i;
struct SNDExChannel *chn;
@ -315,20 +358,23 @@ struct SNDExChannel *SND_AllocExChannel(u32 channelMask, int priority, u32 flags
chnPrev = NULL;
for (i = 0; i < SND_CHANNEL_COUNT; i++) {
for (i = 0; i < SND_CHANNEL_COUNT; i++)
{
channelCandidate = sChannelAllocationOrder[i];
if (channelMask & (1 << channelCandidate)) {
if (channelMask & (1 << channelCandidate))
{
chn = &SNDi_Work.channels[channelCandidate];
if (chnPrev == NULL) {
if (chnPrev == NULL)
{
chnPrev = chn;
continue;
}
if (chn->priority > chnPrev->priority)
continue;
if (chn->priority != chnPrev->priority || ExChannelVolumeCmp(chnPrev, chn) < 0)
chnPrev = chn;
}
@ -336,35 +382,39 @@ struct SNDExChannel *SND_AllocExChannel(u32 channelMask, int priority, u32 flags
if (chnPrev == NULL)
return NULL;
if (priority < chnPrev->priority)
return NULL;
if (chnPrev->callback)
chnPrev->callback(chnPrev, 0, chnPrev->callbackUserData);
chnPrev->flags.syncFlag = 2;
chnPrev->flags.active = 0;
ExChannelSetup(chnPrev, callback, callbackUserData, priority);
return chnPrev;
}
void SND_FreeExChannel(struct SNDExChannel *chn) {
if (chn) {
void SND_FreeExChannel(struct SNDExChannel *chn)
{
if (chn)
{
chn->callback = NULL;
chn->callbackUserData = NULL;
}
}
void SND_StopUnlockedChannel(u32 channelMask, u32 weak) {
void SND_StopUnlockedChannel(u32 channelMask, u32 weak)
{
(void)weak;
struct SNDExChannel *chn;
for (int i = 0; i < SND_CHANNEL_COUNT && channelMask != 0; i++, channelMask >>= 1) {
for (int i = 0; i < SND_CHANNEL_COUNT && channelMask != 0; i++, channelMask >>= 1)
{
if ((channelMask & 1) == 0)
continue;
chn = &SNDi_Work.channels[i];
if (sLockedChannelMask & (1 << i))
@ -381,12 +431,14 @@ void SND_StopUnlockedChannel(u32 channelMask, u32 weak) {
}
}
void SND_LockChannel(u32 channelMask, u32 weak) {
void SND_LockChannel(u32 channelMask, u32 weak)
{
struct SNDExChannel *chn;
u32 j = channelMask;
int i = 0;
for (; i < SND_CHANNEL_COUNT && j != 0; i++, j >>= 1) {
for (; i < SND_CHANNEL_COUNT && j != 0; i++, j >>= 1)
{
if ((j & 1) == 0)
continue;
@ -405,41 +457,57 @@ void SND_LockChannel(u32 channelMask, u32 weak) {
chn->flags.active = 0;
}
if (weak & 1) {
if (weak & 1)
{
sWeakLockedChannelMask |= channelMask;
} else {
}
else
{
sLockedChannelMask |= channelMask;
}
}
void SND_UnlockChannel(u32 channelMask, u32 weak) {
if (weak & 1) {
void SND_UnlockChannel(u32 channelMask, u32 weak)
{
if (weak & 1)
{
sWeakLockedChannelMask &= ~channelMask;
} else {
}
else
{
sLockedChannelMask &= ~channelMask;
}
}
u32 SND_GetLockedChannel(u32 weak) {
if (weak & 1) {
u32 SND_GetLockedChannel(u32 weak)
{
if (weak & 1)
{
return sWeakLockedChannelMask;
} else {
}
else
{
return sLockedChannelMask;
}
}
void SND_InvalidateWave(const void *start, const void *end) {
for (u8 i = 0; i < SND_CHANNEL_COUNT; i++) {
void SND_InvalidateWave(const void *start, const void *end)
{
for (u8 i = 0; i < SND_CHANNEL_COUNT; i++)
{
struct SNDExChannel *chn = &SNDi_Work.channels[i];
if (chn->flags.active && chn->type == 0 && start <= chn->waveDataPtr && chn->waveDataPtr <= end) {
if (chn->flags.active && chn->type == 0 && start <= chn->waveDataPtr &&
chn->waveDataPtr <= end)
{
chn->flags.start = FALSE;
SND_StopChannel(i, 0);
}
}
}
void SND_InitLfoParam(struct SNDLfoParam *lfoParam) {
void SND_InitLfoParam(struct SNDLfoParam *lfoParam)
{
lfoParam->target = SND_LFO_PITCH;
lfoParam->depth = 0;
lfoParam->range = 1;
@ -447,19 +515,25 @@ void SND_InitLfoParam(struct SNDLfoParam *lfoParam) {
lfoParam->delay = 0;
}
void SND_StartLfo(struct SNDLfo *lfo) {
void SND_StartLfo(struct SNDLfo *lfo)
{
lfo->counter = 0;
lfo->delayCounter = 0;
}
void SND_UpdateLfo(struct SNDLfo *lfo) {
if (lfo->delayCounter < lfo->param.delay) {
void SND_UpdateLfo(struct SNDLfo *lfo)
{
if (lfo->delayCounter < lfo->param.delay)
{
lfo->delayCounter++;
} else {
}
else
{
u32 tmp = lfo->counter;
tmp += lfo->param.speed << 6;
tmp >>= 8;
while (tmp >= 0x80) {
while (tmp >= 0x80)
{
tmp -= 0x80;
}
lfo->counter += lfo->param.speed << 6;
@ -468,17 +542,24 @@ void SND_UpdateLfo(struct SNDLfo *lfo) {
}
}
int SND_GetLfoValue(struct SNDLfo *lfo) {
if (lfo->param.depth == 0) {
int SND_GetLfoValue(struct SNDLfo *lfo)
{
if (lfo->param.depth == 0)
{
return 0;
} else if (lfo->delayCounter < lfo->param.delay) {
}
else if (lfo->delayCounter < lfo->param.delay)
{
return 0;
} else {
}
else
{
return SND_SinIdx((s32)((u32)lfo->counter >> 8)) * lfo->param.depth * lfo->param.range;
}
}
static u16 CalcDecayCoeff(int vol) {
static u16 CalcDecayCoeff(int vol)
{
if (vol == 127)
return 0xFFFF;
else if (vol == 126)
@ -489,7 +570,9 @@ static u16 CalcDecayCoeff(int vol) {
return (u16)(0x1E00 / (126 - vol));
}
static void ExChannelSetup(struct SNDExChannel *chn, SNDExChannelCallback callback, void *callbackUserData, int priority) {
static void ExChannelSetup(
struct SNDExChannel *chn, SNDExChannelCallback callback, void *callbackUserData, int priority)
{
chn->channelLLNext = NULL;
chn->callback = callback;
chn->callbackUserData = callbackUserData;
@ -518,7 +601,8 @@ static void ExChannelSetup(struct SNDExChannel *chn, SNDExChannelCallback callba
SND_InitLfoParam(&chn->lfo.param);
}
static void ExChannelStart(struct SNDExChannel *chn, int length) {
static void ExChannelStart(struct SNDExChannel *chn, int length)
{
chn->envAttenuation = -92544;
chn->envStatus = 0;
chn->length = length;
@ -527,7 +611,8 @@ static void ExChannelStart(struct SNDExChannel *chn, int length) {
chn->flags.active = TRUE;
}
static int ExChannelVolumeCmp(struct SNDExChannel *chn_a, struct SNDExChannel *chn_b) {
static int ExChannelVolumeCmp(struct SNDExChannel *chn_a, struct SNDExChannel *chn_b)
{
int vol_a = chn_a->volume & 0xFF;
int vol_b = chn_b->volume & 0xFF;
@ -537,7 +622,8 @@ static int ExChannelVolumeCmp(struct SNDExChannel *chn_a, struct SNDExChannel *c
vol_a >>= sSampleDataShiftTable[chn_a->volume >> 8];
vol_b >>= sSampleDataShiftTable[chn_b->volume >> 8];
if (vol_a != vol_b) {
if (vol_a != vol_b)
{
if (vol_a < vol_b)
return 1;
else
@ -546,14 +632,20 @@ static int ExChannelVolumeCmp(struct SNDExChannel *chn_a, struct SNDExChannel *c
return 0;
}
static int ExChannelSweepUpdate(struct SNDExChannel *chn, BOOL step) {
static int ExChannelSweepUpdate(struct SNDExChannel *chn, BOOL step)
{
s64 result;
if (chn->sweepPitch == 0) {
if (chn->sweepPitch == 0)
{
result = 0;
} else if (chn->sweepCounter >= chn->sweepLength) {
}
else if (chn->sweepCounter >= chn->sweepLength)
{
result = 0;
} else {
}
else
{
result = (s64)chn->sweepPitch * (chn->sweepLength - chn->sweepCounter) / chn->sweepLength;
if (step && chn->flags.autoSweep)
@ -563,25 +655,29 @@ static int ExChannelSweepUpdate(struct SNDExChannel *chn, BOOL step) {
return (int)result;
}
static int ExChannelLfoUpdate(struct SNDExChannel *chn, BOOL step) {
static int ExChannelLfoUpdate(struct SNDExChannel *chn, BOOL step)
{
s64 result = SND_GetLfoValue(&chn->lfo);
if (result != 0) {
switch (chn->lfo.param.target) {
case SND_LFO_VOLUME:
result *= 60;
break;
case SND_LFO_PITCH:
result <<= 6;
break;
case SND_LFO_PAN:
result <<= 6;
break;
if (result != 0)
{
switch (chn->lfo.param.target)
{
case SND_LFO_VOLUME:
result *= 60;
break;
case SND_LFO_PITCH:
result <<= 6;
break;
case SND_LFO_PAN:
result <<= 6;
break;
}
result >>= 14;
}
if (step) {
if (step)
{
SND_UpdateLfo(&chn->lfo);
}

View File

@ -8,18 +8,22 @@
#include "registers.h"
#include "syscall.h"
void SND_Enable(void) {
void SND_Enable(void)
{
reg_SOUNDCNT_MIX |= 0x80;
}
void SND_Disable(void) {
void SND_Disable(void)
{
reg_SOUNDCNT_MIX &= ~0x80;
}
void SND_Shutdown(void) {
void SND_Shutdown(void)
{
SND_Disable();
for (int i = 0; i < SND_CHANNEL_COUNT; i++) {
for (int i = 0; i < SND_CHANNEL_COUNT; i++)
{
SND_StopChannel(i, 1);
}
@ -27,7 +31,8 @@ void SND_Shutdown(void) {
reg_SNDCAPxCNT(1) = 0;
}
void SND_BeginSleep(void) {
void SND_BeginSleep(void)
{
SND_Disable();
SVC_SoundBiasReset(0x80);
OS_SpinWait(0x40000);
@ -35,19 +40,24 @@ void SND_BeginSleep(void) {
reg_POWCNT2 &= ~1;
}
void SND_EndSleep(void) {
reg_POWCNT2 |= 1; // enable speakers
void SND_EndSleep(void)
{
reg_POWCNT2 |= 1; // enable speakers
PMi_SetControl(1);
SVC_SoundBiasSet(0x100);
OS_SpinWait(0x7AB80); // what does this wait for and how long does it wait?
SND_Enable();
}
void SND_SetMasterVolume(int vol) {
void SND_SetMasterVolume(int vol)
{
reg_SOUNDCNT_VOL = (u8)vol;
}
void SND_SetOutputSelector(int leftOutputFrom, int rightOutputFrom, int outputCh1ToMixer, int outputCh3ToMixer) {
void SND_SetOutputSelector(
int leftOutputFrom, int rightOutputFrom, int outputCh1ToMixer, int outputCh3ToMixer)
{
int masterEnable = (reg_SOUNDCNT_MIX & 0x80) ? 1 : 0;
reg_SOUNDCNT_MIX = (u8)((masterEnable << 7) | (outputCh3ToMixer << 5) | (outputCh1ToMixer << 4) | (rightOutputFrom << 2) | (leftOutputFrom));
reg_SOUNDCNT_MIX = (u8)((masterEnable << 7) | (outputCh3ToMixer << 5) |
(outputCh1ToMixer << 4) | (rightOutputFrom << 2) | (leftOutputFrom));
}

View File

@ -12,8 +12,8 @@
#include "SND_work.h"
#include "OS_alarm.h"
#include "OS_thread.h"
#include "OS_message.h"
#include "OS_thread.h"
#include "OS_tick.h"
static void FUN_037fc330(void *);
@ -26,57 +26,74 @@ OSMessageQueue sMessageQueue;
OSMessage sMessageArray[8];
u32 sInitialized = 0;
void SND_Init(u32 priority) {
if (sInitialized == 0) {
void SND_Init(u32 priority)
{
if (sInitialized == 0)
{
sInitialized = 1;
SND_CommandInit();
SND_CreateThread(priority);
}
}
void SND_CreateThread(u32 priority) {
OS_CreateThread(&sThread, SndThread, NULL, &sThreadStack[sizeof(sThreadStack)], sizeof(sThreadStack), priority);
void SND_CreateThread(u32 priority)
{
OS_CreateThread(&sThread,
SndThread,
NULL,
&sThreadStack[sizeof(sThreadStack)],
sizeof(sThreadStack),
priority);
OS_WakeupThreadDirect(&sThread);
}
void SND_InitIntervalTimer(void) {
void SND_InitIntervalTimer(void)
{
OS_InitMessageQueue(&sMessageQueue, sMessageArray, 8);
OS_CreateAlarm(&sAlarm);
}
void SND_StartIntervalTimer(void) {
void SND_StartIntervalTimer(void)
{
OSTick tick = OS_GetTick();
OS_SetPeriodicAlarm(&sAlarm, tick + 0x10000, 2728, FUN_037fc330, NULL);
}
void SND_StopIntervalTimer(void) {
void SND_StopIntervalTimer(void)
{
OS_CancelAlarm(&sAlarm);
}
u32 SND_WaitForIntervalTimer(void) {
u32 SND_WaitForIntervalTimer(void)
{
OSMessage result;
(void)OS_ReceiveMessage(&sMessageQueue, &result, 1);
return (u32)result;
}
void SND_SendWakeupMessage(void) {
void SND_SendWakeupMessage(void)
{
(void)OS_SendMessage(&sMessageQueue, (OSMessage)2, 0);
}
void SNDi_LockMutex(void) {
void SNDi_LockMutex(void)
{
// nothing
}
void SNDi_UnlockMutex(void) {
void SNDi_UnlockMutex(void)
{
// nothing
}
static void FUN_037fc330(void *arg) {
static void FUN_037fc330(void *arg)
{
(void)arg;
(void)OS_SendMessage(&sMessageQueue, (OSMessage)1, 0);
}
static void SndThread(void *arg) {
static void SndThread(void *arg)
{
(void)arg;
SND_InitIntervalTimer();
@ -88,18 +105,20 @@ static void SndThread(void *arg) {
SND_SetMasterVolume(0x7F);
SND_StartIntervalTimer();
while (1) {
while (1)
{
BOOL update = FALSE;
u32 result = SND_WaitForIntervalTimer();
switch (result) {
case 2:
update = FALSE;
break;
case 1:
update = TRUE;
break;
switch (result)
{
case 2:
update = FALSE;
break;
case 1:
update = TRUE;
break;
}
SND_UpdateExChannel();

File diff suppressed because it is too large Load Diff

View File

@ -5,16 +5,19 @@
// TODO remove this extern once the static const definition of it is here
extern s8 sLfoSinTable[0x21];
u16 SND_CalcTimer(int timer, int pitch) {
u16 SND_CalcTimer(int timer, int pitch)
{
int octave = 0;
int pitch_normalized = -pitch;
while (pitch_normalized < 0) {
while (pitch_normalized < 0)
{
octave--;
pitch_normalized += 768;
}
while (pitch_normalized >= 768) {
while (pitch_normalized >= 768)
{
octave++;
pitch_normalized -= 768;
}
@ -23,19 +26,24 @@ u16 SND_CalcTimer(int timer, int pitch) {
result += 0x10000;
result *= timer;
int shift = octave - 16;
if (shift <= 0) {
if (shift <= 0)
{
shift = -shift;
result >>= shift;
} else if (shift < 32) {
}
else if (shift < 32)
{
// what ???
u64 tmp = result & ~0uLL << (32 - shift);
if (tmp != 0)
return 0xFFFF;
result <<= shift;
} else {
}
else
{
return 0xFFFF;
}
@ -47,7 +55,8 @@ u16 SND_CalcTimer(int timer, int pitch) {
return (u16)result;
}
u16 SND_CalcChannelVolume(int value) {
u16 SND_CalcChannelVolume(int value)
{
if (value < SND_VOL_DB_MIN)
value = SND_VOL_DB_MIN;
else if (value > 0)
@ -68,21 +77,30 @@ u16 SND_CalcChannelVolume(int value) {
return (u16)(result | (div << 8));
}
s8 SND_SinIdx(int x) {
s8 SND_SinIdx(int x)
{
// BUG: UB for out of range values
if (x < 0x20) {
if (x < 0x20)
{
return sLfoSinTable[x];
} else if (x < 0x40) {
}
else if (x < 0x40)
{
return sLfoSinTable[0x40 - x];
} else if (x < 0x60) {
}
else if (x < 0x60)
{
return (s8)(-sLfoSinTable[x - 0x40]);
} else {
}
else
{
return (s8)(-sLfoSinTable[0x20 - (x - 0x60)]);
}
}
u16 SND_CalcRandom(void) {
u16 SND_CalcRandom(void)
{
static u32 state = 0x12345678;
// values from "Numerical Recipes"

View File

@ -1,28 +1,32 @@
#include "SND_work.h"
#include "SND_capture.h"
#include "SND_channel.h"
#include "SND_exChannel.h"
#include "SND_capture.h"
struct SNDWork SNDi_Work;
struct SNDSharedWork *SNDi_SharedWork;
void SND_SetPlayerLocalVariable(int player, int var, s16 value) {
void SND_SetPlayerLocalVariable(int player, int var, s16 value)
{
SNDi_SharedWork->players[player].localVars[var] = value;
}
void SND_SetPlayerGlobalVariable(int var, s16 value) {
void SND_SetPlayerGlobalVariable(int var, s16 value)
{
SNDi_SharedWork->globalVars[var] = value;
}
void SND_UpdateSharedWork(void) {
void SND_UpdateSharedWork(void)
{
u16 channelActiveMask = 0;
u16 channelCaptureMask = 0;
if (SNDi_SharedWork == NULL)
return;
for (s32 i = 0; i < SND_CHANNEL_COUNT; i++) {
for (s32 i = 0; i < SND_CHANNEL_COUNT; i++)
{
if (SND_IsChannelActive(i))
channelActiveMask |= 1 << i;
}

View File

@ -13,18 +13,19 @@
#ifndef POKEDIAMOND_SND_ALARM_SHARED_H
#define POKEDIAMOND_SND_ALARM_SHARED_H
#include "nitro/OS_tick_shared.h"
#include "nitro/OS_alarm_shared.h"
#include "nitro/OS_tick_shared.h"
struct SNDAlarm {
u8 enable; // 0x00
u8 id; // 0x01
u16 unk_2; // 0x02
OSTick tick; // 0x04
OSTick period; // 0x0C
OSAlarm alarm; // 0x14
}; // size = 0x40
struct SNDAlarm
{
u8 enable; // 0x00
u8 id; // 0x01
u16 unk_2; // 0x02
OSTick tick; // 0x04
OSTick period; // 0x0C
OSAlarm alarm; // 0x14
}; // size = 0x40
#define SND_ALARM_COUNT 8
#endif //POKEDIAMOND_SND_ALARM_SHARED_H
#endif // POKEDIAMOND_SND_ALARM_SHARED_H

View File

@ -8,14 +8,14 @@
#define SND_INST_MAX_KEYSPLIT 8
#define SND_INST_ILLEGAL 0
#define SND_INST_PCM 1
#define SND_INST_PSG 2
#define SND_INST_NOISE 3
#define SND_INST_DIRECTPCM 4
#define SND_INST_DUMMY 5
#define SND_INST_ILLEGAL 0
#define SND_INST_PCM 1
#define SND_INST_PSG 2
#define SND_INST_NOISE 3
#define SND_INST_DIRECTPCM 4
#define SND_INST_DUMMY 5
#define SND_INST_DRUM_TABLE 16
#define SND_INST_KEY_SPLIT 17
#define SND_INST_KEY_SPLIT 17
#define SND_BANK_MAX_WAVEARC 4
@ -24,65 +24,74 @@
#define SND_INST_OFFSET_DRUMS(bank, off) ((struct SNDDrumSet *)((u8 *)bank + (u32)(off >> 8)))
#define SND_INST_OFFSET_KEYSPL(bank, off) ((struct SNDKeySplit *)((u8 *)bank + (u32)(off >> 8)))
struct SNDInstParam {
u16 wave[2]; // 0x0
u8 rootKey; // 0x4
u8 envAttack; // 0x5
u8 envDecay; // 0x6
u8 envSustain; // 0x7
u8 envRelease; // 0x8
u8 pan; // 0x9
}; // size = 0xA
struct SNDInstParam
{
u16 wave[2]; // 0x0
u8 rootKey; // 0x4
u8 envAttack; // 0x5
u8 envDecay; // 0x6
u8 envSustain; // 0x7
u8 envRelease; // 0x8
u8 pan; // 0x9
}; // size = 0xA
struct SNDInstData {
u8 type; // 0x0
u8 unk_1; // 0x1
struct SNDInstParam param; // 0x2
}; // size = 0xC
struct SNDInstData
{
u8 type; // 0x0
u8 unk_1; // 0x1
struct SNDInstParam param; // 0x2
}; // size = 0xC
struct SNDKeySplit {
u8 key[SND_INST_MAX_KEYSPLIT]; // 0x0
struct SNDInstData instruments[]; // 0x8
}; // size = 0x8
struct SNDKeySplit
{
u8 key[SND_INST_MAX_KEYSPLIT]; // 0x0
struct SNDInstData instruments[]; // 0x8
}; // size = 0x8
struct SNDDrumSet {
struct SNDDrumSet
{
u8 minKey;
u8 maxKey;
struct SNDInstData instruments[];
}; // size = 0x2
}; // size = 0x2
struct SNDWaveArc;
struct SNDWaveArcLink {
struct SNDWaveArc *waveArc; // 0x0
struct SNDWaveArcLink *waveArcLLnext; // 0x4
}; // size = 0x8
struct SNDWaveArcLink
{
struct SNDWaveArc *waveArc; // 0x0
struct SNDWaveArcLink *waveArcLLnext; // 0x4
}; // size = 0x8
struct SNDBankData {
struct SNDBinaryFileHeader fileHeader; // 0x00
struct SNDBinaryBlockHeader blockHeader; // 0x10
struct SNDWaveArcLink waveArcLinks[SND_BANK_MAX_WAVEARC]; // 0x18
u32 instCount; // 0x38
u32 instOffsets[]; // 0x3C
}; // size = 0x40
struct SNDBankData
{
struct SNDBinaryFileHeader fileHeader; // 0x00
struct SNDBinaryBlockHeader blockHeader; // 0x10
struct SNDWaveArcLink waveArcLinks[SND_BANK_MAX_WAVEARC]; // 0x18
u32 instCount; // 0x38
u32 instOffsets[]; // 0x3C
}; // size = 0x40
struct SNDWaveArc {
struct SNDBinaryFileHeader fileHeader; // 0x00
struct SNDBinaryBlockHeader blockHeader; // 0x10
struct SNDWaveArcLink *waveArcLLHead; // 0x18
u8 unk_1C[28]; // 0x1C
u32 waveCount; // 0x38
u32 waveOffsets[]; // 0x3C
}; // size = 0x3C
struct SNDWaveArc
{
struct SNDBinaryFileHeader fileHeader; // 0x00
struct SNDBinaryBlockHeader blockHeader; // 0x10
struct SNDWaveArcLink *waveArcLLHead; // 0x18
u8 unk_1C[28]; // 0x1C
u32 waveCount; // 0x38
u32 waveOffsets[]; // 0x3C
}; // size = 0x3C
struct SNDInstPos {
u32 program; // 0x0
u32 index; // 0x4
}; // size = 0x8
struct SNDInstPos
{
u32 program; // 0x0
u32 index; // 0x4
}; // size = 0x8
struct SNDWaveData {
struct SNDWaveParam param; // 0x0
u8 sampleData[]; // 0xC
}; // size = 0xC
struct SNDWaveData
{
struct SNDWaveParam param; // 0x0
u8 sampleData[]; // 0xC
}; // size = 0xC
#endif //GUARD_SND_BANK_SHARED_H
#endif // GUARD_SND_BANK_SHARED_H

View File

@ -6,49 +6,50 @@
#define SND_CMD_COUNT 256
#define SND_CMD_ARG_MAX 4
#define SND_CMD_FLAG_NOBLOCK 0x0
#define SND_CMD_FLAG_BLOCK 0x1
#define SND_CMD_FLAG_IMMEDIATE 0x2
#define SND_CMD_FLAG_NOBLOCK 0x0
#define SND_CMD_FLAG_BLOCK 0x1
#define SND_CMD_FLAG_IMMEDIATE 0x2
#define SND_CMD_START_SEQ 0x00
#define SND_CMD_STOP_SEQ 0x01
#define SND_CMD_PREPARE_SEQ 0x02
#define SND_CMD_START_PREPARED_SEQ 0x03
#define SND_CMD_PAUSE_SEQ 0x04
#define SND_CMD_SKIP_SEQ 0x05
#define SND_CMD_PLAYER_PARAM 0x06
#define SND_CMD_TRACK_PARAM 0x07
#define SND_CMD_MUTE_TRACK 0x08
#define SND_CMD_ALLOCATABLE_CHANNEL 0x09
#define SND_CMD_PLAYER_LOCAL_VAR 0x0A
#define SND_CMD_PLAYER_GLOBAL_VAR 0x0B
#define SND_CMD_START_TIMER 0x0C
#define SND_CMD_STOP_TIMER 0x0D
#define SND_CMD_SETUP_CHANNEL_PCM 0x0E
#define SND_CMD_SETUP_CHANNEL_PSG 0x0F
#define SND_CMD_SETUP_CHANNEL_NOISE 0x10
#define SND_CMD_SETUP_CAPTURE 0x11
#define SND_CMD_SETUP_ALARM 0x12
#define SND_CMD_CHANNEL_TIMER 0x13
#define SND_CMD_CHANNEL_VOLUME 0x14
#define SND_CMD_CHANNEL_PAN 0x15
#define SND_CMD_SURROUND_DECAY 0x16
#define SND_CMD_MASTER_VOLUME 0x17
#define SND_CMD_MASTER_PAN 0x18
#define SND_CMD_OUTPUT_SELECTOR 0x19
#define SND_CMD_LOCK_CHANNEL 0x1A
#define SND_CMD_UNLOCK_CHANNEL 0x1B
#define SND_CMD_STOP_UNLOCKED_CHANNEL 0x1C
#define SND_CMD_SET_SHARED_WORK 0x1D
#define SND_CMD_INVALIDATE_SEQ 0x1E
#define SND_CMD_INVALIDATE_BANK 0x1F
#define SND_CMD_INVALIDATE_WAVE 0x20
#define SND_CMD_READ_DRIVER_INFO 0x21
#define SND_CMD_START_SEQ 0x00
#define SND_CMD_STOP_SEQ 0x01
#define SND_CMD_PREPARE_SEQ 0x02
#define SND_CMD_START_PREPARED_SEQ 0x03
#define SND_CMD_PAUSE_SEQ 0x04
#define SND_CMD_SKIP_SEQ 0x05
#define SND_CMD_PLAYER_PARAM 0x06
#define SND_CMD_TRACK_PARAM 0x07
#define SND_CMD_MUTE_TRACK 0x08
#define SND_CMD_ALLOCATABLE_CHANNEL 0x09
#define SND_CMD_PLAYER_LOCAL_VAR 0x0A
#define SND_CMD_PLAYER_GLOBAL_VAR 0x0B
#define SND_CMD_START_TIMER 0x0C
#define SND_CMD_STOP_TIMER 0x0D
#define SND_CMD_SETUP_CHANNEL_PCM 0x0E
#define SND_CMD_SETUP_CHANNEL_PSG 0x0F
#define SND_CMD_SETUP_CHANNEL_NOISE 0x10
#define SND_CMD_SETUP_CAPTURE 0x11
#define SND_CMD_SETUP_ALARM 0x12
#define SND_CMD_CHANNEL_TIMER 0x13
#define SND_CMD_CHANNEL_VOLUME 0x14
#define SND_CMD_CHANNEL_PAN 0x15
#define SND_CMD_SURROUND_DECAY 0x16
#define SND_CMD_MASTER_VOLUME 0x17
#define SND_CMD_MASTER_PAN 0x18
#define SND_CMD_OUTPUT_SELECTOR 0x19
#define SND_CMD_LOCK_CHANNEL 0x1A
#define SND_CMD_UNLOCK_CHANNEL 0x1B
#define SND_CMD_STOP_UNLOCKED_CHANNEL 0x1C
#define SND_CMD_SET_SHARED_WORK 0x1D
#define SND_CMD_INVALIDATE_SEQ 0x1E
#define SND_CMD_INVALIDATE_BANK 0x1F
#define SND_CMD_INVALIDATE_WAVE 0x20
#define SND_CMD_READ_DRIVER_INFO 0x21
struct SNDCommand {
struct SNDCommand *llNext; // 0x0
s32 id; // 0x4
u32 arg[SND_CMD_ARG_MAX]; // 0x8
}; // size = 0x18
struct SNDCommand
{
struct SNDCommand *llNext; // 0x0
s32 id; // 0x4
u32 arg[SND_CMD_ARG_MAX]; // 0x8
}; // size = 0x18
#endif //GUARD_SND_COMMAND_SHARED_H
#endif // GUARD_SND_COMMAND_SHARED_H

View File

@ -22,87 +22,93 @@
#define SND_LFO_VOLUME 1
#define SND_LFO_PAN 2
struct SNDWaveParam {
u8 format; // 0x0
struct SNDWaveParam
{
u8 format; // 0x0
u8 loopEnabled; // 0x1
u16 samplerate; // 0x2
u16 timer; // 0x4
u16 loopStart; // 0x6
u16 timer; // 0x4
u16 loopStart; // 0x6
u32 loopLength; // 0x8
}; // size = 0xC
struct SNDLfoParam {
u8 target; // 0x0
u8 speed; // 0x1
u8 depth; // 0x2
u8 range; // 0x3
u16 delay; // 0x4
struct SNDLfoParam
{
u8 target; // 0x0
u8 speed; // 0x1
u8 depth; // 0x2
u8 range; // 0x3
u16 delay; // 0x4
}; // size = 0x6
struct SNDLfo {
struct SNDLfoParam param; // 0x0
u16 delayCounter; // 0x6
u16 counter; // 0x8
struct SNDLfo
{
struct SNDLfoParam param; // 0x0
u16 delayCounter; // 0x6
u16 counter; // 0x8
}; // size = 0xA
struct SNDExChannel;
typedef void (*SNDExChannelCallback)(struct SNDExChannel *chn, int status, void *userData);
struct SNDExChannel {
u8 id; // 0x00
u8 type; // 0x01
u8 envStatus; // 0x02
struct SNDExChannel
{
u8 id; // 0x00
u8 type; // 0x01
u8 envStatus; // 0x02
struct {
struct
{
u8 active : 1;
u8 start : 1;
u8 autoSweep : 1;
u8 syncFlag : 5;
} flags; // 0x03
} flags; // 0x03
u8 panRange; // 0x04
u8 rootMidiKey; // 0x05
s16 userDecay2; // 0x06
u8 panRange; // 0x04
u8 rootMidiKey; // 0x05
s16 userDecay2; // 0x06
u8 midiKey; // 0x08
u8 velocity; // 0x09
s8 initPan; // 0x0A
s8 userPan; // 0x0B
u8 midiKey; // 0x08
u8 velocity; // 0x09
s8 initPan; // 0x0A
s8 userPan; // 0x0B
s16 userDecay; // 0x0C
s16 userPitch; // 0x0E
s16 userDecay; // 0x0C
s16 userPitch; // 0x0E
s32 envAttenuation; // 0x10
s32 sweepCounter; // 0x14
s32 sweepLength; // 0x18
s32 sweepCounter; // 0x14
s32 sweepLength; // 0x18
u8 envAttack; // 0x1C
u8 envSustain; // 0x1D
u16 envDecay; // 0x1E
u16 envRelease; // 0x20
u8 priority; // 0x22
u8 pan; // 0x23
u16 volume; // 0x24
u16 timer; // 0x26
u8 envAttack; // 0x1C
u8 envSustain; // 0x1D
u16 envDecay; // 0x1E
u16 envRelease; // 0x20
u8 priority; // 0x22
u8 pan; // 0x23
u16 volume; // 0x24
u16 timer; // 0x26
struct SNDLfo lfo; // 0x28
struct SNDLfo lfo; // 0x28
s16 sweepPitch; // 0x32
s16 sweepPitch; // 0x32
s32 length; // 0x34
s32 length; // 0x34
struct SNDWaveParam waveParam; // 0x38
struct SNDWaveParam waveParam; // 0x38
union {
union
{
const void *waveDataPtr;
s32 dutyCycle;
}; // 0x44
}; // 0x44
SNDExChannelCallback callback; // 0x48
void *callbackUserData; // 0x4C
struct SNDExChannel *channelLLNext; // 0x50
}; // size = 0x54
}; // size = 0x54
#endif //GUARD_SND_EXCHANNEL_SHARED_H
#endif // GUARD_SND_EXCHANNEL_SHARED_H

View File

@ -15,18 +15,20 @@
#include "nitro/types.h"
struct SNDBinaryFileHeader {
s8 signature[4]; // 0x0
u16 byteOrder; // 0x4
u16 version; // 0x6
u32 fileSize; // 0x8
u16 headerSize; // 0xC
u16 dataBlocks; // 0xE
}; // size = 0x10
struct SNDBinaryFileHeader
{
s8 signature[4]; // 0x0
u16 byteOrder; // 0x4
u16 version; // 0x6
u32 fileSize; // 0x8
u16 headerSize; // 0xC
u16 dataBlocks; // 0xE
}; // size = 0x10
typedef struct SNDBinaryBlockHeader {
u32 type; // 0x0
u32 size; // 0x4
} SNDBinaryBlockHeader; // size = 0x8
#endif //POKEDIAMOND_SND_MAIN_SHARED_H
typedef struct SNDBinaryBlockHeader
{
u32 type; // 0x0
u32 size; // 0x4
} SNDBinaryBlockHeader; // size = 0x8
#endif // POKEDIAMOND_SND_MAIN_SHARED_H

View File

@ -8,34 +8,38 @@
struct SNDBankData;
struct SNDPlayer {
struct {
struct SNDPlayer
{
struct
{
u8 active : 1;
u8 prepared : 1;
u8 paused : 1;
} flags; // 0x0
} flags; // 0x0
u8 playerId; // 0x1
u8 unk_2[2]; // 0x2
u8 playerId; // 0x1
u8 unk_2[2]; // 0x2
u8 prio; // 0x4
u8 volume; // 0x5
s16 extFader; // 0x6
u8 prio; // 0x4
u8 volume; // 0x5
s16 extFader; // 0x6
u8 tracks[SND_TRACK_COUNT_PER_PLAYER]; // 0x8
u8 tracks[SND_TRACK_COUNT_PER_PLAYER]; // 0x8
u16 tempo; // 0x18
u16 tempoRatio; // 0x1A
u16 tempoCounter; // 0x1C
u8 unk_1E[2]; // 0x1E
u16 tempo; // 0x18
u16 tempoRatio; // 0x1A
u16 tempoCounter; // 0x1C
u8 unk_1E[2]; // 0x1E
struct SNDBankData *bank; // 0x20
}; // size = 0x24
struct SNDBankData *bank; // 0x20
}; // size = 0x24
#define SND_TRACK_MAX_CALL 3
struct SNDTrack {
struct {
struct SNDTrack
{
struct
{
u8 active : 1;
u8 noteWait : 1;
u8 muted : 1;
@ -44,43 +48,43 @@ struct SNDTrack {
u8 portamento : 1;
u8 cmp : 1; // ???
u8 channelMask : 1;
} flags; // 0x00
} flags; // 0x00
u8 panRange; // 0x01
u16 program; // 0x02
u8 panRange; // 0x01
u16 program; // 0x02
u8 volume; // 0x04
u8 expression; // 0x05
s8 pitchBend; // 0x06
u8 bendRange; // 0x07
u8 volume; // 0x04
u8 expression; // 0x05
s8 pitchBend; // 0x06
u8 bendRange; // 0x07
s8 pan; // 0x08
s8 extPan; // 0x09
s16 extFader; // 0x0A
s16 extPitch; // 0x0C
u8 envAttack; // 0x0E
u8 envDecay; // 0x0F
u8 envSustain; // 0x10
u8 envRelease; // 0x11
u8 priority; // 0x12
s8 transpose; // 0x13
s8 pan; // 0x08
s8 extPan; // 0x09
s16 extFader; // 0x0A
s16 extPitch; // 0x0C
u8 envAttack; // 0x0E
u8 envDecay; // 0x0F
u8 envSustain; // 0x10
u8 envRelease; // 0x11
u8 priority; // 0x12
s8 transpose; // 0x13
u8 portamentoKey; // 0x14
u8 portamentoTime; // 0x15
s16 sweepPitch; // 0x16
u8 portamentoKey; // 0x14
u8 portamentoTime; // 0x15
s16 sweepPitch; // 0x16
struct SNDLfoParam mod; // 0x18
u16 channelMask; // 0x1E
struct SNDLfoParam mod; // 0x18
u16 channelMask; // 0x1E
s32 wait; // 0x20
s32 wait; // 0x20
const u8 *base; // 0x24
const u8 *cur; // 0x28
const u8 *base; // 0x24
const u8 *cur; // 0x28
const u8 *posCallStack[SND_TRACK_MAX_CALL]; // 0x2C
u8 loopCount[SND_TRACK_MAX_CALL]; // 0x38
u8 callStackDepth; // 0x3B
u8 loopCount[SND_TRACK_MAX_CALL]; // 0x38
u8 callStackDepth; // 0x3B
struct SNDExChannel *channelLLHead; // 0x3C
}; // size = 0x40
}; // size = 0x40
#endif //GUARD_SND_SEQ_SHARED_H
#endif // GUARD_SND_SEQ_SHARED_H

View File

@ -13,81 +13,90 @@
#ifndef POKEDIAMOND_SND_WORK_SHARED_H
#define POKEDIAMOND_SND_WORK_SHARED_H
#include "nitro/SND_main_shared.h"
#include "nitro/SND_alarm_shared.h"
#include "nitro/SND_bank_shared.h"
#include "nitro/SND_main_shared.h"
#include "nitro/SND_seq_shared.h"
#define SND_PLAYER_COUNT 16
#define SND_CHANNEL_COUNT 16
#define SND_TRACK_COUNT 32
struct SNDWork {
struct SNDExChannel channels[SND_CHANNEL_COUNT]; // 0x00
struct SNDPlayer players[SND_PLAYER_COUNT]; // 0x540
struct SNDTrack tracks[SND_TRACK_COUNT]; // 0x780
struct SNDAlarm alarms[SND_ALARM_COUNT]; // 0xF80
}; // size = 0x1180
struct SNDWork
{
struct SNDExChannel channels[SND_CHANNEL_COUNT]; // 0x00
struct SNDPlayer players[SND_PLAYER_COUNT]; // 0x540
struct SNDTrack tracks[SND_TRACK_COUNT]; // 0x780
struct SNDAlarm alarms[SND_ALARM_COUNT]; // 0xF80
}; // size = 0x1180
struct SNDSharedWork {
u32 finishedCommandTag; // 0x0
u32 playerStatus; // 0x4
u16 channelStatus; // 0x8
u16 captureStatus; // 0xA
u8 unk_C[0x14]; // 0xC
struct {
s16 localVars[16]; // local 0x0
u32 tickCounter; // local 0x20
} players[SND_PLAYER_COUNT]; // 0x20
s16 globalVars[16]; // 0x260
}; // size = 0x280
struct SNDSharedWork
{
u32 finishedCommandTag; // 0x0
u32 playerStatus; // 0x4
u16 channelStatus; // 0x8
u16 captureStatus; // 0xA
u8 unk_C[0x14]; // 0xC
struct
{
s16 localVars[16]; // local 0x0
u32 tickCounter; // local 0x20
} players[SND_PLAYER_COUNT]; // 0x20
s16 globalVars[16]; // 0x260
}; // size = 0x280
struct SNDDriverInfo {
struct SNDWork work; // 0x0000
struct SNDDriverInfo
{
struct SNDWork work; // 0x0000
u32 channelControls[SND_CHANNEL_COUNT]; // 0x1180
struct SNDWork *workPtr; // 0x11C0
u32 lockedChannels; // 0x11C4
u8 unk_XXX[24]; // 0x11C8
}; // size = 0x11E0
struct SNDWork *workPtr; // 0x11C0
u32 lockedChannels; // 0x11C4
u8 unk_XXX[24]; // 0x11C8
}; // size = 0x11E0
struct SNDChannelInfo {
struct {
struct SNDChannelInfo
{
struct
{
BOOL active : 1;
BOOL locked: 1;
} flags; // 0x0
u16 volume; // 0x4
u8 pan; // 0x6
u8 unk_7; // 0x7
s32 envStatus; // 0x8
}; // size = 0xC
BOOL locked : 1;
} flags; // 0x0
u16 volume; // 0x4
u8 pan; // 0x6
u8 unk_7; // 0x7
s32 envStatus; // 0x8
}; // size = 0xC
struct SNDPlayerInfo {
struct {
struct SNDPlayerInfo
{
struct
{
BOOL active : 1;
BOOL paused : 1;
} flags; // 0x0
u16 trackBitMask; // 0x4
u16 tempo; // 0x6
u8 volume; // 0x8
u8 unk_9[3]; // 0x9
}; // size = 0xC
} flags; // 0x0
u16 trackBitMask; // 0x4
u16 tempo; // 0x6
u8 volume; // 0x8
u8 unk_9[3]; // 0x9
}; // size = 0xC
struct SNDTrackInfo {
u16 program; // 0x0
u8 volume; // 0x2
u8 expression; // 0x3
struct SNDTrackInfo
{
u16 program; // 0x0
u8 volume; // 0x2
u8 expression; // 0x3
s8 pitchBend; // 0x4
u8 bendRange; // 0x5
u8 pan; // 0x6
s8 transpose; // 0x7
s8 pitchBend; // 0x4
u8 bendRange; // 0x5
u8 pan; // 0x6
s8 transpose; // 0x7
u8 unk_8; // 0x8
u8 chnCount; // 0x9
u8 channel[SND_CHANNEL_COUNT]; // 0xA
}; // size = 0x1A
u8 unk_8; // 0x8
u8 chnCount; // 0x9
u8 channel[SND_CHANNEL_COUNT]; // 0xA
}; // size = 0x1A
extern struct SNDWork SNDi_Work;
extern struct SNDSharedWork *SNDi_SharedWork;
#endif //POKEDIAMOND_SND_WORK_SHARED_H
#endif // POKEDIAMOND_SND_WORK_SHARED_H