BlackHole icon indicating copy to clipboard operation
BlackHole copied to clipboard

Control for pitch adjust

Open HEnquist opened this issue 3 years ago • 15 comments

This is a prototype that exposes a control for adjusting the sample rate of the Blackhole device by +- 1%. This functionality is provided by the standard Alsa loopback device on Linux, and is very useful for syncing the loopback to other things, that may or may not be another Alsa device.

For now it uses the balance control of the playback side for the control. The balance control is perhaps not the ideal choice., but I have not yet figured out how to (and if it's possible) to add a custom control.

Would you be willing to include something like this in Blackhole?

HEnquist avatar Feb 07 '22 20:02 HEnquist

CLA assistant check
All committers have signed the CLA.

CLAassistant avatar Feb 07 '22 20:02 CLAassistant

Any input on this? Do I need to read and agree to the long CLA first?

HEnquist avatar Feb 25 '22 09:02 HEnquist

Sorry I can’t even look at anything without the CLA signed. I License BlackHole to 3rd parties and I want to avoid any copyright infringement.

Devin On Feb 25, 2022, 1:17 AM -0800, Henrik Enquist @.***>, wrote:

Any input on this? Do I need to read and agree to the long CLA first? — Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you are subscribed to this thread.Message ID: @.***>

devinroth avatar Feb 26 '22 18:02 devinroth

Alright, understood. I just find these legal things so tedious, but I have read and signed it now.

HEnquist avatar Feb 26 '22 19:02 HEnquist

This is interesting. Yes a custom control would be a better solution. I'm curious on how this would be implemented. Would you just monitor the clocks of BlackHole and another device and adjust BlackHole when it starts to drift?

My solution, was to synchronize BlackHole clock with that of a different audio device. That's still in development but there were a couple hiccups that need to be ironed out.

devinroth avatar Mar 11 '22 05:03 devinroth

I basically record from one device, do some processing on the audio data, push it to a buffer, and play it back on another device from that buffer. At the same time I monitor how many frames I have in the buffer. If it's lower or higher that the target value, I adjust the speed of the capture device to keep the level constant. When the capture device is an Alsa loopback (on Linux), I adjust the virtual clock of that device. When it's anything else, I instead insert an asynchronous resampler that I adjust. If Blackhole is also adjustable, then I can get rid of this resampler on MacOs too.

I'll continue and try to figure out how to add custom controls then. I think this adjust feature would coexist nicely with your other option of locking the clock to another device.

HEnquist avatar Mar 11 '22 13:03 HEnquist

BTW I'm struggling with finding relevant coreaudio documentation. Does anyone have any advice on where to find something? A book perhaps?

HEnquist avatar Mar 12 '22 10:03 HEnquist

I was thinking AudioSliderControl but just reading the docs it looks like it only uses UInt32. You probably want to use a float.

So maybe your idea of using the AudioStereoControlPan is the best. Doesn’t look like there’s much customizability with these built-in controls unfortunately.

Devin On Mar 12, 2022, 2:28 AM -0800, Henrik Enquist @.***>, wrote:

BTW I'm struggling with finding relevant coreaudio documentation. Does anyone have any advice on where to find something? A book perhaps? — Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you commented.Message ID: @.***>

devinroth avatar Mar 16 '22 19:03 devinroth

Uint32 should be just fine! I think an allowed range of +-1% is reasonable. Dividing that up into 2^32 steps already gives more precision than needed. I think I have figured out how to add custom controls. Will try it as soon as I have a little time.

HEnquist avatar Mar 16 '22 20:03 HEnquist

It seems like custom controls are not shown in Audio Midi Setup. I think the rate control should be accessible from there, if not it needs some app to expose it to the user. I have only managed to get it to show the stereo pan control. This works but it might be a bit confusing that the pitch is called "Balance". I have tried changing that label but without success. I just want a slider called pitch, do you have any ideas for how to achieve that?

HEnquist avatar Mar 19 '22 07:03 HEnquist

I'm guessing that Audio Midi Setup only checks for (and shows) a few different standard controls. It doesn't seem to be possible to customize those with names etc (or at least I haven't managed). What do you prefer, using an existing control like "Balance" and living with the risk of confusion, or adding a custom control and bundling Blackhole with a small app (tiny GUI or cli tool) to access the control?

HEnquist avatar Mar 20 '22 19:03 HEnquist

Just had a (maybe) good idea. What if we add a ClockSource control, with two values called something like "InternalFixed" and "InternalAdjustable"? Default is "InternalFixed" where everything is the same as before, and "InternalAdjustable" enables adjusting via the pan control. And later the list can be extended with the other devices for syncing the clock to another device.

HEnquist avatar Mar 29 '22 11:03 HEnquist

THere’s actually a clock source control that I was going to use for external syncing.

Devin On Mar 29, 2022, 4:36 AM -0700, Henrik Enquist @.***>, wrote:

Just had a (maybe) good idea. What if we add a ClockSource control, with two values called something like "InternalFixed" and "InternalAdjustable"? Default is "InternalFixed" where everything is the same as before, and "InternalAdjustable" enables adjusting via the pan control. And later the list can be extended with the other devices for syncing the clock to another device. — Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you commented.Message ID: @.***>

devinroth avatar Apr 03 '22 19:04 devinroth

will there still be an update on this feature?

Wang-Yue avatar Jun 03 '22 14:06 Wang-Yue

will there still be an update on this feature?

I will finish it! I just haven't had enough free time lately.

HEnquist avatar Jun 03 '22 20:06 HEnquist

Rebased on current master. I had to change the os target version back to 11.1 since my old Mac can't run the latest Xcode. This is a bit annoying since it meant I had to rename kAudioObjectPropertyElementMain back to the old kAudioObjectPropertyElementMaster to be able to compile. Is it ok if I leave it like this in the PR?

I haven't looked at the clock source selection yet. Should I continue using the balance control for the rate, and add the clock source selection as I suggested before? Just want to confirm this before I start any work.

HEnquist avatar Oct 12 '22 20:10 HEnquist

Why not do something like define kAudioObjectPropertyElementMain = kAudioObjectPropertyElementMaster if target is below a certain macOS version? Then it works in all instances.

devinroth avatar Oct 13 '22 00:10 devinroth

Why not do something like define kAudioObjectPropertyElementMain = kAudioObjectPropertyElementMaster if target is below a certain macOS version? Then it works in all instances.

Good idea, done!

I'm still wondering about the clock source select and use of the pan control, can you please share your view on that?

HEnquist avatar Oct 13 '22 21:10 HEnquist

The changes for adding a clock source selection are here: https://github.com/HEnquist/BlackHole/pull/1 This adds the sources "Internal Fixed" and "Internal Adjustable", where the adjustable one activates the adjust via the pan control.

HEnquist avatar Oct 16 '22 21:10 HEnquist

Hi, Devin any chance to prioritize the review and merge these changes in? Thanks!

Wang-Yue avatar Oct 19 '22 13:10 Wang-Yue

A friendly ping

Wang-Yue avatar Oct 28 '22 01:10 Wang-Yue

I'm still wondering about the clock source select and use of the pan control, can you please share your view on that?

I'm still not sure what to do here. Should I merge the clock source select to this pr or not?

HEnquist avatar Nov 15 '22 09:11 HEnquist

Nah. I can deal with that another time.

But please merge master into your branch.

Devin On Nov 15, 2022 at 1:02 AM -0800, Henrik Enquist @.***>, wrote:

I'm still wondering about the clock source select and use of the pan control, can you please share your view on that? I'm still not sure what to do here. Should I merge the clock source select to this pr or not? — Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you commented.Message ID: @.***>

devinroth avatar Nov 15 '22 20:11 devinroth

I did that a couple of weeks ago, I don't see any changes in master since then.

Then I leave this PR as is, and submit another one for the clock source select.

HEnquist avatar Nov 15 '22 20:11 HEnquist

Should I get rid of the changes in the other files than Blackhole.c?

HEnquist avatar Nov 15 '22 20:11 HEnquist

Yeah.

Devin On Nov 15, 2022, 12:59 PM -0800, Henrik Enquist @.***>, wrote:

Should I get rid of the changes in the other files than Blackhole.c? — Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you commented.Message ID: @.***>

devinroth avatar Nov 23 '22 19:11 devinroth

done

HEnquist avatar Nov 23 '22 19:11 HEnquist

Any chance this could be merged soon?

Wang-Yue avatar Dec 13 '22 10:12 Wang-Yue

I'll be able to look at this over the next week.

devinroth avatar Jan 07 '23 21:01 devinroth

Looking at this now!

devinroth avatar Jan 16 '23 19:01 devinroth