mirror of
https://github.com/KartKrewDev/RingRacers.git
synced 2025-10-30 08:01:28 +00:00
sdl/new_sound.cpp: record audio with AVRecorder
This commit is contained in:
parent
c65f4ff893
commit
fa0071e785
3 changed files with 22 additions and 0 deletions
|
|
@ -55,6 +55,10 @@ void I_StartupSound(void);
|
||||||
*/
|
*/
|
||||||
void I_ShutdownSound(void);
|
void I_ShutdownSound(void);
|
||||||
|
|
||||||
|
/** \brief Update instance of AVRecorder for audio capture.
|
||||||
|
*/
|
||||||
|
void I_UpdateAudioRecorder(void);
|
||||||
|
|
||||||
/// ------------------------
|
/// ------------------------
|
||||||
/// SFX I/O
|
/// SFX I/O
|
||||||
/// ------------------------
|
/// ------------------------
|
||||||
|
|
|
||||||
|
|
@ -171,6 +171,8 @@ boolean M_AVRecorder_Open(const char* filename)
|
||||||
|
|
||||||
g_av_recorder = std::make_shared<AVRecorder>(cfg);
|
g_av_recorder = std::make_shared<AVRecorder>(cfg);
|
||||||
|
|
||||||
|
I_UpdateAudioRecorder();
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
catch (const std::exception& ex)
|
catch (const std::exception& ex)
|
||||||
|
|
@ -183,6 +185,8 @@ boolean M_AVRecorder_Open(const char* filename)
|
||||||
void M_AVRecorder_Close(void)
|
void M_AVRecorder_Close(void)
|
||||||
{
|
{
|
||||||
g_av_recorder.reset();
|
g_av_recorder.reset();
|
||||||
|
|
||||||
|
I_UpdateAudioRecorder();
|
||||||
}
|
}
|
||||||
|
|
||||||
const char* M_AVRecorder_GetFileExtension(void)
|
const char* M_AVRecorder_GetFileExtension(void)
|
||||||
|
|
|
||||||
|
|
@ -21,6 +21,7 @@
|
||||||
#include "../audio/sound_effect_player.hpp"
|
#include "../audio/sound_effect_player.hpp"
|
||||||
#include "../cxxutil.hpp"
|
#include "../cxxutil.hpp"
|
||||||
#include "../io/streams.hpp"
|
#include "../io/streams.hpp"
|
||||||
|
#include "../m_avrecorder.hpp"
|
||||||
|
|
||||||
#include "../doomdef.h"
|
#include "../doomdef.h"
|
||||||
#include "../i_sound.h"
|
#include "../i_sound.h"
|
||||||
|
|
@ -57,6 +58,8 @@ static shared_ptr<Gain<2>> gain_music;
|
||||||
|
|
||||||
static vector<shared_ptr<SoundEffectPlayer>> sound_effect_channels;
|
static vector<shared_ptr<SoundEffectPlayer>> sound_effect_channels;
|
||||||
|
|
||||||
|
static shared_ptr<srb2::media::AVRecorder> av_recorder;
|
||||||
|
|
||||||
static void (*music_fade_callback)();
|
static void (*music_fade_callback)();
|
||||||
|
|
||||||
void* I_GetSfx(sfxinfo_t* sfx)
|
void* I_GetSfx(sfxinfo_t* sfx)
|
||||||
|
|
@ -135,6 +138,9 @@ void audio_callback(void* userdata, Uint8* buffer, int len)
|
||||||
std::clamp(float_buffer[i].amplitudes[1], -1.f, 1.f),
|
std::clamp(float_buffer[i].amplitudes[1], -1.f, 1.f),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (av_recorder)
|
||||||
|
av_recorder->push_audio_samples(tcb::span {float_buffer, float_len});
|
||||||
}
|
}
|
||||||
catch (...)
|
catch (...)
|
||||||
{
|
{
|
||||||
|
|
@ -749,3 +755,11 @@ boolean I_FadeInPlaySong(UINT32 ms, boolean looping)
|
||||||
else
|
else
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void I_UpdateAudioRecorder(void)
|
||||||
|
{
|
||||||
|
// must be locked since av_recorder is used by audio_callback
|
||||||
|
SdlAudioLockHandle _;
|
||||||
|
|
||||||
|
av_recorder = g_av_recorder;
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue