我对iOS开发相当陌生,而且我是一个有声音的新手。
我试图获得使用TAAE播放的音频的响度或功率。我不确定我所做的事情是否有意义。
这是我的代码
static var gameStatus : GameStatus = .Starting
private init(){
audioController = AEAudioController(audioDescription: AEAudioController.nonInterleavedFloatStereoAudioDescription())
initializeAudioTrack()
}
func initializeAudioTrack() {
let file = NSBundle.mainBundle().URLForResource("01 Foreign Formula", withExtension:
"mp3")
let channel: AnyObject! = AEAudioFilePlayer.audioFilePlayerWithURL(file, audioController: audioController, error: nil)
let receiver = AEBlockAudioReceiver { (source, time, frames, audioBufferList) -> Void in
let leftSample = UnsafeMutablePointer<Float>(audioBufferList[0].mBuffers.mData)
let rightSample = UnsafeMutablePointer<Float>(audioBufferList[1].mBuffers.mData)
var accumulator = Float(0.0)
for i in 0...frames {
accumulator += leftSample[Int(i)] * leftSample[Int(i)]
}
var power = accumulator / Float(frames)
println(power)
}
println(audioController?.masterOutputVolume)
audioController?.addChannels([channel])
audioController?.addOutputReceiver(receiver)
audioController?.useMeasurementMode = true
audioController?.preferredBufferDuration = 0.005
audioController?.start(nil)
}
我到处试图了解如何完成这项工作,但我很难知道应该寻找什么。
基本上我需要的全部是找到音频的力量(强度,低音等)来确定和操纵我正在构建的游戏中的某些东西。
我真的很喜欢任何解释或帮助。
随意在Objective-C或其他
中编写代码