2015-06-26 05:31:30 -07:00
|
|
|
#include <obs-module.h>
|
|
|
|
#include <media-io/audio-math.h>
|
|
|
|
#include <math.h>
|
|
|
|
|
2019-06-22 22:13:45 -07:00
|
|
|
#define do_log(level, format, ...) \
|
2015-06-26 05:31:30 -07:00
|
|
|
blog(level, "[gain filter: '%s'] " format, \
|
2019-06-22 22:13:45 -07:00
|
|
|
obs_source_get_name(gf->context), ##__VA_ARGS__)
|
2015-06-26 05:31:30 -07:00
|
|
|
|
2019-06-22 22:13:45 -07:00
|
|
|
#define warn(format, ...) do_log(LOG_WARNING, format, ##__VA_ARGS__)
|
|
|
|
#define info(format, ...) do_log(LOG_INFO, format, ##__VA_ARGS__)
|
2015-06-26 05:31:30 -07:00
|
|
|
|
2019-06-22 22:13:45 -07:00
|
|
|
#define S_GAIN_DB "db"
|
2015-06-26 05:31:30 -07:00
|
|
|
|
|
|
|
#define MT_ obs_module_text
|
2019-06-22 22:13:45 -07:00
|
|
|
#define TEXT_GAIN_DB MT_("Gain.GainDB")
|
2015-06-26 05:31:30 -07:00
|
|
|
|
|
|
|
struct gain_data {
|
|
|
|
obs_source_t *context;
|
libobs: Add surround sound audio support
(This commit also modifies the following modules: UI,
deps/media-playback, coreaudio-encoder, decklink, linux-alsa,
linux-pulseaudio, mac-capture, obs-ffmpeg, obs-filters, obs-libfdk,
obs-outputs, win-dshow, and win-wasapi)
Adds surround sound audio support to the core, core plugins, and user
interface.
Compatible streaming services: Twitch, FB 360 live
Compatible protocols: rtmp / mpeg-ts tcp udp
Compatible file formats: mkv mp4 ts (others untested)
Compatible codecs: ffmpeg aac, fdk_aac, CoreAudio aac,
opus, vorbis, pcm (others untested).
Tested streaming servers: wowza, nginx
HLS, mpeg-dash : surround passthrough
Html5 players tested with live surround:
videojs, mediaelement, viblast (hls+dash), hls.js
Decklink: on win32, swap channels order for 5.1 7.1
(due to different channel mapping on wav, mpeg, ffmpeg)
Audio filters: surround working.
Monitoring: surround working (win macOs linux (pulse-audio)).
VST: stereo plugins keep in general only the first two channels.
surround plugins should work (e.g. mcfx does).
OS: win, macOs, linux (alsa, pulse-audio).
Misc: larger audio bitrates unlocked to accommodate more channels
NB: mf-aac only supports mono and stereo + 5.1 on win 10
(not implemented due to lack of usefulness)
Closes jp9000/obs-studio#968
2017-05-26 17:15:54 -07:00
|
|
|
size_t channels;
|
2015-06-26 05:31:30 -07:00
|
|
|
float multiple;
|
|
|
|
};
|
|
|
|
|
2015-09-16 01:30:51 -07:00
|
|
|
static const char *gain_name(void *unused)
|
2015-06-26 05:31:30 -07:00
|
|
|
{
|
2015-09-16 01:30:51 -07:00
|
|
|
UNUSED_PARAMETER(unused);
|
2015-06-26 05:31:30 -07:00
|
|
|
return obs_module_text("Gain");
|
|
|
|
}
|
|
|
|
|
|
|
|
static void gain_destroy(void *data)
|
|
|
|
{
|
|
|
|
struct gain_data *gf = data;
|
|
|
|
bfree(gf);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void gain_update(void *data, obs_data_t *s)
|
|
|
|
{
|
|
|
|
struct gain_data *gf = data;
|
|
|
|
double val = obs_data_get_double(s, S_GAIN_DB);
|
libobs: Add surround sound audio support
(This commit also modifies the following modules: UI,
deps/media-playback, coreaudio-encoder, decklink, linux-alsa,
linux-pulseaudio, mac-capture, obs-ffmpeg, obs-filters, obs-libfdk,
obs-outputs, win-dshow, and win-wasapi)
Adds surround sound audio support to the core, core plugins, and user
interface.
Compatible streaming services: Twitch, FB 360 live
Compatible protocols: rtmp / mpeg-ts tcp udp
Compatible file formats: mkv mp4 ts (others untested)
Compatible codecs: ffmpeg aac, fdk_aac, CoreAudio aac,
opus, vorbis, pcm (others untested).
Tested streaming servers: wowza, nginx
HLS, mpeg-dash : surround passthrough
Html5 players tested with live surround:
videojs, mediaelement, viblast (hls+dash), hls.js
Decklink: on win32, swap channels order for 5.1 7.1
(due to different channel mapping on wav, mpeg, ffmpeg)
Audio filters: surround working.
Monitoring: surround working (win macOs linux (pulse-audio)).
VST: stereo plugins keep in general only the first two channels.
surround plugins should work (e.g. mcfx does).
OS: win, macOs, linux (alsa, pulse-audio).
Misc: larger audio bitrates unlocked to accommodate more channels
NB: mf-aac only supports mono and stereo + 5.1 on win 10
(not implemented due to lack of usefulness)
Closes jp9000/obs-studio#968
2017-05-26 17:15:54 -07:00
|
|
|
gf->channels = audio_output_get_channels(obs_get_audio());
|
2015-06-26 05:31:30 -07:00
|
|
|
gf->multiple = db_to_mul((float)val);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void *gain_create(obs_data_t *settings, obs_source_t *filter)
|
|
|
|
{
|
|
|
|
struct gain_data *gf = bzalloc(sizeof(*gf));
|
|
|
|
gf->context = filter;
|
|
|
|
gain_update(gf, settings);
|
|
|
|
return gf;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct obs_audio_data *gain_filter_audio(void *data,
|
2019-06-22 22:13:45 -07:00
|
|
|
struct obs_audio_data *audio)
|
2015-06-26 05:31:30 -07:00
|
|
|
{
|
|
|
|
struct gain_data *gf = data;
|
libobs: Add surround sound audio support
(This commit also modifies the following modules: UI,
deps/media-playback, coreaudio-encoder, decklink, linux-alsa,
linux-pulseaudio, mac-capture, obs-ffmpeg, obs-filters, obs-libfdk,
obs-outputs, win-dshow, and win-wasapi)
Adds surround sound audio support to the core, core plugins, and user
interface.
Compatible streaming services: Twitch, FB 360 live
Compatible protocols: rtmp / mpeg-ts tcp udp
Compatible file formats: mkv mp4 ts (others untested)
Compatible codecs: ffmpeg aac, fdk_aac, CoreAudio aac,
opus, vorbis, pcm (others untested).
Tested streaming servers: wowza, nginx
HLS, mpeg-dash : surround passthrough
Html5 players tested with live surround:
videojs, mediaelement, viblast (hls+dash), hls.js
Decklink: on win32, swap channels order for 5.1 7.1
(due to different channel mapping on wav, mpeg, ffmpeg)
Audio filters: surround working.
Monitoring: surround working (win macOs linux (pulse-audio)).
VST: stereo plugins keep in general only the first two channels.
surround plugins should work (e.g. mcfx does).
OS: win, macOs, linux (alsa, pulse-audio).
Misc: larger audio bitrates unlocked to accommodate more channels
NB: mf-aac only supports mono and stereo + 5.1 on win 10
(not implemented due to lack of usefulness)
Closes jp9000/obs-studio#968
2017-05-26 17:15:54 -07:00
|
|
|
const size_t channels = gf->channels;
|
2019-06-22 22:13:45 -07:00
|
|
|
float **adata = (float **)audio->data;
|
2015-06-26 05:31:30 -07:00
|
|
|
const float multiple = gf->multiple;
|
|
|
|
|
libobs: Add surround sound audio support
(This commit also modifies the following modules: UI,
deps/media-playback, coreaudio-encoder, decklink, linux-alsa,
linux-pulseaudio, mac-capture, obs-ffmpeg, obs-filters, obs-libfdk,
obs-outputs, win-dshow, and win-wasapi)
Adds surround sound audio support to the core, core plugins, and user
interface.
Compatible streaming services: Twitch, FB 360 live
Compatible protocols: rtmp / mpeg-ts tcp udp
Compatible file formats: mkv mp4 ts (others untested)
Compatible codecs: ffmpeg aac, fdk_aac, CoreAudio aac,
opus, vorbis, pcm (others untested).
Tested streaming servers: wowza, nginx
HLS, mpeg-dash : surround passthrough
Html5 players tested with live surround:
videojs, mediaelement, viblast (hls+dash), hls.js
Decklink: on win32, swap channels order for 5.1 7.1
(due to different channel mapping on wav, mpeg, ffmpeg)
Audio filters: surround working.
Monitoring: surround working (win macOs linux (pulse-audio)).
VST: stereo plugins keep in general only the first two channels.
surround plugins should work (e.g. mcfx does).
OS: win, macOs, linux (alsa, pulse-audio).
Misc: larger audio bitrates unlocked to accommodate more channels
NB: mf-aac only supports mono and stereo + 5.1 on win 10
(not implemented due to lack of usefulness)
Closes jp9000/obs-studio#968
2017-05-26 17:15:54 -07:00
|
|
|
for (size_t c = 0; c < channels; c++) {
|
2015-06-26 05:31:30 -07:00
|
|
|
if (audio->data[c]) {
|
|
|
|
for (size_t i = 0; i < audio->frames; i++) {
|
|
|
|
adata[c][i] *= multiple;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return audio;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void gain_defaults(obs_data_t *s)
|
|
|
|
{
|
|
|
|
obs_data_set_default_double(s, S_GAIN_DB, 0.0f);
|
|
|
|
}
|
|
|
|
|
|
|
|
static obs_properties_t *gain_properties(void *data)
|
|
|
|
{
|
|
|
|
obs_properties_t *ppts = obs_properties_create();
|
|
|
|
|
2019-07-18 00:38:50 -07:00
|
|
|
obs_property_t *p = obs_properties_add_float_slider(
|
|
|
|
ppts, S_GAIN_DB, TEXT_GAIN_DB, -30.0, 30.0, 0.1);
|
|
|
|
obs_property_float_set_suffix(p, " dB");
|
2015-06-26 05:31:30 -07:00
|
|
|
|
|
|
|
UNUSED_PARAMETER(data);
|
|
|
|
return ppts;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct obs_source_info gain_filter = {
|
|
|
|
.id = "gain_filter",
|
|
|
|
.type = OBS_SOURCE_TYPE_FILTER,
|
|
|
|
.output_flags = OBS_SOURCE_AUDIO,
|
|
|
|
.get_name = gain_name,
|
|
|
|
.create = gain_create,
|
|
|
|
.destroy = gain_destroy,
|
|
|
|
.update = gain_update,
|
|
|
|
.filter_audio = gain_filter_audio,
|
|
|
|
.get_defaults = gain_defaults,
|
|
|
|
.get_properties = gain_properties,
|
|
|
|
};
|