mirror of
https://github.com/obsproject/obs-studio.git
synced 2024-07-15 07:44:10 +00:00
Implement volumes for sources
- Added a volume variable to the obs_source structure and implemented functions for manipulating source volume. - Added a volume variable to the audio_data structure so that the volume will be applied when mixing.
This commit is contained in:
parent
4fe3c47216
commit
3838abe1f4
|
@ -60,6 +60,7 @@ struct audio_data {
|
|||
const void *data;
|
||||
uint32_t frames;
|
||||
uint64_t timestamp;
|
||||
float volume;
|
||||
};
|
||||
|
||||
struct audio_info {
|
||||
|
|
|
@ -128,6 +128,7 @@ bool obs_source_init(struct obs_source *source, const char *settings,
|
|||
uint32_t flags = info->get_output_flags(source->data);
|
||||
|
||||
source->refs = 1;
|
||||
source->volume = 1.0f;
|
||||
pthread_mutex_init_value(&source->filter_mutex);
|
||||
pthread_mutex_init_value(&source->video_mutex);
|
||||
pthread_mutex_init_value(&source->audio_mutex);
|
||||
|
@ -349,6 +350,7 @@ static void source_output_audio_line(obs_source_t source,
|
|||
}
|
||||
|
||||
in.timestamp += source->timing_adjust;
|
||||
in.volume = source->volume;
|
||||
audio_line_output(source->audio_line, &in);
|
||||
}
|
||||
|
||||
|
@ -366,6 +368,7 @@ static void obs_source_flush_audio_wait_buffer(obs_source_t source)
|
|||
data.data = buf->data;
|
||||
data.frames = buf->frames;
|
||||
data.timestamp = buf->timestamp + source->timing_adjust;
|
||||
data.volume = source->volume;
|
||||
audio_line_output(source->audio_line, &data);
|
||||
audiobuf_free(buf);
|
||||
}
|
||||
|
@ -864,7 +867,7 @@ void obs_source_output_audio(obs_source_t source,
|
|||
|
||||
/* wait for video to start before outputting any audio so we
|
||||
* have a base for sync */
|
||||
if (!source->timing_set && flags & SOURCE_ASYNC_VIDEO) {
|
||||
if (!source->timing_set && (flags & SOURCE_ASYNC_VIDEO) != 0) {
|
||||
struct audiobuf newbuf;
|
||||
size_t audio_size = blocksize * output->frames;
|
||||
|
||||
|
@ -1058,3 +1061,13 @@ proc_handler_t obs_source_prochandler(obs_source_t source)
|
|||
{
|
||||
return source->procs;
|
||||
}
|
||||
|
||||
void obs_source_setvolume(obs_source_t source, float volume)
|
||||
{
|
||||
source->volume = volume;
|
||||
}
|
||||
|
||||
float obs_source_getvolume(obs_source_t source)
|
||||
{
|
||||
return source->volume;
|
||||
}
|
||||
|
|
|
@ -235,6 +235,7 @@ struct obs_source {
|
|||
pthread_mutex_t audio_mutex;
|
||||
struct filtered_audio audio_data;
|
||||
size_t audio_storage_size;
|
||||
float volume;
|
||||
|
||||
/* async video data */
|
||||
texture_t output_texture;
|
||||
|
|
|
@ -408,6 +408,12 @@ 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 */
|
||||
EXPORT void obs_source_setvolume(obs_source_t source, float volume);
|
||||
|
||||
/** Gets the volume for a source that has audio output */
|
||||
EXPORT float obs_source_getvolume(obs_source_t source);
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
/* Functions used by sources */
|
||||
|
||||
|
|
Loading…
Reference in a new issue