AudioUnitSetProperty Swift 个错误
AudioUnitSetProperty Swift errors
我正在尝试使用 AudioUnitSetProperty 在我的均衡器中设置频段,但无法理解 Swift 中的语法。我的代码如下所示:
var eqFrequencies: NSArray = [ 32, 250, 500, 1000, 2000, 16000 ]
var noBands = UInt32(eqFrequencies.count)
AudioUnitSetProperty(self.MyAppUnit, AudioUnitParameterID(kAUNBandEQProperty_NumberOfBands), AudioUnitScope(kAudioUnitScope_Global), 0, 6, UInt32(sizeof(noBands)))
有人知道正确的做法吗?
试试这个(在 Xcode 6.3 中为我编译):
var eqFrequencies: [UInt32] = [ 32, 250, 500, 1000, 2000, 16000 ]
AudioUnitSetProperty(
self.MyAppUnit,
AudioUnitPropertyID(kAUNBandEQProperty_NumberOfBands),
AudioUnitScope(kAudioUnitScope_Global),
0,
eqFrequencies,
UInt32(eqFrequencies.count*sizeof(UInt32))
)
Swift 抱怨各种 int 类型,因此额外的转换和大小计算是错误的,但是带 swift 数组的 UInt32
s (not NSArray
) 应该自动转换为 UnsafePointer<Void>
.
我正在尝试使用 AudioUnitSetProperty 在我的均衡器中设置频段,但无法理解 Swift 中的语法。我的代码如下所示:
var eqFrequencies: NSArray = [ 32, 250, 500, 1000, 2000, 16000 ]
var noBands = UInt32(eqFrequencies.count)
AudioUnitSetProperty(self.MyAppUnit, AudioUnitParameterID(kAUNBandEQProperty_NumberOfBands), AudioUnitScope(kAudioUnitScope_Global), 0, 6, UInt32(sizeof(noBands)))
有人知道正确的做法吗?
试试这个(在 Xcode 6.3 中为我编译):
var eqFrequencies: [UInt32] = [ 32, 250, 500, 1000, 2000, 16000 ]
AudioUnitSetProperty(
self.MyAppUnit,
AudioUnitPropertyID(kAUNBandEQProperty_NumberOfBands),
AudioUnitScope(kAudioUnitScope_Global),
0,
eqFrequencies,
UInt32(eqFrequencies.count*sizeof(UInt32))
)
Swift 抱怨各种 int 类型,因此额外的转换和大小计算是错误的,但是带 swift 数组的 UInt32
s (not NSArray
) 应该自动转换为 UnsafePointer<Void>
.