Skip to content

Commit 02753c5

Browse files
committed
fxies to the driver cleanup routine
1 parent a4f7891 commit 02753c5

2 files changed

Lines changed: 28 additions & 17 deletions

File tree

native/driver/Driver.xcodeproj/project.pbxproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -461,6 +461,7 @@
461461
"$(inherited)",
462462
"@executable_path/../Frameworks",
463463
"@loader_path/../Frameworks",
464+
"/Library/Audio/Plug-Ins/HAL/eqMac.driver/Contents/Frameworks",
464465
);
465466
MACOSX_DEPLOYMENT_TARGET = 10.10;
466467
MARKETING_VERSION = 1.3.0;
@@ -533,6 +534,7 @@
533534
"$(inherited)",
534535
"@executable_path/../Frameworks",
535536
"@loader_path/../Frameworks",
537+
"/Library/Audio/Plug-Ins/HAL/eqMac.driver/Contents/Frameworks",
536538
);
537539
MACOSX_DEPLOYMENT_TARGET = 10.10;
538540
MARKETING_VERSION = 1.3.0;

native/driver/Source/EQMDevice.swift

Lines changed: 26 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -592,6 +592,10 @@ class EQMDevice: EQMObject {
592592

593593
static func doIO (client: EQMClient?, operationID: UInt32, sample: UnsafeMutablePointer<Float32>, cycleInfo: AudioServerPlugInIOCycleInfo, frameSize: UInt32) -> OSStatus {
594594

595+
guard let buffer = ringBuffer else {
596+
return noErr
597+
}
598+
595599
ioMutex.lock()
596600

597601
switch operationID {
@@ -601,21 +605,22 @@ class EQMDevice: EQMObject {
601605
for frame in 0 ..< frameSize {
602606
for channel in 0 ..< kChannelCount {
603607
let readFrame = Int(frame * kChannelCount + channel)
608+
604609
if EQMControl.muted {
605610
// Muted
606611
sample[readFrame] = 0
607-
} else {
608-
let nextSampleTime = sampleTime + Int(frame)
609-
let remainder = nextSampleTime % Int(ringBufferSize)
610-
let writeFrame = remainder * Int(kChannelCount) + Int(channel)
611-
ringBuffer![writeFrame] += sample[readFrame]
612612
}
613613

614+
let writePosition = sampleTime + Int(frame)
615+
let writeRemainder = writePosition % Int(ringBufferSize)
616+
let writeFrame = writeRemainder * Int(kChannelCount) + Int(channel)
617+
buffer[writeFrame] += sample[readFrame]
618+
614619
// Clean up buffer
615-
let cleanFromFrame = sampleTime + Int(frame) + 8192
616-
let remainder = cleanFromFrame % Int(ringBufferSize)
617-
let cleanFrame = remainder * Int(kChannelCount) + Int(channel)
618-
ringBuffer![cleanFrame] = 0
620+
let cleanCleanPosition = sampleTime + Int(frame) + 8192
621+
let cleanRemainder = cleanCleanPosition % Int(ringBufferSize)
622+
let cleanFrame = cleanRemainder * Int(kChannelCount) + Int(channel)
623+
buffer[cleanFrame] = 0
619624
}
620625
}
621626

@@ -629,20 +634,24 @@ class EQMDevice: EQMObject {
629634
for frame in 0 ..< frameSize {
630635
for channel in 0 ..< kChannelCount {
631636
let writeFrame = Int(frame * kChannelCount + channel)
637+
632638
if EQMControl.muted {
633639
sample[writeFrame] = 0
634640
} else {
635-
let nextSampleTime = sampleTime + Int(frame)
636-
let remainder = nextSampleTime % Int(ringBufferSize)
637-
let readFrame = remainder * Int(kChannelCount) + Int(channel)
638-
sample[writeFrame] = ringBuffer![readFrame]
641+
let readPosition = sampleTime + Int(frame)
642+
let readRemainder = readPosition % Int(ringBufferSize)
643+
let readFrame = readRemainder * Int(kChannelCount) + Int(channel)
644+
sample[writeFrame] = buffer[readFrame]
639645
}
640646

641647
// Clean up buffer
642-
let cleanFromFrame = sampleTime + Int(frame) - Int(ringBufferSize)
643-
let remainder = cleanFromFrame % Int(ringBufferSize)
644-
let cleanFrame = remainder * Int(kChannelCount) + Int(channel)
645-
ringBuffer![cleanFrame] = 0
648+
let cleanPosition = sampleTime + Int(frame) - Int(ringBufferSize)
649+
if (cleanPosition > 0) {
650+
let cleanRemainder = cleanPosition % Int(ringBufferSize)
651+
let cleanFrame = cleanRemainder * Int(kChannelCount) + Int(channel)
652+
buffer[cleanFrame] = 0
653+
}
654+
646655
}
647656
}
648657
break

0 commit comments

Comments
 (0)