- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
第 5 行的这种关联对应用程序的成功没有贡献。但老实说,我不明白那一刻发生了什么。
Overloads for ÜnsafeMutablePointer exist with partially matching parameter list: (RawPointer).
但这是什么意思呢?谢谢
override func buffer(withCsound cs: CsoundObj) -> Data {
let length = Int(AKSettings.shared().numberOfChannels) *
Int(AKSettings.shared().samplesPerControlPeriod) * 4
let num = length / 4
let floats = UnsafeMutablePointer<Float>(malloc(length))
/* The phase and amplitude are different for each line to get a nice
* gimmick. */
let phase = (self.amplifier + 0.8) / 1.8
for i in 0 ... num - 1 {
/* The amplitude is placed within the for-loop because it can fade
* to a slightly different value during one plot refresh. */
let amplitude = self.amplifier * self.amplitude
/* It is incredibly important that `time` and `phase` aren't
* multiplied with the frequency or else it will bump at each
* frequency change. */
var t = (time + Double(i) / Double(num) * self.frequency + phase)
floats[i] = Float(sin(t * 2 * 3.14))
/* It is multiplied with a "regular" 0.5 Hz sine to get both ends
* to fade out nicely. It's sort of a simplistic window function. */
t = Double(i) / Double(num)
floats[i] *= Float(sin(t * 1 * 3.14) * amplitude)
floats[i] *= 1 - pow(1 - Float(i) / Float(num), 2.0)
time += self.frequency / 44100 / 2
/* Fade smoothly to the next frequency and amplitude. */
self.frequency += (nextFrequency - self.frequency) / 44100.0 / 4.0
self.amplitude += (nextAmplitude - self.amplitude) / 44100.0 / 2.0
}
/* We keep the time between 0 and 1 to make sure it never overflows /
* loses the necessary precision. */
time = fmod(time, 1.0)
return Data(bytesNoCopy: UnsafeMutablePointer<UInt8>(floats), count: length, deallocator: .free)
}
最佳答案
你可以找到一些类似的文章搜索错误信息。
例如:How to use UnsafeMutablePointer in Swift 3?
你最好阅读MIGRATING TO SWIFT 3 , 特别是 this article .
具体到您的情况。
改变这一行:
let floats = UnsafeMutablePointer<Float>(malloc(length))
到:
let rawBytes = malloc(length)!
let floats = rawBytes.assumingMemoryBound(to: Float.self)
并更改最后一行:
return Data(bytesNoCopy: UnsafeMutablePointer<UInt8>(floats), count: length, deallocator: .free)
到:
return Data(bytesNoCopy: rawBytes, count: length, deallocator: .free)
选项 2。
更改行 let floats = UnsafeMutablePointer<Float>(malloc(length))
到:
var data = Data(count: length)
data.withUnsafeMutableBytes {(floats: UnsafeMutablePointer<Float>) in
并将最后一行更改为:
}
return data
(它们之间的所有行都包含在闭包 {(floats: UnsafeMutablePointer<Float>) in ...}
中。)
关于ios - 无法使用类型为 'UnsafeMutablePointer<Float>' 的参数列表调用类型为 '(UnsafeMutableRawPointer!)' 的初始值设定项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41517732/
我正在使用 Swift 的 C API,对于我需要调用的方法之一,我需要给出一个 UnsafeMutablePointer>> 更多信息: 快速界面: public func presage_pred
函数: public func OSAtomicCompareAndSwapPtr(_ __oldValue: UnsafeMutableRawPointer!, _ __newValue: Unsa
我正在尝试使用 NSView 的 getRectsBeingDrawn,但我不太确定如何转换它需要的变量。 它的定义是: func getRectsBeingDrawn(rects: UnsafeMu
更新到 Swift 3 后,我的代码出现了一些问题。我在转换之前有这段代码: extension NSData { func castToCPointer() -> T { let mem
我真的被一个愚蠢但看似简单的问题弄疯了......我必须将 Data 转换为 AVAudioPCMBuffer。 寻找this question这似乎很容易,但随着 Swift 3 的出现,一切都发生
我需要使用一个使用 UnsafeMutablePointer?>! 的函数作为参数。它是用 Objective-C++ 框架编写的,我通过桥接 header 访问它: - (void) applyFi
我的 Swift 项目中有这个 EZAudio 方法,用于从麦克风捕获音频: func microphone(microphone: EZMicrophone!, hasAudioReceived b
我刚开始弄乱图像处理,我遇到了几个非常奇怪的问题,或者至少我认为是这样。我假设我犯了一些非常愚蠢的错误。 我本来打算就此发布另一个问题,但是使用下面的代码有时我也会得到随机噪声,而不是用户抽取数字的像
在main.swift文件,我们调用了我们的收据检查系统(由 Receigen 生成)。在 Swift 2 中,main.swift阅读: startup(Process.argc, UnsafeMu
我在 Swift 中创建了一个名为 RGB 的结构,非常简单: struct PixelRGB { var r: CUnsignedChar = 0 var g: CUnsignedC
我正在使用 SceneKit 的 SCNParticleSystem 构建一个测试应用程序。它有一个回调,可让您修改每个帧上的粒子属性。这个回调的签名是 typealias SCNParticleMo
Accelerate 框架的 Swift 签名 vDSP_biquadm()函数包括 UnsafeMutablePointer> 的参数类型和 UnsafeMutablePointer> . 如何在
请帮助语法: __weak typeof (self) weakSelf = self; [self.audioFile getWaveformDataWithCompletionBlock:^(fl
这段代码在 Swift2.3 中运行良好,现在我将其转换为 Swift3。所以我收到这个错误。有人知道如何解决这个问题吗? var cmdLnConf: OpaquePointer? filepriv
我构建了一个小结构,其中包含伪 C 字符串 UnsafeMutablePointer。现在我想添加一种方法来获取字符串的长度,但有些行为非常奇怪: struct Char { let valu
1. let context = CGContext(...) 2. context.draw(...) 3. let buffer = UnsafeMutablePointer(context.da
在 C 中,我有以下代码来分配一个具有适当大小的 AudioBufferList,然后用相关数据填充它。 AudioObjectPropertyScope scope = mIsInput ? kAu
我正在尝试将我的 Swift 2 代码转换为最新的语法 (Swift 3)。我收到以下错误: Cannot invoke initializer for type 'UnsafeMutablePoin
var a = [1,2,3] let ptr1 = UnsafeMutablePointer(&a[0]) //works fine let index = 0 let ptr2 = UnsafeM
在我创建的结构中(在Xcode 10.1,Swift 4.2上)观察到的属性上使用UnsafeMutablePointer时,出现了一些意外的行为。请参阅以下游乐场代码: struct NormalT
我是一名优秀的程序员,十分优秀!