Skip to content

Commit

Permalink
fix rrow
Browse files Browse the repository at this point in the history
  • Loading branch information
LittleCube-hax committed Dec 29, 2024
1 parent 1361c48 commit cc4a6a3
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 1 deletion.
2 changes: 1 addition & 1 deletion librecomp/src/ai.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,5 @@ extern "C" void osAiGetLength_recomp(uint8_t* rdram, recomp_context* ctx) {
}

extern "C" void osAiGetStatus_recomp(uint8_t* rdram, recomp_context* ctx) {
ctx->r2 = 0x00000000; // Pretend the audio DMAs finish instantly
ctx->r2 = osAiGetStatus();
}
2 changes: 2 additions & 0 deletions ultramodern/include/ultramodern/ultra64.h
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,8 @@ int osSetTimer(RDRAM_ARG PTR(OSTimer) timer, OSTime countdown, OSTime interval,
int osStopTimer(RDRAM_ARG PTR(OSTimer) timer);
u32 osVirtualToPhysical(PTR(void) addr);

u32 osAiGetStatus();

/* Controller interface */

s32 osContInit(RDRAM_ARG PTR(OSMesgQueue), u8*, PTR(OSContStatus));
Expand Down
24 changes: 24 additions & 0 deletions ultramodern/src/audio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ static uint32_t sample_rate = 48000;

static ultramodern::audio_callbacks_t audio_callbacks;

std::atomic<uint32_t> recent_frames_queued = 0;

void ultramodern::set_audio_callbacks(const ultramodern::audio_callbacks_t& callbacks) {
audio_callbacks = callbacks;
}
Expand Down Expand Up @@ -65,3 +67,25 @@ uint32_t ultramodern::get_remaining_audio_bytes() {
}
return buffered_byte_count;
}

extern "C" u32 osAiGetStatus() {
uint32_t cur_frame_count = 0;
if (audio_callbacks.get_frames_remaining != nullptr) {
cur_frame_count = audio_callbacks.get_frames_remaining();
}

uint32_t samples_per_vi = (sample_rate / 60);
if (cur_frame_count > static_cast<uint32_t>(buffer_offset_frames * samples_per_vi)) {
cur_frame_count -= static_cast<uint32_t>(buffer_offset_frames * samples_per_vi);
}
else {
cur_frame_count = 0;
}

// Check if the most recently queued samples are playing, if not then consider the DMA as incomplete.
if (cur_frame_count > recent_frames_queued.load()) {
return 0x80000000;
}

return 0x0;
}

0 comments on commit cc4a6a3

Please sign in to comment.