diff --git a/rpcs3/Emu/Cell/Modules/cellAudio.cpp b/rpcs3/Emu/Cell/Modules/cellAudio.cpp index 5a900ce181..ec6348ac6c 100644 --- a/rpcs3/Emu/Cell/Modules/cellAudio.cpp +++ b/rpcs3/Emu/Cell/Modules/cellAudio.cpp @@ -295,7 +295,7 @@ void audio_ringbuffer::commit_data(f32* buf, u32 sample_cnt) if (g_recording_mode != recording_mode::stopped) { utils::video_provider& provider = g_fxo->get(); - provider.present_samples(reinterpret_cast(buf), sample_cnt, static_cast(cfg.audio_channels)); + provider.present_samples(reinterpret_cast(buf), sample_cnt, cfg.audio_channels); } // Downmix if necessary @@ -1004,7 +1004,7 @@ void cell_audio_thread::operator()() break; default: - fmt::throw_exception("Unsupported channel count in cell_audio_config: %d", static_cast(cfg.audio_channels)); + fmt::throw_exception("Unsupported channel count in cell_audio_config: %d", cfg.audio_channels); } // Enqueue diff --git a/rpcs3/Emu/Cell/lv2/sys_rsxaudio.cpp b/rpcs3/Emu/Cell/lv2/sys_rsxaudio.cpp index b11065748b..f7ded746a9 100644 --- a/rpcs3/Emu/Cell/lv2/sys_rsxaudio.cpp +++ b/rpcs3/Emu/Cell/lv2/sys_rsxaudio.cpp @@ -3,6 +3,7 @@ #include "Emu/IdManager.h" #include "Emu/System.h" #include "Emu/system_config.h" +#include "util/video_provider.h" #include "sys_process.h" #include "sys_rsxaudio.h" @@ -22,6 +23,8 @@ LOG_CHANNEL(sys_rsxaudio); +extern atomic_t g_recording_mode; + namespace rsxaudio_ringbuf_reader { static constexpr void clean_buf(rsxaudio_shmem::ringbuf_t& ring_buf) @@ -1353,6 +1356,16 @@ void rsxaudio_backend_thread::update_emu_cfg() } } +u32 rsxaudio_backend_thread::get_sample_rate() const +{ + return callback_cfg.load().freq; +} + +u8 rsxaudio_backend_thread::get_channel_count() const +{ + return callback_cfg.load().input_ch_cnt; +} + rsxaudio_backend_thread::emu_audio_cfg rsxaudio_backend_thread::get_emu_cfg() { // Get max supported channel count @@ -1466,7 +1479,8 @@ void rsxaudio_backend_thread::operator()() state_update_c.wait(state_update_m, ERROR_SERVICE_PERIOD); break; } - else if (use_aux_ringbuf) + + if (use_aux_ringbuf) { const u64 next_period_time = get_time_until_service(); should_service_stream = next_period_time <= SERVICE_THRESHOLD; @@ -1570,6 +1584,7 @@ void rsxaudio_backend_thread::operator()() crnt_buf_size = sample_cnt * bytes_per_sample; } + // Dump audio if enabled if (emu_cfg.dump_to_file) { dumper.WriteData(crnt_buf, static_cast(crnt_buf_size)); @@ -1842,6 +1857,13 @@ u32 rsxaudio_backend_thread::write_data_callback(u32 bytes, void* buf) return bytes; } + // Record audio if enabled + if (g_recording_mode != recording_mode::stopped) + { + utils::video_provider& provider = g_fxo->get(); + provider.present_samples(reinterpret_cast(callback_tmp_buf.data()), sample_cnt / cb_cfg.input_ch_cnt, cb_cfg.input_ch_cnt); + } + // Downmix if necessary AudioBackend::downmix(sample_cnt, cb_cfg.input_ch_cnt, cb_cfg.output_ch_cnt, callback_tmp_buf.data(), callback_tmp_buf.data()); diff --git a/rpcs3/Emu/Cell/lv2/sys_rsxaudio.h b/rpcs3/Emu/Cell/lv2/sys_rsxaudio.h index c223793cd6..bd0a3531fd 100644 --- a/rpcs3/Emu/Cell/lv2/sys_rsxaudio.h +++ b/rpcs3/Emu/Cell/lv2/sys_rsxaudio.h @@ -458,6 +458,9 @@ public: void update_emu_cfg(); + u32 get_sample_rate() const; + u8 get_channel_count() const; + static constexpr auto thread_name = "RsxAudio Backend Thread"sv; private: diff --git a/rpcs3/rpcs3qt/gs_frame.cpp b/rpcs3/rpcs3qt/gs_frame.cpp index 29d9cfd37d..4a21bfa1ca 100644 --- a/rpcs3/rpcs3qt/gs_frame.cpp +++ b/rpcs3/rpcs3qt/gs_frame.cpp @@ -13,6 +13,7 @@ #include "Emu/Cell/Modules/cellScreenshot.h" #include "Emu/Cell/Modules/cellVideoOut.h" #include "Emu/Cell/Modules/cellAudio.h" +#include "Emu/Cell/lv2/sys_rsxaudio.h" #include "Emu/RSX/rsx_utils.h" #include "Emu/RSX/Overlays/overlay_message.h" #include "Emu/Io/recording_config.h" @@ -504,8 +505,31 @@ void gs_frame::toggle_recording() m_video_encoder->set_max_b_frames(g_cfg_recording.video.max_b_frames); m_video_encoder->set_gop_size(g_cfg_recording.video.gop_size); m_video_encoder->set_output_format(output_format); - m_video_encoder->set_sample_rate(g_fxo->get().cfg.audio_sampling_rate); - m_video_encoder->set_audio_channels(static_cast(g_fxo->get().cfg.audio_channels)); + + switch (g_cfg.audio.provider) + { + case audio_provider::none: + { + // Disable audio recording + m_video_encoder->use_internal_audio = false; + break; + } + case audio_provider::cell_audio: + { + const cell_audio_config& cfg = g_fxo->get().cfg; + m_video_encoder->set_sample_rate(cfg.audio_sampling_rate); + m_video_encoder->set_audio_channels(cfg.audio_channels); + break; + } + case audio_provider::rsxaudio: + { + const auto& rsx_audio = g_fxo->get(); + m_video_encoder->set_sample_rate(rsx_audio.get_sample_rate()); + m_video_encoder->set_audio_channels(rsx_audio.get_channel_count()); + break; + } + } + m_video_encoder->set_audio_bitrate(g_cfg_recording.audio.audio_bps); m_video_encoder->set_audio_codec(g_cfg_recording.audio.audio_codec); m_video_encoder->encode();