briankendall / proxy-audio-device

A virtual audio driver for macOS to sends all audio to another output
The Unlicense
514 stars 33 forks source link

Fixed Bugs on calculating 'theHostClockFrequency' #21

Closed kasimok closed 1 year ago

kasimok commented 1 year ago

"theTimeBaseInfo.denom / theTimeBaseInfo.numer" dividing operation in Apple Silicon will get 0 on apple silicon

The below code have different behavior on Intel CPU types and apple Silicon CPU types. `#import <Foundation/Foundation.h>

import <mach/mach_time.h>

int main(int argc, const char argv[]) { @autoreleasepool { // insert code here... struct mach_timebase_info theTimeBaseInfo; mach_timebase_info(&theTimeBaseInfo); Float64 theHostClockFrequency = theTimeBaseInfo.denom / theTimeBaseInfo.numer; theHostClockFrequency = 1000000000.0; NSLog(@"%f", theHostClockFrequency); } return 0; } `

So we should cast the theTimeBaseInfo.denom into Float64 first. Otherwise a theHostClockFrequency will result in no sound from PAD.

kasimok commented 1 year ago

@briankendall " theTimeBaseInfo.denom / theTimeBaseInfo.numer" seems to be 1.0 on Intel machines, but it can be quite different on apple silicon machines. For example: my M1 Mac has a number of 125 and denom of 3 which if we don't cast denom to Float64, the returning theHostClockFrequency will be zero.

briankendall commented 1 year ago

That seems to fix it. Well done!