MCPcopy Create free account
hub / github.com/RevoSucks/BM64Recomp / get_frames_remaining

Function get_frames_remaining

src/main/main.cpp:267–288  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

265}
266
267size_t get_frames_remaining() {
268 constexpr float buffer_offset_frames = 1.0f;
269 // Get the number of remaining buffered audio bytes.
270 uint64_t buffered_byte_count = SDL_GetQueuedAudioSize(audio_device);
271
272 // Scale the byte count based on the ratio of sample rates and channel counts.
273 buffered_byte_count = buffered_byte_count * 2 * sample_rate / output_sample_rate / output_channels;
274
275 // Adjust the reported count to be some number of refreshes in the future, which helps ensure that
276 // there are enough samples even if the audio thread experiences a small amount of lag. This prevents
277 // audio popping on games that use the buffered audio byte count to determine how many samples
278 // to generate.
279 uint32_t frames_per_vi = (sample_rate / 60);
280 if (buffered_byte_count > (buffer_offset_frames * bytes_per_frame * frames_per_vi)) {
281 buffered_byte_count -= (buffer_offset_frames * bytes_per_frame * frames_per_vi);
282 }
283 else {
284 buffered_byte_count = 0;
285 }
286 // Convert from byte count to sample count.
287 return static_cast<uint32_t>(buffered_byte_count / bytes_per_frame);
288}
289
290void update_audio_converter() {
291 int ret = SDL_BuildAudioCVT(&audio_convert, AUDIO_F32, input_channels, sample_rate, AUDIO_F32, output_channels, output_sample_rate);

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected