jaudio_NES: several improvements

This commit is contained in:
Cuyler36
2025-07-16 04:41:02 -04:00
parent b5ab50084b
commit 1a38b42b5b
8 changed files with 57 additions and 41 deletions
+2 -2
View File
@@ -771,7 +771,7 @@ config.libs = [
Object(Matching, "jaudio_NES/internal/driverinterface.c"),
Object(Matching, "jaudio_NES/internal/dsp_cardunlock.c"),
Object(Matching, "jaudio_NES/internal/dsp_GBAKey.c"),
Object(Equivalent, "jaudio_NES/internal/dspdriver.c"),
Object(Equivalent, "jaudio_NES/internal/dspdriver.c", extra_cflags=["-vector on"]),
Object(Matching, "jaudio_NES/internal/dspinterface.c"),
Object(Matching, "jaudio_NES/internal/effect.c", extra_cflags=["-pragma \"scheduling 7400\""]),
Object(Matching, "jaudio_NES/internal/fat.c"),
@@ -788,7 +788,7 @@ config.libs = [
Object(Matching, "jaudio_NES/internal/rate.c"),
Object(NonMatching, "jaudio_NES/internal/rspsim.c"),
Object(Matching, "jaudio_NES/internal/seqsetup.c"),
Object(Equivalent, "jaudio_NES/internal/system.c", extra_cflags=["-pragma \"scheduling 7400\""]),
Object(Equivalent, "jaudio_NES/internal/system.c", extra_cflags=["-vector on"]),
Object(Matching, "jaudio_NES/internal/tables.c"),
Object(Matching, "jaudio_NES/internal/waveread.c"),
],
+1 -1
View File
@@ -35,7 +35,7 @@ int Na_GetRadioCounter(Radio_c* radio) {
radio->measure_progress = counter / 768.0f;
}
radio->tempo = AG.groups[sou_now_bgm_handle].tempo / 48;
radio->tempo = AG.groups[sou_now_bgm_handle].tempo / AUDIO_TATUMS_PER_BEAT;
tempo = radio->tempo;
return 0;
}
+11 -11
View File
@@ -331,7 +331,7 @@ static s8 Na_GetRhythmSeNum(s8 num, sub* sub) {
extern void Na_GetRhythmInfo(TempoBeat_c* tempo) {
if (tempo != nullptr) {
tempo->tempo = (AG.groups[2].tempo / 48);
tempo->tempo = (AG.groups[2].tempo / AUDIO_TATUMS_PER_BEAT);
tempo->beat = Na_GetRhythmBeatType();
}
}
@@ -348,10 +348,10 @@ extern void Na_SetRhythmInfo(TempoBeat_c* tempo) {
}
static void tempo_adjust(group* group) {
int tempo = (AG.groups[2].tempo / 48);
int tempo = (AG.groups[2].tempo / AUDIO_TATUMS_PER_BEAT);
int newTempo;
if (AG.groups[sou_now_bgm_handle].flags.enabled != 0) {
newTempo = (AG.groups[sou_now_bgm_handle].tempo / 48);
newTempo = (AG.groups[sou_now_bgm_handle].tempo / AUDIO_TATUMS_PER_BEAT);
if (tempo > newTempo) {
tempo--;
@@ -359,7 +359,7 @@ static void tempo_adjust(group* group) {
tempo++;
}
}
group->tempo = tempo * 48;
group->tempo = tempo * AUDIO_TATUMS_PER_BEAT;
}
static s8 Na_RhythmGrpProcess(s8 arg0, group* group) {
@@ -368,7 +368,7 @@ static s8 Na_RhythmGrpProcess(s8 arg0, group* group) {
int r30;
int r31;
int ret = 1;
r29 = 24;
r29 = AUDIO_TATUMS_PER_BEAT / 2;
static int pre_beat_type = -1;
static int pre_frame_per_step = -1;
@@ -380,7 +380,7 @@ static s8 Na_RhythmGrpProcess(s8 arg0, group* group) {
r29 = 16;
}
} else {
r29 = 24;
r29 = AUDIO_TATUMS_PER_BEAT / 2;
}
/* random call to arg0 so it is stored on the stack, can also do (void)arg0 */
@@ -392,7 +392,7 @@ static s8 Na_RhythmGrpProcess(s8 arg0, group* group) {
} else if (Na_GetRhythmBeatType() == 0) {
r27 = r31 + 32;
} else {
r27 = r31 + 24;
r27 = r31 + AUDIO_TATUMS_PER_BEAT / 2;
}
if (pre_beat_type != rhythm_beat_type) {
@@ -410,11 +410,11 @@ static s8 Na_RhythmGrpProcess(s8 arg0, group* group) {
r30 = 0;
}
if (r30 > 24) {
r30 -= 48;
if (r30 > (AUDIO_TATUMS_PER_BEAT / 2)) {
r30 -= AUDIO_TATUMS_PER_BEAT;
}
if (r30 < -24) {
r30 += 48;
if (r30 < (-AUDIO_TATUMS_PER_BEAT / 2)) {
r30 += AUDIO_TATUMS_PER_BEAT;
}
if (r30 > 1 || r30 < -1) {
+1 -1
View File
@@ -217,7 +217,7 @@ extern void Na_GetStaffRollInfo(StaffRollInfo_c* info) {
break;
}
temp = info->beat * 48;
temp = info->beat * AUDIO_TATUMS_PER_BEAT;
info->_01 = counter / temp;
counter -= info->_01 * temp;
info->percent = (f32)counter / temp;
+20 -11
View File
@@ -46,6 +46,14 @@ void InitDSPchannel()
}
}
typedef enum DSPChannelAllocState {
DSPCHAN_Free = 0, // Channel is available for allocation
DSPCHAN_MonoAllocated = 1, // Channel allocated for mono playback
DSPCHAN_StereoLeft = 2, // Left channel of stereo pair
DSPCHAN_StereoRight = 3, // Right channel of stereo pair
DSPCHAN_Stopping = 4 // Channel is being force stopped
} DSPChannelAllocState;
/*
* --INFO--
* Address: 8000AD60
@@ -53,16 +61,17 @@ void InitDSPchannel()
*/
dspch_* AllocDSPchannel(u32 param_1, u32 param_2)
{
jc_* jc = (jc_*)param_2;
s32 i;
u8 __stack_pad[1];
jc_* p2 = (jc_*)param_2;
s32* ip = &i;
if (param_1 == 0) {
for (i = 0; i < DSPCH_LENGTH; ++i) {
if (DSPCH[i]._01 == 0) {
// @nonmatching - r0/r6 regswap
DSPCH[i]._01 = true;
DSPCH[i]._08 = jc;
if (DSPCH[i]._01 == DSPCHAN_Free) {
DSPCH[i]._01 = DSPCHAN_MonoAllocated;
DSPCH[i]._08 = p2;
DSPCH[i]._03 = 1;
DSP_AllocInit(i);
return &DSPCH[i];
@@ -73,13 +82,13 @@ dspch_* AllocDSPchannel(u32 param_1, u32 param_2)
for (i = 1; i < DSPCH_LENGTH; i += 2) {
if (DSPCH[i]._01 || DSPCH[i - 1]._01)
if (DSPCH[i]._01 != DSPCHAN_Free || DSPCH[i - 1]._01 != DSPCHAN_Free)
continue;
DSPCH[i]._01 = 3;
DSPCH[i - 1]._01 = 2;
DSPCH[i]._08 = (jc_*)param_2;
DSPCH[i - 1]._08 = (jc_*)param_2;
DSPCH[i]._01 = DSPCHAN_StereoRight;
DSPCH[i - 1]._01 = DSPCHAN_StereoLeft;
DSPCH[i]._08 = p2;
DSPCH[i - 1]._08 = p2;
DSP_AllocInit(i);
DSP_AllocInit(i - 1);
return &DSPCH[i - 1];
+1 -1
View File
@@ -1008,7 +1008,7 @@ void __Nas_MemoryReconfig() {
/*0x0002*/ AG._0002 = spec->_14;
s32 tmp = AG.audio_params.updates_per_frame;
/*0x28BC*/ AG.max_tempo = ((((60.0f * 1000.0f * 48) * tmp) / AGC.timeBase) / AG._29D8) / 1.04613;
/*0x28BC*/ AG.max_tempo = ((((60.0f * 1000.0f * AUDIO_TATUMS_PER_BEAT) * tmp) / AGC.timeBase) / AG._29D8) / 1.04613;
/*0x2894*/ AG._2894 = (f32)AG.refresh_rate * (f32)tmp / AG.audio_params.ai_sampling_frequency / AG.max_tempo;
+1 -1
View File
@@ -175,7 +175,7 @@ static void Init_Track(seqp_* track, u32 dataAddress, seqp_* parent)
track->baseData = (u8*)dataAddress;
track->programCounter = 0;
track->tempo = 120;
track->timeBase = 48;
track->timeBase = AUDIO_TATUMS_PER_BEAT;
track->timeRelationMode = 1;
track->isPaused = FALSE;
track->pauseStatus = 10;
+20 -13
View File
@@ -1742,7 +1742,12 @@ s32 Nas_BankOfsToAddr(s32 bank_id, u8* ctrl_p, WaveMedia* wave_media, s32 async)
s32 i;
s32 preloading;
static ALHeap awheap;
u8 medium;
u8 __stack_pad[12];
s32* i_p = &i; // this feels wrong but w/e
preloading = FALSE;
if (AG.num_requested_samples != 0) {
preloading = TRUE;
@@ -1755,7 +1760,7 @@ s32 Nas_BankOfsToAddr(s32 bank_id, u8* ctrl_p, WaveMedia* wave_media, s32 async)
size = 0;
for (i = 0; i < AG.num_used_samples; i++) {
size += ALIGN_NEXT(AG.used_samples[i]->size, 32);
size += ALIGN_NEXT(AG.used_samples[i]->size, 16);
}
for (i = 0; i < AG.num_used_samples; i++) {
@@ -1768,26 +1773,28 @@ s32 Nas_BankOfsToAddr(s32 bank_id, u8* ctrl_p, WaveMedia* wave_media, s32 async)
switch (async) {
case FALSE:
if (wavetable->medium == wave_media->wave0_media) {
medium = wavetable->medium;
if (medium == wave_media->wave0_media) {
wave_ram_p = (u8*)Nas_Alloc_Single(wavetable->size, wave_media->wave0_bank_id, wavetable->sample,
wavetable->medium, CACHE_PERSISTENT);
} else if (wavetable->medium == wave_media->wave1_media) {
(s8)medium, CACHE_PERSISTENT);
} else if (medium == wave_media->wave1_media) {
wave_ram_p = (u8*)Nas_Alloc_Single(wavetable->size, wave_media->wave1_bank_id, wavetable->sample,
wavetable->medium, CACHE_PERSISTENT);
} else if (wavetable->medium == MEDIUM_DISK_DRIVE) {
wave_ram_p = (u8*)Nas_Alloc_Single(wavetable->size, 0xFE, wavetable->sample, wavetable->medium,
(s8)wavetable->medium, CACHE_PERSISTENT);
} else if (medium == MEDIUM_DISK_DRIVE) {
wave_ram_p = (u8*)Nas_Alloc_Single(wavetable->size, 0xFE, wavetable->sample, (s8)wavetable->medium,
CACHE_PERSISTENT);
}
break;
case TRUE:
if (wavetable->medium == wave_media->wave0_media) {
medium = wavetable->medium;
if (medium == wave_media->wave0_media) {
wave_ram_p = (u8*)Nas_Alloc_Single(wavetable->size, wave_media->wave0_bank_id, wavetable->sample,
wavetable->medium, CACHE_TEMPORARY);
} else if (wavetable->medium == wave_media->wave1_media) {
(s8)wavetable->medium, CACHE_TEMPORARY);
} else if (medium == wave_media->wave1_media) {
wave_ram_p = (u8*)Nas_Alloc_Single(wavetable->size, wave_media->wave1_bank_id, wavetable->sample,
wavetable->medium, CACHE_TEMPORARY);
} else if (wavetable->medium == MEDIUM_DISK_DRIVE) {
wave_ram_p = (u8*)Nas_Alloc_Single(wavetable->size, 0xFE, wavetable->sample, wavetable->medium,
(s8)wavetable->medium, CACHE_TEMPORARY);
} else if (medium == MEDIUM_DISK_DRIVE) {
wave_ram_p = (u8*)Nas_Alloc_Single(wavetable->size, 0xFE, wavetable->sample, (s8)wavetable->medium,
CACHE_TEMPORARY);
}
break;