Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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()) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't you be updating recent_frames_queued somewhere? Otherwise this will always eval to zero

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right, and upon further inspection adding the missing piece to this implementation breaks the recomp this was used for. It doesn't make sense to merge this if it's incomplete, so I'll close it for now.

return 0x80000000;
}

return 0x0;
}