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
This commit is contained in:
@@ -16,6 +16,7 @@
|
||||
|
||||
struct gain_data {
|
||||
obs_source_t *context;
|
||||
size_t channels;
|
||||
float multiple;
|
||||
};
|
||||
|
||||
@@ -35,7 +36,7 @@ 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);
|
||||
|
||||
gf->channels = audio_output_get_channels(obs_get_audio());
|
||||
gf->multiple = db_to_mul((float)val);
|
||||
}
|
||||
|
||||
@@ -51,11 +52,11 @@ static struct obs_audio_data *gain_filter_audio(void *data,
|
||||
struct obs_audio_data *audio)
|
||||
{
|
||||
struct gain_data *gf = data;
|
||||
|
||||
float *adata[2] = {(float*)audio->data[0], (float*)audio->data[1]};
|
||||
const size_t channels = gf->channels;
|
||||
float **adata = (float**)audio->data;
|
||||
const float multiple = gf->multiple;
|
||||
|
||||
for (size_t c = 0; c < 2; c++) {
|
||||
for (size_t c = 0; c < channels; c++) {
|
||||
if (audio->data[c]) {
|
||||
for (size_t i = 0; i < audio->frames; i++) {
|
||||
adata[c][i] *= multiple;
|
||||
|
@@ -109,7 +109,7 @@ static struct obs_audio_data *noise_gate_filter_audio(void *data,
|
||||
{
|
||||
struct noise_gate_data *ng = data;
|
||||
|
||||
float *adata[2] = {(float*)audio->data[0], (float*)audio->data[1]};
|
||||
float **adata = (float**)audio->data;
|
||||
const float close_threshold = ng->close_threshold;
|
||||
const float open_threshold = ng->open_threshold;
|
||||
const float sample_rate_i = ng->sample_rate_i;
|
||||
@@ -120,9 +120,10 @@ static struct obs_audio_data *noise_gate_filter_audio(void *data,
|
||||
const size_t channels = ng->channels;
|
||||
|
||||
for (size_t i = 0; i < audio->frames; i++) {
|
||||
float cur_level = (channels == 2)
|
||||
? fmaxf(fabsf(adata[0][i]), fabsf(adata[1][i]))
|
||||
: fabsf(adata[0][i]);
|
||||
float cur_level = fabsf(adata[0][i]);
|
||||
for (size_t j = 0; j < channels; j++) {
|
||||
cur_level = fmaxf(cur_level, fabsf(adata[j][i]));
|
||||
}
|
||||
|
||||
if (cur_level > open_threshold && !ng->is_open) {
|
||||
ng->is_open = true;
|
||||
|
@@ -27,7 +27,7 @@
|
||||
#define MT_ obs_module_text
|
||||
#define TEXT_SUPPRESS_LEVEL MT_("NoiseSuppress.SuppressLevel")
|
||||
|
||||
#define MAX_PREPROC_CHANNELS 2
|
||||
#define MAX_PREPROC_CHANNELS 8
|
||||
|
||||
/* -------------------------------------------------------- */
|
||||
|
||||
@@ -120,12 +120,12 @@ static void noise_suppress_update(void *data, obs_data_t *s)
|
||||
/* One speex state for each channel (limit 2) */
|
||||
ng->copy_buffers[0] = bmalloc(frames * channels * sizeof(float));
|
||||
ng->segment_buffers[0] = bmalloc(frames * channels * sizeof(spx_int16_t));
|
||||
|
||||
if (channels == 2) {
|
||||
ng->copy_buffers[1] = ng->copy_buffers[0] + frames;
|
||||
ng->segment_buffers[1] = ng->segment_buffers[0] + frames;
|
||||
for (size_t c = 1; c < channels; ++c) {
|
||||
ng->copy_buffers[c] = ng->copy_buffers[c-1] + frames;
|
||||
ng->segment_buffers[c] = ng->segment_buffers[c-1] + frames;
|
||||
}
|
||||
|
||||
|
||||
for (size_t i = 0; i < channels; i++)
|
||||
alloc_channel(ng, sample_rate, i, frames);
|
||||
}
|
||||
|
Reference in New Issue
Block a user