Setup the desired sampleRate #33

Open
wkpark wants to merge 1 commit from wkpark/samplerate into master
wkpark commented 2021-07-26 09:16:08 -05:00 (Migrated from github.com)

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

Checklist:

  • My code has been run through clang-format.
  • I have read the contributing document.
  • My code is not on the master branch.
  • The code has been tested.
  • All commit messages are properly formatted and commits squashed where appropriate.
  • I have included updates to all appropriate documentation.
<!--- Please fill out the following template, which will help other contributors review your Pull Request. --> <!--- Make sure you’ve read the contribution guidelines here: https://github.com/obsproject/obs-studio/blob/master/CONTRIBUTING.rst --> try to set the desired sampling rate. ### Description <!--- Describe your changes in detail. --> <!--- If this change includes UI elements, please include screenshots. --> this fix try to set the desired sampling rate by modifying `nSamplesPerSec` ### Motivation and Context <!--- Why is this change required? What problem does it solve? --> <!--- If it fixes an open GitHub Issue, or implements feature request --> <!--- from the Ideas page, please link to the issue here. --> 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? <!--- Please describe in detail how you tested your changes. --> <!--- Include details of your testing environment (hardware, OS version, etc.),--> <!--- and the tests you ran, including how it may affect other areas of code. --> * 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 <!--- What types of changes does your PR introduce? Uncomment all that apply --> <!--- - Bug fix (non-breaking change which fixes an issue) --> <!--- - New feature (non-breaking change which adds functionality) --> <!--- - Performance enhancement (non-breaking change which improves efficiency) --> <!--- - Code cleanup (non-breaking change which makes code smaller or more readable) --> <!--- - Breaking change (fix or feature that would cause existing functionality to change) --> <!--- - Documentation (a change to documentation pages) --> 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: <!--- Go over all the following points, and put an `x` in all the boxes that apply. --> <!--- If you're unsure about any of these, don't hesitate to ask. We're here to help! --> - [x] My code has been run through [clang-format](https://github.com/obsproject/obs-studio/blob/master/.clang-format). - [x] I have read the [**contributing** document](https://github.com/obsproject/obs-studio/blob/master/CONTRIBUTING.rst). - [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.
WizardCM commented 2021-07-26 19:07:15 -05:00 (Migrated from github.com)

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

What happens if the device doesn't support the requested sample rate?
wkpark commented 2021-07-26 21:16:20 -05:00 (Migrated from github.com)

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;
		}
	}
	
> 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) ~~~cpp ... if (!!pinConfig) { hr = pinConfig->SetFormat(audioMediaType); if (FAILED(hr) && hr != E_NOTIMPL) { Error(L"Could not set audio format"); return false; } } ~~~
This pull request is broken due to missing fork information.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'wkpark/samplerate:wkpark/samplerate'
git switch 'wkpark/samplerate'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'master'
git merge --no-ff 'wkpark/samplerate'
git switch 'wkpark/samplerate'
git rebase 'master'
git switch 'master'
git merge --ff-only 'wkpark/samplerate'
git switch 'wkpark/samplerate'
git rebase 'master'
git switch 'master'
git merge --no-ff 'wkpark/samplerate'
git switch 'master'
git merge --squash 'wkpark/samplerate'
git switch 'master'
git merge --ff-only 'wkpark/samplerate'
git switch 'master'
git merge 'wkpark/samplerate'
git push origin 'master'
Sign in to join this conversation.
No reviewers
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
gh-obsproject/libdshowcapture!33
No description provided.