diff --git a/libobs/obs-internal.h b/libobs/obs-internal.h index 87a6eba43..5afd05c3b 100644 --- a/libobs/obs-internal.h +++ b/libobs/obs-internal.h @@ -120,6 +120,9 @@ struct obs_core_video { struct obs_core_audio { /* TODO: sound output subsystem */ audio_t audio; + + float user_volume; + float present_volume; }; /* user sources, output channels, and displays */ @@ -204,7 +207,8 @@ struct obs_source { pthread_mutex_t audio_mutex; struct filtered_audio audio_data; size_t audio_storage_size; - float volume; + float user_volume; + float present_volume; /* async video data */ texture_t output_texture; diff --git a/libobs/obs-source.c b/libobs/obs-source.c index 5c6b97a9a..c96b641c3 100644 --- a/libobs/obs-source.c +++ b/libobs/obs-source.c @@ -93,7 +93,8 @@ bool obs_source_init(struct obs_source *source, const struct obs_source_info *info) { source->refs = 1; - source->volume = 1.0f; + source->user_volume = 1.0f; + source->present_volume = 1.0f; pthread_mutex_init_value(&source->filter_mutex); pthread_mutex_init_value(&source->video_mutex); pthread_mutex_init_value(&source->audio_mutex); @@ -388,7 +389,8 @@ static void source_output_audio_line(obs_source_t source, return; in.timestamp += source->timing_adjust; - in.volume = source->volume; + in.volume = source->user_volume * source->present_volume * + obs->audio.user_volume * obs->audio.present_volume; audio_line_output(source->audio_line, &in); } @@ -1129,10 +1131,20 @@ proc_handler_t obs_source_prochandler(obs_source_t source) void obs_source_setvolume(obs_source_t source, float volume) { - source->volume = volume; + source->user_volume = volume; +} + +void obs_source_set_present_volume(obs_source_t source, float volume) +{ + source->present_volume = volume; } float obs_source_getvolume(obs_source_t source) { - return source->volume; + return source->user_volume; +} + +float obs_source_get_present_volume(obs_source_t source) +{ + return source->present_volume; } diff --git a/libobs/obs.c b/libobs/obs.c index 4a2dcf497..1cfbef0be 100644 --- a/libobs/obs.c +++ b/libobs/obs.c @@ -314,6 +314,9 @@ static bool obs_init_audio(struct audio_output_info *ai) /* TODO: sound subsystem */ + audio->user_volume = 1.0f; + audio->present_volume = 1.0f; + errorcode = audio_output_open(&audio->audio, ai); if (errorcode == AUDIO_OUTPUT_SUCCESS) return true; @@ -790,3 +793,25 @@ void obs_render_main_view(void) if (!obs) return; obs_view_render(&obs->data.main_view); } + +void obs_set_master_volume(float volume) +{ + if (!obs) return; + obs->audio.user_volume = volume; +} + +void obs_set_present_volume(float volume) +{ + if (!obs) return; + obs->audio.present_volume = volume; +} + +float obs_get_master_volume(void) +{ + return obs ? obs->audio.user_volume : 0.0f; +} + +float obs_get_present_volume(void) +{ + return obs ? obs->audio.present_volume : 0.0f; +} diff --git a/libobs/obs.h b/libobs/obs.h index 32d3c56ca..fd4f833cf 100644 --- a/libobs/obs.h +++ b/libobs/obs.h @@ -328,6 +328,18 @@ EXPORT void obs_resize(uint32_t cx, uint32_t cy); /** Renders the main view */ EXPORT void obs_render_main_view(void); +/** Sets the master user volume */ +EXPORT void obs_set_master_volume(float volume); + +/** Sets the master presentation volume */ +EXPORT void obs_set_present_volume(float volume); + +/** Gets the master user volume */ +EXPORT float obs_get_master_volume(void); + +/** Gets the master presentation volume */ +EXPORT float obs_get_present_volume(void); + /* ------------------------------------------------------------------------- */ /* View context */ @@ -480,12 +492,18 @@ EXPORT signal_handler_t obs_source_signalhandler(obs_source_t source); /** Returns the procedure handler for a source */ EXPORT proc_handler_t obs_source_prochandler(obs_source_t source); -/** Sets the volume for a source that has audio output */ +/** Sets the user volume for a source that has audio output */ EXPORT void obs_source_setvolume(obs_source_t source, float volume); -/** Gets the volume for a source that has audio output */ +/** Sets the presentation volume for a source */ +EXPORT void obs_source_set_present_volume(obs_source_t source, float volume); + +/** Gets the user volume for a source that has audio output */ EXPORT float obs_source_getvolume(obs_source_t source); +/** Gets the presentation volume for a source */ +EXPORT float obs_source_get_present_volume(obs_source_t source); + /* ------------------------------------------------------------------------- */ /* Functions used by sources */ diff --git a/vs/2013/OBS.sln b/vs/2013/OBS.sln index 23e7f91f4..cc6fabec2 100644 --- a/vs/2013/OBS.sln +++ b/vs/2013/OBS.sln @@ -39,8 +39,6 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "obs-ffmpeg", "obs-ffmpeg\ob EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "obs-studio", "obs-studio\obs-studio.vcxproj", "{B12702AD-ABFB-343A-A199-8E24837244A3}" EndProject -Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{6AE25DF7-A903-48AD-8DA4-9902010AEB11}" -EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Win32 = Debug|Win32