我想将泛型约束为可以用C表示的类型.在Swift标准库中是否存在所有C类型符合的协议或类型?
func doWithCType<T:CRepresentable>(cValue: T) {
// do thing with C type
}
Run Code Online (Sandbox Code Playgroud)
如果不是CRepresentable,可能是CStruct类型?
线索:
使用此C类型:
typedef struct {
int hodor;
} Hodor;
Run Code Online (Sandbox Code Playgroud)
我强制将结构转换为不兼容的类型(导致崩溃).这是错误消息:Could not cast value of type '__C.Hodor' (0x1035c0700) to 'Swift.CVarArg' (0x107196240).
我无法在任何地方找到"__C",但我希望C类型有所区别.
我收到崩溃日志,说我的应用程序正在崩溃[UIPopoverPresentationController presentationTransitionWillBegin],但在我的代码中没有使用UIPopoverPresentationController.一切都在iPad上,我使用的UIDocumentInteractionController看起来很相似,也许它是UIPopoverPresentationController的子类,我不知道.知道是什么原因引起的吗?
Exception Type: EXC_CRASH (SIGABRT)
Exception Codes: 0x0000000000000000, 0x0000000000000000
Exception Note: EXC_CORPSE_NOTIFY
Triggered by Thread: 0
Last Exception Backtrace:
0 CoreFoundation 0x184799900 __exceptionPreprocess + 124 (NSException.m:162)
1 libobjc.A.dylib 0x183e07f80 objc_exception_throw + 56 (objc-exception.mm:531)
2 UIKit 0x189db43a0 -[UIPopoverPresentationController presentationTransitionWillBegin] + 2884 (UIPopoverPresentationController.m:1197)
3 UIKit 0x1897e82fc __71-[UIPresentationController _initViewHierarchyForPresentationSuperview:]_block_invoke + 1640 (UIPresentationController.m:1136)
4 UIKit 0x1897e6414 __56-[UIPresentationController runTransitionForCurrentState]_block_invoke + 332 (UIPresentationController.m:704)
5 UIKit 0x18973cb70 _runAfterCACommitDeferredBlocks + 292 (UIApplication.m:2312)
6 UIKit 0x18974a030 _cleanUpAfterCAFlushAndRunDeferredBlocks + 92 (UIApplication.m:2290)
7 UIKit 0x18947dc24 _afterCACommitHandler + 96 …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用 AudioKit 的 AKPlayer 同步播放 4 个 mp3 文件,并且非常成功。不过,作为我的 Swift 研究的一部分,我想使用数组(或我还没有学到的东西)来简化我的代码,因为我觉得我的代码中有一些多余的东西,只是简单地复制了四次播放器代码。下面是我写的代码:
let file1 = try? AKAudioFile(readFileName: "mixing_1_vocal.mp3")
let file2 = try? AKAudioFile(readFileName: "mixing_2_drums.mp3")
let file3 = try? AKAudioFile(readFileName: "mixing_3_synth.mp3")
let file4 = try? AKAudioFile(readFileName: "mixing_4_bass.mp3")
let player1 = AKPlayer(audioFile: file1!)
let player2 = AKPlayer(audioFile: file2!)
let player3 = AKPlayer(audioFile: file3!)
let player4 = AKPlayer(audioFile: file4!)
let startTime = AVAudioTime.now() + 0.25
let mixer = AKMixer()
player1 >>> mixer
player2 >>> mixer
player3 >>> mixer
player4 >>> mixer
player1.isLooping = true …Run Code Online (Sandbox Code Playgroud) 问题1
我的第一个问题是将an AVAudioPlayerNode和an AVAudioSequencer用于MIDI 时的播放同步。基本上,我试图通过MIDI播放某些东西,但是它们需要完全同步。
我知道AVAudioPlayerNodes 有同步方法,但是音序器似乎没有这样的东西。
目前,我已经尝试在单独的线程上使用CAMediaTime() + delay和usleep,但是它们似乎不能很好地工作。
问题2我正在使用上的水龙头engine.inputNode来获取录音,与音乐播放分开。但是,录音似乎开始得较早。当我将记录的数据与原始播放进行比较时,相差大约300毫秒。我可以在300毫秒后开始记录,但是即使那样,也不能保证精确的同步,并且可能与机器有关。
所以我的问题是,什么是确保在播放开始时准确开始录制的好方法?