I wrote a function:
func rms16(buffer: Int, bufferSize: Int) -> Float
{
let sum: Float = 0.0
let mySize: Int = bufferSize / sizeof(CShort)
var buffer_short: Int = buffer
for var i = 0; i < mySize; i++ {
sum += buffer_short[i] * 2
}
let sqrt1: Float = sqrtf(sum / Float(mySize))
return (sqrt1) / Float(mySize)
}
Above function in a for loop it show me error like this:
Type Int has no subscript members
Anyone tell me how can i fix it?
The buffer_short is an integer variable not an array of integer.
You need to change the first argument of your function to an array of integer, like:
func rms16(buffer: [Int], bufferSize: Int) -> Float
{
let sum: Float = 0.0
let mySize: Int = bufferSize / sizeof(CShort)
var buffer_short = buffer
for var i = 0; i < mySize; i++
{
sum += buffer_short[i] * 2
}
let sqrt1: Float = sqrtf(sum / Float(mySize))
return (sqrt1) / Float(mySize)
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With