gpt4 book ai didi

ios - paramErr -50 来自 AudioUnitRender swift

转载 作者:行者123 更新时间:2023-11-28 16:08:36 25 4
gpt4 key购买 nike

我正在尝试使用 AudioUnit Render 进行离线渲染,但我没有看到哪个参数有误。可能是缓冲的大小。

我正在使用 swift 和 core audio 来解决这个问题,这是我从 GenericOutput audioUnit 中提取的一些代码。

谢谢

   func pullGenericOutput(_ player: UnsafeMutablePointer<AUGraphPlayer>){
//var player = AUGraphPlayer()

do {
var flags = AudioUnitRenderActionFlags()
var inTimeStamp = AudioTimeStamp()
inTimeStamp.mFlags = .sampleTimeValid

var busNumber:UInt32 = 0
var numberFrames:UInt32 = 512
inTimeStamp.mSampleTime = 0
var channelCount = 2

print("Final numberFrames :\(numberFrames)")
var totFrms = MaxSampleTime

while totFrms > 0 {

if totFrms < numberFrames {
numberFrames = totFrms
print("Final numberFrames :\(numberFrames)")
print("stuck")
}
else {
totFrms -= numberFrames
}
var bufferList = AudioBufferList()
bufferList.mNumberBuffers = UInt32(channelCount)

for j in 0..<channelCount {
var buffer = AudioBuffer()
buffer.mNumberChannels = 1
buffer.mDataByteSize = numberFrames * UInt32(MemoryLayout.size(ofValue: UInt32.self))
buffer.mData = calloc(Int(numberFrames), MemoryLayout.size(ofValue: UInt32.self))

bufferList.mBuffers = buffer
}//for loop end
//var actionFlags = AudioUnitRenderActionFlags(rawValue: UInt32(flags))
// print(actionFlags)
Utility.check(AudioUnitRender(player.pointee.mGIO!, &flags, &inTimeStamp, busNumber, numberFrames, &bufferList), operation: "AudioUnitRender mGIO")

inTimeStamp.mSampleTime += inTimeStamp.mSampleTime

Utility.check(ExtAudioFileWrite( player.pointee.extAudioFile!, numberFrames, &bufferList), operation: ("extaudiofilewrite fail"))
}//while loop end
self.filesSavingCompleted(player)
}
}

最佳答案

试试这个!

var flags: AudioUnitRenderActionFlags = AudioUnitRenderActionFlags(rawValue: 0)
var inTimeStamp = AudioTimeStamp()

memset(&inTimeStamp, 0, MemoryLayout.size(ofValue: inTimeStamp))
inTimeStamp.mFlags = .smpteTimeValid

let busNumber: UInt32 = 0
var numberFrames: UInt32 = 1024
inTimeStamp.mSampleTime = 0
let channelCount: Int = 2
var totFrms: Int = Int(maxSampleTime)

while totFrms > 0 {

if UInt32(totFrms) < numberFrames {
numberFrames = UInt32(totFrms)
} else {
totFrms -= Int(numberFrames)
}

let bufferList = AudioBufferList.allocate(maximumBuffers: Int(channelCount))

for i in 0...channelCount-1 {

var buffer = AudioBuffer()
buffer.mNumberChannels = 1
buffer.mDataByteSize = numberFrames * 4
buffer.mData = calloc(Int(numberFrames), 4)
bufferList[i] = buffer

var result: OSStatus = AudioUnitRender(mGIO!, &flags, &inTimeStamp, busNumber, numberFrames, bufferList.unsafeMutablePointer)
print(result)
if result == 0 {
result = ExtAudioFileWrite(extAudioFile!, numberFrames, bufferList.unsafeMutablePointer)
}
inTimeStamp.mSampleTime += Float64(numberFrames)
}
}

关于ios - paramErr -50 来自 AudioUnitRender swift,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39886839/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com