libdshowcapture icon indicating copy to clipboard operation
libdshowcapture copied to clipboard

setup the desired sampleRate

Open wkpark opened this issue 4 years ago • 2 comments

try to set the desired sampling rate.

Description

this fix try to set the desired sampling rate by modifying nSamplesPerSec

Motivation and Context

I'm not sure but when using a video capture card (MJPEG only ) with a USB audio support (like as ATEM mini) with Custom Audio setting. OBS does not set/report the correct sampling rate for the selected audio device as follows.

20:13:11.138: [DShow Device: 'ATEMMini'] settings updated:
20:13:11.138: video device: Blackmagic Design
...
20:13:11.138: resolution: 1920x1080
20:13:11.138: flip: 0
20:13:11.138: fps: 60.00 (interval: 166667)
20:13:11.138: format: MJPEG
20:13:11.154: using video device audio: no
20:13:11.154: audio device: Mic (Blackmagic Design)
20:13:11.154: separate audio filter
20:13:11.154: sample rate: 44100 // <-- wrong
20:13:11.154: channels: 2
20:13:11.154: audio type: Capture

and the result of this situation (I guess)

  • frequent audio out of sync while broadcasting
  • need to deactivate/activate again and again to make it work properly.

How Has This Been Tested?

  • OBS sampling rate profile: 48 kHz
  • Video/audio capture cards like the Blackmagic Atem mini (Video - MJPEG, Audio - USB audio)
  • Select custom audio device to its USB audio device
  • broadcasting with these settings results in audio quality problems.

Types of changes

This quick hack try to set the desired sampling rate by modifying nSamplesPerSec

See also

  • https://social.msdn.microsoft.com/Forums/windowsdesktop/en-US/9d61c9c0-9e0d-4ed6-81dd-f9f9b174dee5/specifying-audio-settings-bits-sample-rate-etc-when-capturing-video?forum=windowsdirectshowdevelopment
  • https://titanwolf.org/Network/Articles/Article?AID=8cf7dc88-9fe9-4c0e-8a0f-ff484f68e0e4#gsc.tab=0

Checklist:

  • [x] My code has been run through clang-format.
  • [x] I have read the contributing document.
  • [x] My code is not on the master branch.
  • [x] The code has been tested.
  • [x] All commit messages are properly formatted and commits squashed where appropriate.
  • [x] I have included updates to all appropriate documentation.

wkpark avatar Jul 26 '21 14:07 wkpark

What happens if the device doesn't support the requested sample rate?

WizardCM avatar Jul 27 '21 00:07 WizardCM

What happens if the device doesn't support the requested sample rate?

as you know, for this case, SetFormat() will be failed and we can't use the win-dshow plugin (anyway, obs have another audio driver option.)

https://github.com/obsproject/libdshowcapture/pull/33/commits/f3381a7f63ee50dad9ffdd4979deb11bf3a523e6#diff-55b8bf12e74f93879b4bc14277476b5aa7dcee1f47320a76f812a3754f72c85eL472-L480

(line L472-L480)

...
	if (!!pinConfig) {
		hr = pinConfig->SetFormat(audioMediaType);
		if (FAILED(hr) && hr != E_NOTIMPL) {
			Error(L"Could not set audio format");
			return false;
		}
	}
	

wkpark avatar Jul 27 '21 02:07 wkpark