Skip to content

Commit 4a4f537

Browse files
committed
recording: Implement audio recording for rsx audio
1 parent 44585b9 commit 4a4f537

File tree

4 files changed

+54
-5
lines changed

4 files changed

+54
-5
lines changed

rpcs3/Emu/Cell/Modules/cellAudio.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ void audio_ringbuffer::commit_data(f32* buf, u32 sample_cnt)
295295
if (g_recording_mode != recording_mode::stopped)
296296
{
297297
utils::video_provider& provider = g_fxo->get<utils::video_provider>();
298-
provider.present_samples(reinterpret_cast<u8*>(buf), sample_cnt, static_cast<u32>(cfg.audio_channels));
298+
provider.present_samples(reinterpret_cast<u8*>(buf), sample_cnt, cfg.audio_channels);
299299
}
300300

301301
// Downmix if necessary
@@ -1004,7 +1004,7 @@ void cell_audio_thread::operator()()
10041004
break;
10051005

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

10101010
// Enqueue

rpcs3/Emu/Cell/lv2/sys_rsxaudio.cpp

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#include "Emu/IdManager.h"
44
#include "Emu/System.h"
55
#include "Emu/system_config.h"
6+
#include "util/video_provider.h"
67

78
#include "sys_process.h"
89
#include "sys_rsxaudio.h"
@@ -22,6 +23,8 @@
2223

2324
LOG_CHANNEL(sys_rsxaudio);
2425

26+
extern atomic_t<recording_mode> g_recording_mode;
27+
2528
namespace rsxaudio_ringbuf_reader
2629
{
2730
static constexpr void clean_buf(rsxaudio_shmem::ringbuf_t& ring_buf)
@@ -1353,6 +1356,16 @@ void rsxaudio_backend_thread::update_emu_cfg()
13531356
}
13541357
}
13551358

1359+
u32 rsxaudio_backend_thread::get_sample_rate() const
1360+
{
1361+
return callback_cfg.load().freq;
1362+
}
1363+
1364+
u8 rsxaudio_backend_thread::get_channel_count() const
1365+
{
1366+
return callback_cfg.load().input_ch_cnt;
1367+
}
1368+
13561369
rsxaudio_backend_thread::emu_audio_cfg rsxaudio_backend_thread::get_emu_cfg()
13571370
{
13581371
// Get max supported channel count
@@ -1466,7 +1479,8 @@ void rsxaudio_backend_thread::operator()()
14661479
state_update_c.wait(state_update_m, ERROR_SERVICE_PERIOD);
14671480
break;
14681481
}
1469-
else if (use_aux_ringbuf)
1482+
1483+
if (use_aux_ringbuf)
14701484
{
14711485
const u64 next_period_time = get_time_until_service();
14721486
should_service_stream = next_period_time <= SERVICE_THRESHOLD;
@@ -1570,6 +1584,7 @@ void rsxaudio_backend_thread::operator()()
15701584
crnt_buf_size = sample_cnt * bytes_per_sample;
15711585
}
15721586

1587+
// Dump audio if enabled
15731588
if (emu_cfg.dump_to_file)
15741589
{
15751590
dumper.WriteData(crnt_buf, static_cast<u32>(crnt_buf_size));
@@ -1842,6 +1857,13 @@ u32 rsxaudio_backend_thread::write_data_callback(u32 bytes, void* buf)
18421857
return bytes;
18431858
}
18441859

1860+
// Record audio if enabled
1861+
if (g_recording_mode != recording_mode::stopped)
1862+
{
1863+
utils::video_provider& provider = g_fxo->get<utils::video_provider>();
1864+
provider.present_samples(reinterpret_cast<u8*>(callback_tmp_buf.data()), sample_cnt / cb_cfg.input_ch_cnt, cb_cfg.input_ch_cnt);
1865+
}
1866+
18451867
// Downmix if necessary
18461868
AudioBackend::downmix(sample_cnt, cb_cfg.input_ch_cnt, cb_cfg.output_ch_cnt, callback_tmp_buf.data(), callback_tmp_buf.data());
18471869

rpcs3/Emu/Cell/lv2/sys_rsxaudio.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -458,6 +458,9 @@ class rsxaudio_backend_thread
458458

459459
void update_emu_cfg();
460460

461+
u32 get_sample_rate() const;
462+
u8 get_channel_count() const;
463+
461464
static constexpr auto thread_name = "RsxAudio Backend Thread"sv;
462465

463466
private:

rpcs3/rpcs3qt/gs_frame.cpp

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include "Emu/Cell/Modules/cellScreenshot.h"
1414
#include "Emu/Cell/Modules/cellVideoOut.h"
1515
#include "Emu/Cell/Modules/cellAudio.h"
16+
#include "Emu/Cell/lv2/sys_rsxaudio.h"
1617
#include "Emu/RSX/rsx_utils.h"
1718
#include "Emu/RSX/Overlays/overlay_message.h"
1819
#include "Emu/Io/recording_config.h"
@@ -504,8 +505,31 @@ void gs_frame::toggle_recording()
504505
m_video_encoder->set_max_b_frames(g_cfg_recording.video.max_b_frames);
505506
m_video_encoder->set_gop_size(g_cfg_recording.video.gop_size);
506507
m_video_encoder->set_output_format(output_format);
507-
m_video_encoder->set_sample_rate(g_fxo->get<cell_audio>().cfg.audio_sampling_rate);
508-
m_video_encoder->set_audio_channels(static_cast<u32>(g_fxo->get<cell_audio>().cfg.audio_channels));
508+
509+
switch (g_cfg.audio.provider)
510+
{
511+
case audio_provider::none:
512+
{
513+
// Disable audio recording
514+
m_video_encoder->use_internal_audio = false;
515+
break;
516+
}
517+
case audio_provider::cell_audio:
518+
{
519+
const cell_audio_config& cfg = g_fxo->get<cell_audio>().cfg;
520+
m_video_encoder->set_sample_rate(cfg.audio_sampling_rate);
521+
m_video_encoder->set_audio_channels(cfg.audio_channels);
522+
break;
523+
}
524+
case audio_provider::rsxaudio:
525+
{
526+
const auto& rsx_audio = g_fxo->get<rsx_audio_backend>();
527+
m_video_encoder->set_sample_rate(rsx_audio.get_sample_rate());
528+
m_video_encoder->set_audio_channels(rsx_audio.get_channel_count());
529+
break;
530+
}
531+
}
532+
509533
m_video_encoder->set_audio_bitrate(g_cfg_recording.audio.audio_bps);
510534
m_video_encoder->set_audio_codec(g_cfg_recording.audio.audio_codec);
511535
m_video_encoder->encode();

0 commit comments

Comments
 (0)