Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Recording: Implement audio recording for rsx audio #14856

Merged
merged 1 commit into from Nov 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions rpcs3/Emu/Cell/Modules/cellAudio.cpp
Expand Up @@ -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<utils::video_provider>();
provider.present_samples(reinterpret_cast<u8*>(buf), sample_cnt, static_cast<u32>(cfg.audio_channels));
provider.present_samples(reinterpret_cast<u8*>(buf), sample_cnt, cfg.audio_channels);
}

// Downmix if necessary
Expand Down Expand Up @@ -1004,7 +1004,7 @@ void cell_audio_thread::operator()()
break;

default:
fmt::throw_exception("Unsupported channel count in cell_audio_config: %d", static_cast<u32>(cfg.audio_channels));
fmt::throw_exception("Unsupported channel count in cell_audio_config: %d", cfg.audio_channels);
}

// Enqueue
Expand Down
24 changes: 23 additions & 1 deletion rpcs3/Emu/Cell/lv2/sys_rsxaudio.cpp
Expand Up @@ -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"
Expand All @@ -22,6 +23,8 @@

LOG_CHANNEL(sys_rsxaudio);

extern atomic_t<recording_mode> g_recording_mode;

namespace rsxaudio_ringbuf_reader
{
static constexpr void clean_buf(rsxaudio_shmem::ringbuf_t& ring_buf)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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<u32>(crnt_buf_size));
Expand Down Expand Up @@ -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<utils::video_provider>();
provider.present_samples(reinterpret_cast<u8*>(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());

Expand Down
3 changes: 3 additions & 0 deletions rpcs3/Emu/Cell/lv2/sys_rsxaudio.h
Expand Up @@ -458,6 +458,9 @@ class rsxaudio_backend_thread

void update_emu_cfg();

u32 get_sample_rate() const;
u8 get_channel_count() const;

static constexpr auto thread_name = "RsxAudio Backend Thread"sv;

private:
Expand Down
28 changes: 26 additions & 2 deletions rpcs3/rpcs3qt/gs_frame.cpp
Expand Up @@ -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"
Expand Down Expand Up @@ -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<cell_audio>().cfg.audio_sampling_rate);
m_video_encoder->set_audio_channels(static_cast<u32>(g_fxo->get<cell_audio>().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<cell_audio>().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<rsx_audio_backend>();
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();
Expand Down