obs-transition: Add crossfade option to stinger

Add option in properties that let you choose how audio is mixed during
transition:
- Fade Out/Fade In (existing behavior, default)
- Crossfade

Closes jp9000/obs-studio#1028
master
Makeenon 2017-09-16 10:11:52 +02:00 committed by jp9000
parent dab278e1b6
commit 006fc35a2d
2 changed files with 59 additions and 3 deletions

View File

@ -17,6 +17,9 @@ TransitionPointFrame="Transition Point (frame)"
TransitionPointType="Transition Point Type"
TransitionPointTypeFrame="Frame"
TransitionPointTypeTime="Time (milliseconds)"
AudioFadeStyle="Audio Fade Style"
AudioFadeStyle.FadeOutFadeIn="Fade out to transition point then fade in"
AudioFadeStyle.CrossFade="Crossfade"
SwitchPoint="Peak Color Point (percentage)"
LumaWipeTransition="Luma Wipe"
LumaWipe.Image="Image"

View File

@ -3,6 +3,11 @@
#define TIMING_TIME 0
#define TIMING_FRAME 1
enum fade_style {
FADE_STYLE_FADE_OUT_FADE_IN,
FADE_STYLE_CROSS_FADE
};
struct stinger_info {
obs_source_t *source;
@ -18,6 +23,10 @@ struct stinger_info {
bool transitioning;
bool transition_point_is_frame;
int monitoring_type;
enum fade_style fade_style;
float (*mix_a)(void *data, float t);
float (*mix_b)(void *data, float t);
};
static const char *stinger_get_name(void *type_data)
@ -26,6 +35,11 @@ static const char *stinger_get_name(void *type_data)
return obs_module_text("StingerTransition");
}
static float mix_a_fade_in_out(void *data, float t);
static float mix_b_fade_in_out(void *data, float t);
static float mix_a_cross_fade(void *data, float t);
static float mix_b_cross_fade(void *data, float t);
static void stinger_update(void *data, obs_data_t *settings)
{
struct stinger_info *s = data;
@ -51,6 +65,21 @@ static void stinger_update(void *data, obs_data_t *settings)
s->monitoring_type = obs_data_get_int(settings,"audio_monitoring");
obs_source_set_monitoring_type(s->media_source, s->monitoring_type);
s->fade_style = (enum fade_style)obs_data_get_int(settings,
"audio_fade_style");
switch (s->fade_style) {
default:
case FADE_STYLE_FADE_OUT_FADE_IN:
s->mix_a = mix_a_fade_in_out;
s->mix_b = mix_b_fade_in_out;
break;
case FADE_STYLE_CROSS_FADE:
s->mix_a = mix_a_cross_fade;
s->mix_b = mix_b_cross_fade;
break;
}
}
static void *stinger_create(obs_data_t *settings, obs_source_t *source)
@ -58,6 +87,8 @@ static void *stinger_create(obs_data_t *settings, obs_source_t *source)
struct stinger_info *s = bzalloc(sizeof(*s));
s->source = source;
s->mix_a = mix_a_fade_in_out;
s->mix_b = mix_b_fade_in_out;
obs_transition_enable_fixed(s->source, true, 0);
obs_source_update(source, settings);
@ -112,18 +143,30 @@ static inline float calc_fade(float t, float mul)
return t > 1.0f ? 1.0f : t;
}
static float mix_a(void *data, float t)
static float mix_a_fade_in_out(void *data, float t)
{
struct stinger_info *s = data;
return 1.0f - calc_fade(t, s->transition_a_mul);
}
static float mix_b(void *data, float t)
static float mix_b_fade_in_out(void *data, float t)
{
struct stinger_info *s = data;
return 1.0f - calc_fade(1.0f - t, s->transition_b_mul);
}
static float mix_a_cross_fade(void *data, float t)
{
UNUSED_PARAMETER(data);
return 1.0f - t;
}
static float mix_b_cross_fade(void *data, float t)
{
UNUSED_PARAMETER(data);
return t;
}
static bool stinger_audio_render(void *data, uint64_t *ts_out,
struct obs_source_audio_mix *audio, uint32_t mixers,
size_t channels, size_t sample_rate)
@ -138,7 +181,7 @@ static bool stinger_audio_render(void *data, uint64_t *ts_out,
}
bool success = obs_transition_audio_render(s->source, ts_out,
audio, mixers, channels, sample_rate, mix_a, mix_b);
audio, mixers, channels, sample_rate, s->mix_a, s->mix_b);
if (!ts)
return success;
@ -296,6 +339,16 @@ static obs_properties_t *stinger_properties(void *data)
obs_module_text("AudioMonitoring.Both"),
OBS_MONITORING_TYPE_MONITOR_AND_OUTPUT);
obs_property_t *audio_fade_style = obs_properties_add_list(ppts,
"audio_fade_style", obs_module_text("AudioFadeStyle"),
OBS_COMBO_TYPE_LIST, OBS_COMBO_FORMAT_INT);
obs_property_list_add_int(audio_fade_style,
obs_module_text("AudioFadeStyle.FadeOutFadeIn"),
FADE_STYLE_FADE_OUT_FADE_IN);
obs_property_list_add_int(audio_fade_style,
obs_module_text("AudioFadeStyle.CrossFade"),
FADE_STYLE_CROSS_FADE);
UNUSED_PARAMETER(data);
return ppts;
}