1
1
mirror of https://github.com/bitgapp/eqMac.git synced 2024-12-02 10:24:09 +03:00

some sample rate mismatch and playthrough fixes

This commit is contained in:
nodeful 2020-04-26 00:58:50 +01:00
parent 7f43828879
commit 13654ecb95
7 changed files with 39 additions and 30 deletions

View File

@ -11,7 +11,7 @@ target 'eqMac' do
# Pods for eqMac
pod 'AudioKit', '4.9.5'
pod 'AMCoreAudio', '~> 3.2.1'
pod 'AMCoreAudio', '~> 3.3.1'
pod 'Criollo', '~> 0.5
pod 'WebViewJavascriptBridge', '~> 6.0'
pod 'ReSwift'

View File

@ -1,5 +1,5 @@
PODS:
- AMCoreAudio (3.2.1)
- AMCoreAudio (3.3.1)
- AudioKit (4.9.5):
- AudioKit/Core (= 4.9.5)
- AudioKit/UI (= 4.9.5)
@ -24,7 +24,7 @@ PODS:
- Zip (1.1.0)
DEPENDENCIES:
- AMCoreAudio (~> 3.2.1)
- AMCoreAudio (~> 3.3.1)
- AudioKit (= 4.9.5)
- Criollo (~> 0.5)
- EmitterKit (~> 5.2)
@ -67,7 +67,7 @@ CHECKOUT OPTIONS:
:git: https://github.com/sveinbjornt/STPrivilegedTask.git
SPEC CHECKSUMS:
AMCoreAudio: 7fa6b718dc93acc29f849d60c3ad680ae1bf07b5
AMCoreAudio: 6bf97d548d02ebb75b56c1cbf6b1f87bcfdeb748
AudioKit: ccf4e39c89ed6e5cbbce5fef58d819db39446437
CocoaAsyncSocket: 694058e7c0ed05a9e217d1b3c7ded962f4180845
Criollo: 617173837c296ca4248b0b058f36ce9b91e5c25b
@ -83,6 +83,6 @@ SPEC CHECKSUMS:
WebViewJavascriptBridge: 7f5bc4d3581e672e8f32bd0f812d54bc69bb8e29
Zip: 8877eede3dda76bcac281225c20e71c25270774c
PODFILE CHECKSUM: af9609c8cb57f7a692fe492dc72205a4e2ea5b4b
PODFILE CHECKSUM: e17cf26c243566da606db59c356b057283ec8836
COCOAPODS: 1.9.1

View File

@ -14,13 +14,6 @@ import ServiceManagement
class AppDelegate: NSObject, NSApplicationDelegate {
func applicationDidFinishLaunching(_ aNotification: Notification) {
Application.start()
// print(Driver.latency)
// Driver.latency = 1000
// print(Driver.latency)
//
// print(Driver.safetyOffset)
// Driver.safetyOffset = 1000
// print(Driver.safetyOffset)
}
func applicationWillTerminate(_ aNotification: Notification) {

View File

@ -275,6 +275,11 @@ class Application {
private static func createAudioPipeline () {
Sources() { sources in
let outputSampleRate = selectedDevice.actualSampleRate()!
let driverSampleRates = Driver.sampleRates
let closestSampleRate = driverSampleRates.min( by: { abs($0 - outputSampleRate) < abs($1 - outputSampleRate) } )!
Driver.device!.setNominalSampleRate(closestSampleRate)
self.sources = sources
effects = Effects()
volume = Volume()

View File

@ -79,7 +79,7 @@ class Engine {
private func setupBuffer () {
let framesPerSample = Driver.device!.bufferFrameSize(direction: .playback)
ringBuffer = CARingBuffer<Float>(numberOfChannels: 2, capacityFrames: UInt32(framesPerSample * 1024 * 16))
ringBuffer = CARingBuffer<Float>(numberOfChannels: 2, capacityFrames: UInt32(framesPerSample * 512))
}
private func attach () {
@ -89,8 +89,8 @@ class Engine {
}
private func attachSource () {
format = AVAudioFormat(commonFormat: .pcmFormatFloat32, sampleRate: 44_100, channels: 2, interleaved: false)
sources.system.setInputDevice(engine: engine)
format = engine.inputNode.inputFormat(forBus: 0)
}
private func attachEffects () {

View File

@ -37,22 +37,8 @@ class Output {
let abl = UnsafeMutableAudioBufferListPointer(ioData)!
let output = Unmanaged<Output>.fromOpaque(inRefCon).takeUnretainedValue()
let engine: Engine! = output.engine!
var inTS = AudioTimeStamp()
var outTS = AudioTimeStamp()
let inputDevice = Driver.device!
if AudioDeviceGetCurrentTime(inputDevice.id, &inTS) != noErr {
makeBufferSilent(abl)
return noErr
}
if AudioDeviceGetCurrentTime(output.device.id, &outTS) != noErr {
makeBufferSilent(abl)
return noErr
}
output.varispeed.rate = Float(inTS.mRateScalar / outTS.mRateScalar)
let sampleTime = inTimeStamp.pointee.mSampleTime
if output.firstOutputTime < 0 {
output.firstOutputTime = sampleTime
@ -93,6 +79,7 @@ class Output {
var device: AudioDevice!
var engine: Engine!
var outputEngine = AVAudioEngine()
var format: AVAudioFormat!
var player = AVAudioPlayerNode()
var varispeed = AVAudioUnitVarispeed()
let deviceChanged = EmitterKit.Event<AudioDevice>()
@ -109,10 +96,14 @@ class Output {
outputEngine.setOutputDevice(device)
format = outputEngine.outputNode.outputFormat(forBus: 0)
varispeed.rate = Float(Driver.device!.actualSampleRate()! / device.actualSampleRate()!)
Console.log("Varispeed Rate: \(varispeed.rate)")
outputEngine.attach(player)
outputEngine.attach(varispeed)
outputEngine.connect(player, to: varispeed, format: nil)
outputEngine.connect(varispeed, to: outputEngine.mainMixerNode, format: nil)
outputEngine.connect(player, to: varispeed, format: format)
outputEngine.connect(varispeed, to: outputEngine.mainMixerNode, format: format)
self.setRenderCallback()

View File

@ -53,6 +53,26 @@ class Driver {
}
}
static var sampleRates: [Double] {
return [
8_000,
11_025,
12_000,
16_000,
22_050,
24_000,
32_000,
44_100,
48_000,
64_000,
88_200,
96_000,
128_000,
176_400,
192_000
]
}
static func getDeviceIsShown (device: DriverDevice) -> Bool {
if Driver.device != nil { return true }
if let pluginId = self.pluginId {