feat(keyboard): improve typing, voice flow, and polish reliability
Reduce extension memory pressure and delivery races while adding richer candidates, tactile feedback, and safer two-level creative polishing.
This commit is contained in:
@@ -0,0 +1,25 @@
|
||||
// AudioBufferSnapshot+AVFoundation.swift
|
||||
// OSGKeyboard · HostSupport
|
||||
//
|
||||
// AVAudioPCMBuffer → AudioBufferSnapshot copy helper. Kept out of Shared so
|
||||
// the keyboard extension does not link AVFoundation for this type alone.
|
||||
|
||||
import AVFoundation
|
||||
import Foundation
|
||||
#if canImport(OSGKeyboardShared)
|
||||
import OSGKeyboardShared
|
||||
#endif
|
||||
|
||||
extension AudioBufferSnapshot {
|
||||
/// Construct from an `AVAudioPCMBuffer` by copying out the channel data.
|
||||
public init(buffer: AVAudioPCMBuffer) {
|
||||
guard let channelData = buffer.floatChannelData else {
|
||||
self.init(samples: [], sampleRate: buffer.format.sampleRate)
|
||||
return
|
||||
}
|
||||
let n = Int(buffer.frameLength)
|
||||
var copy = [Float](repeating: 0, count: n)
|
||||
memcpy(©, channelData[0], n * MemoryLayout<Float>.size)
|
||||
self.init(samples: copy, sampleRate: buffer.format.sampleRate)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user