| 684 | } |
| 685 | |
| 686 | static Result EnsureDecoderScratchBufferSize(SoundSystem* sound, const dmSoundCodec::Info& info, uint32_t required_frame_capacity) |
| 687 | { |
| 688 | const uint64_t required_temp_output_capacity = (uint64_t)required_frame_capacity * GetDecoderOutputStrideBytes(info); |
| 689 | if (required_temp_output_capacity > 0xffffffffU) |
| 690 | return RESULT_OUT_OF_MEMORY; |
| 691 | |
| 692 | const bool grow_decoder_buffers = required_frame_capacity > sound->m_DecoderBufferFrameCapacity; |
| 693 | const bool grow_temp_buffer = required_temp_output_capacity > sound->m_DecoderTempOutputCapacity; |
| 694 | |
| 695 | if (!grow_decoder_buffers && !grow_temp_buffer) |
| 696 | return RESULT_OK; |
| 697 | |
| 698 | if (grow_decoder_buffers) |
| 699 | { |
| 700 | for (uint32_t c = 0; c < SOUND_MAX_DECODE_CHANNELS; ++c) |
| 701 | { |
| 702 | float* new_decoder_output = (float*)realloc(sound->m_DecoderOutput[c], required_frame_capacity * sizeof(float)); |
| 703 | if (new_decoder_output == 0) |
| 704 | { |
| 705 | return RESULT_OUT_OF_MEMORY; |
| 706 | } |
| 707 | sound->m_DecoderOutput[c] = new_decoder_output; |
| 708 | } |
| 709 | sound->m_DecoderBufferFrameCapacity = required_frame_capacity; |
| 710 | } |
| 711 | |
| 712 | if (grow_temp_buffer) |
| 713 | { |
| 714 | void* new_decoder_temp_output = realloc(sound->m_DecoderTempOutput, (size_t)required_temp_output_capacity); |
| 715 | if (new_decoder_temp_output == 0) |
| 716 | return RESULT_OUT_OF_MEMORY; |
| 717 | |
| 718 | sound->m_DecoderTempOutput = new_decoder_temp_output; |
| 719 | sound->m_DecoderTempOutputCapacity = (uint32_t)required_temp_output_capacity; |
| 720 | } |
| 721 | |
| 722 | DM_PROPERTY_SET_U32(rmtp_ScratchBufferSize, sound->m_DecoderBufferFrameCapacity * sizeof(float) * SOUND_MAX_DECODE_CHANNELS + sound->m_DecoderTempOutputCapacity); |
| 723 | |
| 724 | return RESULT_OK; |
| 725 | } |
| 726 | |
| 727 | static Result EnsureInstanceFrameBufferSize(SoundInstance* instance, uint32_t required_frame_capacity) |
| 728 | { |
no test coverage detected