来自 AudioUnitRender swift 的 paramErr -50

Posted

技术标签:

【中文标题】来自 AudioUnitRender swift 的 paramErr -50【英文标题】:paramErr -50 from AudioUnitRender swift 【发布时间】:2016-10-06 03:01:23 【问题描述】:

我正在尝试使用 AudioUnit Render 进行离线渲染,但我看不出哪个参数有误。也许是缓冲的大小。

我正在使用 swift 和核心音频来解决这个问题,这是我从 GenericOutput 音频单元中提取的一些代码。

谢谢

   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)
    
    

【问题讨论】:

音频 -50 错误通常涉及设置不受支持的音频格式。您的格式规范是什么(位、字节、通道、采样率等)? 我正在使用这个 imgur.com/a/E9N72 我使用 getproperty 来填充其余部分 【参考方案1】:

试试这个!

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)
    

【讨论】:

以上是关于来自 AudioUnitRender swift 的 paramErr -50的主要内容,如果未能解决你的问题,请参考以下文章

Swift 中的 AudioUnitRender 和 ExtAudioFileWrite 错误 -50:尝试将 MIDI 转换为音频文件

AudioUnitRender 是啥意思?

AudioUnitRender 出现错误 kAudioUnitErr_CannotDoInCurrentContext (-10863)

AudioUnitRender 错误 -50 带有奇数长度的缓冲区

AudioUnit inputCallback 与 AudioUnitRender -> audioBufferList.mBuffers[0].mDataByteSize 之间不匹配!= in

AudioUnit Render 回调中的 Objective-C/Swift 用法