diff options
| author | 2020-09-11 10:57:27 -0400 | |
|---|---|---|
| committer | 2020-09-11 10:57:27 -0400 | |
| commit | 324029d4f9fd2381f474e608a2859360324161e5 (patch) | |
| tree | d2dc348235f05f20686c526f7092590f596f65c2 /src/core | |
| parent | Merge pull request #4597 from Morph1984/mjolnir-p2 (diff) | |
| parent | Preliminary effects (diff) | |
| download | yuzu-324029d4f9fd2381f474e608a2859360324161e5.tar.gz yuzu-324029d4f9fd2381f474e608a2859360324161e5.tar.xz yuzu-324029d4f9fd2381f474e608a2859360324161e5.zip | |
Merge pull request #4310 from ogniK5377/apollo-1-prod
audio_core: Apollo Part 1, AudioRenderer refactor
Diffstat (limited to 'src/core')
| -rw-r--r-- | src/core/hle/service/audio/audren_u.cpp | 149 |
1 files changed, 77 insertions, 72 deletions
diff --git a/src/core/hle/service/audio/audren_u.cpp b/src/core/hle/service/audio/audren_u.cpp index d8359abaa..a2d3ded7b 100644 --- a/src/core/hle/service/audio/audren_u.cpp +++ b/src/core/hle/service/audio/audren_u.cpp | |||
| @@ -26,7 +26,7 @@ namespace Service::Audio { | |||
| 26 | 26 | ||
| 27 | class IAudioRenderer final : public ServiceFramework<IAudioRenderer> { | 27 | class IAudioRenderer final : public ServiceFramework<IAudioRenderer> { |
| 28 | public: | 28 | public: |
| 29 | explicit IAudioRenderer(Core::System& system, AudioCore::AudioRendererParameter audren_params, | 29 | explicit IAudioRenderer(Core::System& system, AudioCommon::AudioRendererParameter audren_params, |
| 30 | const std::size_t instance_number) | 30 | const std::size_t instance_number) |
| 31 | : ServiceFramework("IAudioRenderer") { | 31 | : ServiceFramework("IAudioRenderer") { |
| 32 | // clang-format off | 32 | // clang-format off |
| @@ -94,14 +94,15 @@ private: | |||
| 94 | void RequestUpdateImpl(Kernel::HLERequestContext& ctx) { | 94 | void RequestUpdateImpl(Kernel::HLERequestContext& ctx) { |
| 95 | LOG_DEBUG(Service_Audio, "(STUBBED) called"); | 95 | LOG_DEBUG(Service_Audio, "(STUBBED) called"); |
| 96 | 96 | ||
| 97 | auto result = renderer->UpdateAudioRenderer(ctx.ReadBuffer()); | 97 | std::vector<u8> output_params(ctx.GetWriteBufferSize()); |
| 98 | auto result = renderer->UpdateAudioRenderer(ctx.ReadBuffer(), output_params); | ||
| 98 | 99 | ||
| 99 | if (result.Succeeded()) { | 100 | if (result.IsSuccess()) { |
| 100 | ctx.WriteBuffer(result.Unwrap()); | 101 | ctx.WriteBuffer(output_params); |
| 101 | } | 102 | } |
| 102 | 103 | ||
| 103 | IPC::ResponseBuilder rb{ctx, 2}; | 104 | IPC::ResponseBuilder rb{ctx, 2}; |
| 104 | rb.Push(result.Code()); | 105 | rb.Push(result); |
| 105 | } | 106 | } |
| 106 | 107 | ||
| 107 | void Start(Kernel::HLERequestContext& ctx) { | 108 | void Start(Kernel::HLERequestContext& ctx) { |
| @@ -346,7 +347,7 @@ void AudRenU::OpenAudioRenderer(Kernel::HLERequestContext& ctx) { | |||
| 346 | OpenAudioRendererImpl(ctx); | 347 | OpenAudioRendererImpl(ctx); |
| 347 | } | 348 | } |
| 348 | 349 | ||
| 349 | static u64 CalculateNumPerformanceEntries(const AudioCore::AudioRendererParameter& params) { | 350 | static u64 CalculateNumPerformanceEntries(const AudioCommon::AudioRendererParameter& params) { |
| 350 | // +1 represents the final mix. | 351 | // +1 represents the final mix. |
| 351 | return u64{params.effect_count} + params.submix_count + params.sink_count + params.voice_count + | 352 | return u64{params.effect_count} + params.submix_count + params.sink_count + params.voice_count + |
| 352 | 1; | 353 | 1; |
| @@ -375,7 +376,7 @@ void AudRenU::GetAudioRendererWorkBufferSize(Kernel::HLERequestContext& ctx) { | |||
| 375 | constexpr u64 upsampler_manager_size = 0x48; | 376 | constexpr u64 upsampler_manager_size = 0x48; |
| 376 | 377 | ||
| 377 | // Calculates the part of the size that relates to mix buffers. | 378 | // Calculates the part of the size that relates to mix buffers. |
| 378 | const auto calculate_mix_buffer_sizes = [](const AudioCore::AudioRendererParameter& params) { | 379 | const auto calculate_mix_buffer_sizes = [](const AudioCommon::AudioRendererParameter& params) { |
| 379 | // As of 8.0.0 this is the maximum on voice channels. | 380 | // As of 8.0.0 this is the maximum on voice channels. |
| 380 | constexpr u64 max_voice_channels = 6; | 381 | constexpr u64 max_voice_channels = 6; |
| 381 | 382 | ||
| @@ -397,7 +398,7 @@ void AudRenU::GetAudioRendererWorkBufferSize(Kernel::HLERequestContext& ctx) { | |||
| 397 | }; | 398 | }; |
| 398 | 399 | ||
| 399 | // Calculates the portion of the size related to the mix data (and the sorting thereof). | 400 | // Calculates the portion of the size related to the mix data (and the sorting thereof). |
| 400 | const auto calculate_mix_info_size = [](const AudioCore::AudioRendererParameter& params) { | 401 | const auto calculate_mix_info_size = [](const AudioCommon::AudioRendererParameter& params) { |
| 401 | // The size of the mixing info data structure. | 402 | // The size of the mixing info data structure. |
| 402 | constexpr u64 mix_info_size = 0x940; | 403 | constexpr u64 mix_info_size = 0x940; |
| 403 | 404 | ||
| @@ -447,7 +448,7 @@ void AudRenU::GetAudioRendererWorkBufferSize(Kernel::HLERequestContext& ctx) { | |||
| 447 | }; | 448 | }; |
| 448 | 449 | ||
| 449 | // Calculates the part of the size related to voice channel info. | 450 | // Calculates the part of the size related to voice channel info. |
| 450 | const auto calculate_voice_info_size = [](const AudioCore::AudioRendererParameter& params) { | 451 | const auto calculate_voice_info_size = [](const AudioCommon::AudioRendererParameter& params) { |
| 451 | constexpr u64 voice_info_size = 0x220; | 452 | constexpr u64 voice_info_size = 0x220; |
| 452 | constexpr u64 voice_resource_size = 0xD0; | 453 | constexpr u64 voice_resource_size = 0xD0; |
| 453 | 454 | ||
| @@ -461,7 +462,7 @@ void AudRenU::GetAudioRendererWorkBufferSize(Kernel::HLERequestContext& ctx) { | |||
| 461 | }; | 462 | }; |
| 462 | 463 | ||
| 463 | // Calculates the part of the size related to memory pools. | 464 | // Calculates the part of the size related to memory pools. |
| 464 | const auto calculate_memory_pools_size = [](const AudioCore::AudioRendererParameter& params) { | 465 | const auto calculate_memory_pools_size = [](const AudioCommon::AudioRendererParameter& params) { |
| 465 | const u64 num_memory_pools = sizeof(s32) * (u64{params.effect_count} + params.voice_count); | 466 | const u64 num_memory_pools = sizeof(s32) * (u64{params.effect_count} + params.voice_count); |
| 466 | const u64 memory_pool_info_size = 0x20; | 467 | const u64 memory_pool_info_size = 0x20; |
| 467 | return Common::AlignUp(num_memory_pools * memory_pool_info_size, info_field_alignment_size); | 468 | return Common::AlignUp(num_memory_pools * memory_pool_info_size, info_field_alignment_size); |
| @@ -469,7 +470,7 @@ void AudRenU::GetAudioRendererWorkBufferSize(Kernel::HLERequestContext& ctx) { | |||
| 469 | 470 | ||
| 470 | // Calculates the part of the size related to the splitter context. | 471 | // Calculates the part of the size related to the splitter context. |
| 471 | const auto calculate_splitter_context_size = | 472 | const auto calculate_splitter_context_size = |
| 472 | [](const AudioCore::AudioRendererParameter& params) -> u64 { | 473 | [](const AudioCommon::AudioRendererParameter& params) -> u64 { |
| 473 | if (!IsFeatureSupported(AudioFeatures::Splitter, params.revision)) { | 474 | if (!IsFeatureSupported(AudioFeatures::Splitter, params.revision)) { |
| 474 | return 0; | 475 | return 0; |
| 475 | } | 476 | } |
| @@ -488,27 +489,29 @@ void AudRenU::GetAudioRendererWorkBufferSize(Kernel::HLERequestContext& ctx) { | |||
| 488 | }; | 489 | }; |
| 489 | 490 | ||
| 490 | // Calculates the part of the size related to the upsampler info. | 491 | // Calculates the part of the size related to the upsampler info. |
| 491 | const auto calculate_upsampler_info_size = [](const AudioCore::AudioRendererParameter& params) { | 492 | const auto calculate_upsampler_info_size = |
| 492 | constexpr u64 upsampler_info_size = 0x280; | 493 | [](const AudioCommon::AudioRendererParameter& params) { |
| 493 | // Yes, using the buffer size over info alignment size is intentional here. | 494 | constexpr u64 upsampler_info_size = 0x280; |
| 494 | return Common::AlignUp(upsampler_info_size * (u64{params.submix_count} + params.sink_count), | 495 | // Yes, using the buffer size over info alignment size is intentional here. |
| 495 | buffer_alignment_size); | 496 | return Common::AlignUp(upsampler_info_size * |
| 496 | }; | 497 | (u64{params.submix_count} + params.sink_count), |
| 498 | buffer_alignment_size); | ||
| 499 | }; | ||
| 497 | 500 | ||
| 498 | // Calculates the part of the size related to effect info. | 501 | // Calculates the part of the size related to effect info. |
| 499 | const auto calculate_effect_info_size = [](const AudioCore::AudioRendererParameter& params) { | 502 | const auto calculate_effect_info_size = [](const AudioCommon::AudioRendererParameter& params) { |
| 500 | constexpr u64 effect_info_size = 0x2B0; | 503 | constexpr u64 effect_info_size = 0x2B0; |
| 501 | return Common::AlignUp(effect_info_size * params.effect_count, info_field_alignment_size); | 504 | return Common::AlignUp(effect_info_size * params.effect_count, info_field_alignment_size); |
| 502 | }; | 505 | }; |
| 503 | 506 | ||
| 504 | // Calculates the part of the size related to audio sink info. | 507 | // Calculates the part of the size related to audio sink info. |
| 505 | const auto calculate_sink_info_size = [](const AudioCore::AudioRendererParameter& params) { | 508 | const auto calculate_sink_info_size = [](const AudioCommon::AudioRendererParameter& params) { |
| 506 | const u64 sink_info_size = 0x170; | 509 | const u64 sink_info_size = 0x170; |
| 507 | return Common::AlignUp(sink_info_size * params.sink_count, info_field_alignment_size); | 510 | return Common::AlignUp(sink_info_size * params.sink_count, info_field_alignment_size); |
| 508 | }; | 511 | }; |
| 509 | 512 | ||
| 510 | // Calculates the part of the size related to voice state info. | 513 | // Calculates the part of the size related to voice state info. |
| 511 | const auto calculate_voice_state_size = [](const AudioCore::AudioRendererParameter& params) { | 514 | const auto calculate_voice_state_size = [](const AudioCommon::AudioRendererParameter& params) { |
| 512 | const u64 voice_state_size = 0x100; | 515 | const u64 voice_state_size = 0x100; |
| 513 | const u64 additional_size = buffer_alignment_size - 1; | 516 | const u64 additional_size = buffer_alignment_size - 1; |
| 514 | return Common::AlignUp(voice_state_size * params.voice_count + additional_size, | 517 | return Common::AlignUp(voice_state_size * params.voice_count + additional_size, |
| @@ -516,7 +519,7 @@ void AudRenU::GetAudioRendererWorkBufferSize(Kernel::HLERequestContext& ctx) { | |||
| 516 | }; | 519 | }; |
| 517 | 520 | ||
| 518 | // Calculates the part of the size related to performance statistics. | 521 | // Calculates the part of the size related to performance statistics. |
| 519 | const auto calculate_perf_size = [](const AudioCore::AudioRendererParameter& params) { | 522 | const auto calculate_perf_size = [](const AudioCommon::AudioRendererParameter& params) { |
| 520 | // Extra size value appended to the end of the calculation. | 523 | // Extra size value appended to the end of the calculation. |
| 521 | constexpr u64 appended = 128; | 524 | constexpr u64 appended = 128; |
| 522 | 525 | ||
| @@ -543,79 +546,81 @@ void AudRenU::GetAudioRendererWorkBufferSize(Kernel::HLERequestContext& ctx) { | |||
| 543 | }; | 546 | }; |
| 544 | 547 | ||
| 545 | // Calculates the part of the size that relates to the audio command buffer. | 548 | // Calculates the part of the size that relates to the audio command buffer. |
| 546 | const auto calculate_command_buffer_size = [](const AudioCore::AudioRendererParameter& params) { | 549 | const auto calculate_command_buffer_size = |
| 547 | constexpr u64 alignment = (buffer_alignment_size - 1) * 2; | 550 | [](const AudioCommon::AudioRendererParameter& params) { |
| 551 | constexpr u64 alignment = (buffer_alignment_size - 1) * 2; | ||
| 548 | 552 | ||
| 549 | if (!IsFeatureSupported(AudioFeatures::VariadicCommandBuffer, params.revision)) { | 553 | if (!IsFeatureSupported(AudioFeatures::VariadicCommandBuffer, params.revision)) { |
| 550 | constexpr u64 command_buffer_size = 0x18000; | 554 | constexpr u64 command_buffer_size = 0x18000; |
| 551 | 555 | ||
| 552 | return command_buffer_size + alignment; | 556 | return command_buffer_size + alignment; |
| 553 | } | 557 | } |
| 554 | 558 | ||
| 555 | // When the variadic command buffer is supported, this means | 559 | // When the variadic command buffer is supported, this means |
| 556 | // the command generator for the audio renderer can issue commands | 560 | // the command generator for the audio renderer can issue commands |
| 557 | // that are (as one would expect), variable in size. So what we need to do | 561 | // that are (as one would expect), variable in size. So what we need to do |
| 558 | // is determine the maximum possible size for a few command data structures | 562 | // is determine the maximum possible size for a few command data structures |
| 559 | // then multiply them by the amount of present commands indicated by the given | 563 | // then multiply them by the amount of present commands indicated by the given |
| 560 | // respective audio parameters. | 564 | // respective audio parameters. |
| 561 | 565 | ||
| 562 | constexpr u64 max_biquad_filters = 2; | 566 | constexpr u64 max_biquad_filters = 2; |
| 563 | constexpr u64 max_mix_buffers = 24; | 567 | constexpr u64 max_mix_buffers = 24; |
| 564 | 568 | ||
| 565 | constexpr u64 biquad_filter_command_size = 0x2C; | 569 | constexpr u64 biquad_filter_command_size = 0x2C; |
| 566 | 570 | ||
| 567 | constexpr u64 depop_mix_command_size = 0x24; | 571 | constexpr u64 depop_mix_command_size = 0x24; |
| 568 | constexpr u64 depop_setup_command_size = 0x50; | 572 | constexpr u64 depop_setup_command_size = 0x50; |
| 569 | 573 | ||
| 570 | constexpr u64 effect_command_max_size = 0x540; | 574 | constexpr u64 effect_command_max_size = 0x540; |
| 571 | 575 | ||
| 572 | constexpr u64 mix_command_size = 0x1C; | 576 | constexpr u64 mix_command_size = 0x1C; |
| 573 | constexpr u64 mix_ramp_command_size = 0x24; | 577 | constexpr u64 mix_ramp_command_size = 0x24; |
| 574 | constexpr u64 mix_ramp_grouped_command_size = 0x13C; | 578 | constexpr u64 mix_ramp_grouped_command_size = 0x13C; |
| 575 | 579 | ||
| 576 | constexpr u64 perf_command_size = 0x28; | 580 | constexpr u64 perf_command_size = 0x28; |
| 577 | 581 | ||
| 578 | constexpr u64 sink_command_size = 0x130; | 582 | constexpr u64 sink_command_size = 0x130; |
| 579 | 583 | ||
| 580 | constexpr u64 submix_command_max_size = | 584 | constexpr u64 submix_command_max_size = |
| 581 | depop_mix_command_size + (mix_command_size * max_mix_buffers) * max_mix_buffers; | 585 | depop_mix_command_size + (mix_command_size * max_mix_buffers) * max_mix_buffers; |
| 582 | 586 | ||
| 583 | constexpr u64 volume_command_size = 0x1C; | 587 | constexpr u64 volume_command_size = 0x1C; |
| 584 | constexpr u64 volume_ramp_command_size = 0x20; | 588 | constexpr u64 volume_ramp_command_size = 0x20; |
| 585 | 589 | ||
| 586 | constexpr u64 voice_biquad_filter_command_size = | 590 | constexpr u64 voice_biquad_filter_command_size = |
| 587 | biquad_filter_command_size * max_biquad_filters; | 591 | biquad_filter_command_size * max_biquad_filters; |
| 588 | constexpr u64 voice_data_command_size = 0x9C; | 592 | constexpr u64 voice_data_command_size = 0x9C; |
| 589 | const u64 voice_command_max_size = | 593 | const u64 voice_command_max_size = |
| 590 | (params.splitter_count * depop_setup_command_size) + | 594 | (params.splitter_count * depop_setup_command_size) + |
| 591 | (voice_data_command_size + voice_biquad_filter_command_size + volume_ramp_command_size + | 595 | (voice_data_command_size + voice_biquad_filter_command_size + |
| 592 | mix_ramp_grouped_command_size); | 596 | volume_ramp_command_size + mix_ramp_grouped_command_size); |
| 593 | 597 | ||
| 594 | // Now calculate the individual elements that comprise the size and add them together. | 598 | // Now calculate the individual elements that comprise the size and add them together. |
| 595 | const u64 effect_commands_size = params.effect_count * effect_command_max_size; | 599 | const u64 effect_commands_size = params.effect_count * effect_command_max_size; |
| 596 | 600 | ||
| 597 | const u64 final_mix_commands_size = | 601 | const u64 final_mix_commands_size = |
| 598 | depop_mix_command_size + volume_command_size * max_mix_buffers; | 602 | depop_mix_command_size + volume_command_size * max_mix_buffers; |
| 599 | 603 | ||
| 600 | const u64 perf_commands_size = | 604 | const u64 perf_commands_size = |
| 601 | perf_command_size * (CalculateNumPerformanceEntries(params) + max_perf_detail_entries); | 605 | perf_command_size * |
| 606 | (CalculateNumPerformanceEntries(params) + max_perf_detail_entries); | ||
| 602 | 607 | ||
| 603 | const u64 sink_commands_size = params.sink_count * sink_command_size; | 608 | const u64 sink_commands_size = params.sink_count * sink_command_size; |
| 604 | 609 | ||
| 605 | const u64 splitter_commands_size = | 610 | const u64 splitter_commands_size = |
| 606 | params.num_splitter_send_channels * max_mix_buffers * mix_ramp_command_size; | 611 | params.num_splitter_send_channels * max_mix_buffers * mix_ramp_command_size; |
| 607 | 612 | ||
| 608 | const u64 submix_commands_size = params.submix_count * submix_command_max_size; | 613 | const u64 submix_commands_size = params.submix_count * submix_command_max_size; |
| 609 | 614 | ||
| 610 | const u64 voice_commands_size = params.voice_count * voice_command_max_size; | 615 | const u64 voice_commands_size = params.voice_count * voice_command_max_size; |
| 611 | 616 | ||
| 612 | return effect_commands_size + final_mix_commands_size + perf_commands_size + | 617 | return effect_commands_size + final_mix_commands_size + perf_commands_size + |
| 613 | sink_commands_size + splitter_commands_size + submix_commands_size + | 618 | sink_commands_size + splitter_commands_size + submix_commands_size + |
| 614 | voice_commands_size + alignment; | 619 | voice_commands_size + alignment; |
| 615 | }; | 620 | }; |
| 616 | 621 | ||
| 617 | IPC::RequestParser rp{ctx}; | 622 | IPC::RequestParser rp{ctx}; |
| 618 | const auto params = rp.PopRaw<AudioCore::AudioRendererParameter>(); | 623 | const auto params = rp.PopRaw<AudioCommon::AudioRendererParameter>(); |
| 619 | 624 | ||
| 620 | u64 size = 0; | 625 | u64 size = 0; |
| 621 | size += calculate_mix_buffer_sizes(params); | 626 | size += calculate_mix_buffer_sizes(params); |
| @@ -681,7 +686,7 @@ void AudRenU::GetAudioDeviceServiceWithRevisionInfo(Kernel::HLERequestContext& c | |||
| 681 | 686 | ||
| 682 | void AudRenU::OpenAudioRendererImpl(Kernel::HLERequestContext& ctx) { | 687 | void AudRenU::OpenAudioRendererImpl(Kernel::HLERequestContext& ctx) { |
| 683 | IPC::RequestParser rp{ctx}; | 688 | IPC::RequestParser rp{ctx}; |
| 684 | const auto params = rp.PopRaw<AudioCore::AudioRendererParameter>(); | 689 | const auto params = rp.PopRaw<AudioCommon::AudioRendererParameter>(); |
| 685 | IPC::ResponseBuilder rb{ctx, 2, 0, 1}; | 690 | IPC::ResponseBuilder rb{ctx, 2, 0, 1}; |
| 686 | 691 | ||
| 687 | rb.Push(RESULT_SUCCESS); | 692 | rb.Push(RESULT_SUCCESS); |