Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions libobs/media-io/audio-resampler-ffmpeg.c
Original file line number Diff line number Diff line change
Expand Up @@ -216,3 +216,27 @@ bool audio_resampler_resample(audio_resampler_t *rs, uint8_t *output[], uint32_t
*out_frames = (uint32_t)ret;
return true;
}

// Allows passing of a matrix for channel re-ordering and custom weights.
bool audio_resampler_set_matrix(audio_resampler_t *rs, double *matrix, int stride)
{
if (!rs) {
return false;
}

swr_close(rs->context);

if (swr_set_matrix(rs->context, matrix, stride) < 0) {
blog(LOG_DEBUG, "swr_set_matrix failed\n");
audio_resampler_destroy(rs);
return false;
}

int errcode = swr_init(rs->context);
if (errcode != 0) {
blog(LOG_ERROR, "swr_init failed: error code %d", errcode);
audio_resampler_destroy(rs);
return false;
}
return true;
}
2 changes: 2 additions & 0 deletions libobs/media-io/audio-resampler.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ EXPORT void audio_resampler_destroy(audio_resampler_t *resampler);
EXPORT bool audio_resampler_resample(audio_resampler_t *resampler, uint8_t *output[], uint32_t *out_frames,
uint64_t *ts_offset, const uint8_t *const input[], uint32_t in_frames);

EXPORT bool audio_resampler_set_matrix(audio_resampler_t *rs, double *matrix, int stride);

#ifdef __cplusplus
}
#endif
1 change: 1 addition & 0 deletions plugins/mac-capture/data/locale/en-US.ini
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ CoreAudio.Channel.Unnamed="Unnamed"
CoreAudio.Channel.Device="Device Channel"
CoreAudio.None="None"
CoreAudio.Downmix="Enable Downmixing"
CoreAudio.Downmix.Hint="By default OBS will automatically upmix or downmix to the number of channels configured in settings. Enabling this setting will allow you to manually select which channels of the device to map to the input in OBS."
ApplicationCapture="Application Capture"
ApplicationAudioCapture="Application Audio Capture"
DesktopAudioCapture="Desktop Audio Capture"
Expand Down
1 change: 1 addition & 0 deletions plugins/mac-capture/mac-audio.c
Original file line number Diff line number Diff line change
Expand Up @@ -1015,6 +1015,7 @@ static obs_properties_t *coreaudio_properties(bool input, void *data)
obs_property_set_modified_callback2(property, coreaudio_device_changed, ca);

property = obs_properties_add_bool(props, "enable_downmix", obs_module_text("CoreAudio.Downmix"));
obs_property_set_long_description(property, obs_module_text("CoreAudio.Downmix.Hint"));
obs_property_set_modified_callback2(property, coreaudio_downmix_changed, ca);

if (ca != NULL && ca->au_initialized) {
Expand Down
11 changes: 11 additions & 0 deletions plugins/win-wasapi/data/locale/en-US.ini
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,14 @@ Priority="Window Match Priority"
Priority.Title="Window title must match"
Priority.Class="Match title, otherwise find window of same type"
Priority.Exe="Match title, otherwise find window of same executable"
Routing="Enable Channel Routing"
Routing.Hint="By default OBS will automatically upmix or downmix to the number of channels configured in settings.\nEnabling this setting will allow you to manually select which channels of the device to map to the input in OBS."
OBS_channel.0="OBS Channel 1"
OBS_channel.1="OBS Channel 2"
OBS_channel.2="OBS Channel 3"
OBS_channel.3="OBS Channel 4"
OBS_channel.4="OBS Channel 5"
OBS_channel.5="OBS Channel 6"
OBS_channel.6="OBS Channel 7"
OBS_channel.7="OBS Channel 8"
None="None"
63 changes: 63 additions & 0 deletions plugins/win-wasapi/enum-wasapi.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "enum-wasapi.hpp"

#include <util/base.h>
#include <util/bmem.h>
#include <util/platform.h>
#include <util/windows/HRError.hpp>
#include <util/windows/ComPtr.hpp>
Expand Down Expand Up @@ -34,6 +35,26 @@ string GetDeviceName(IMMDevice *device)
return device_name;
}

std::string GetWASAPIDefaultDeviceName(bool input)
{
ComPtr<IMMDeviceEnumerator> enumerator;
ComPtr<IMMDevice> device;

HRESULT res = CoCreateInstance(__uuidof(MMDeviceEnumerator), NULL, CLSCTX_ALL, __uuidof(IMMDeviceEnumerator),
(void **)enumerator.Assign());
if (FAILED(res)) {
return "";
}

res = enumerator->GetDefaultAudioEndpoint(input ? eCapture : eRender, input ? eCommunications : eConsole,
device.Assign());
if (FAILED(res)) {
return "";
}

return GetDeviceName(device);
}

static void GetWASAPIAudioDevices_(vector<AudioDeviceInfo> &devices, bool input)
{
ComPtr<IMMDeviceEnumerator> enumerator;
Expand Down Expand Up @@ -90,3 +111,45 @@ void GetWASAPIAudioDevices(vector<AudioDeviceInfo> &devices, bool input)
blog(LOG_WARNING, "[GetWASAPIAudioDevices] %s: %lX", error.str, error.hr);
}
}

int GetWASAPIDeviceInputChannels(const char *device_id)
{
ComPtr<IMMDeviceEnumerator> enumerator;
ComPtr<IMMDevice> device;
ComPtr<IAudioClient> client;
CoTaskMemPtr<WAVEFORMATEX> wfex;

HRESULT res =
CoCreateInstance(__uuidof(MMDeviceEnumerator), nullptr, CLSCTX_ALL, IID_PPV_ARGS(enumerator.Assign()));
if (FAILED(res)) {
return 0;
}

if (strcmp(device_id, "default") == 0) {
res = enumerator->GetDefaultAudioEndpoint(eCapture, eCommunications, device.Assign());
} else {
wchar_t *w_id = nullptr;
os_utf8_to_wcs_ptr(device_id, strlen(device_id), &w_id);
if (!w_id) {
return 0;
}
res = enumerator->GetDevice(w_id, device.Assign());
bfree(w_id);
}

if (FAILED(res) || !device) {
return 0;
}

res = device->Activate(__uuidof(IAudioClient), CLSCTX_ALL, nullptr, (void **)client.Assign());
if (FAILED(res)) {
return 0;
}

res = client->GetMixFormat(&wfex);
if (FAILED(res) || !wfex) {
return 0;
}

return wfex->nChannels;
}
2 changes: 2 additions & 0 deletions plugins/win-wasapi/enum-wasapi.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,6 @@ struct AudioDeviceInfo {
};

std::string GetDeviceName(IMMDevice *device);
std::string GetWASAPIDefaultDeviceName(bool input);
void GetWASAPIAudioDevices(std::vector<AudioDeviceInfo> &devices, bool input);
int GetWASAPIDeviceInputChannels(const char *device_id);
Loading
Loading