| 265 | } |
| 266 | |
| 267 | size_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 | |
| 290 | void update_audio_converter() { |
| 291 | int ret = SDL_BuildAudioCVT(&audio_convert, AUDIO_F32, input_channels, sample_rate, AUDIO_F32, output_channels, output_sample_rate); |
nothing calls this directly
no outgoing calls
no test coverage detected