What we talk about when we talk about Technology

技術について語ります。

ラ!

結局ほとんどQiitanの記事のまんま

let renderCallback: AURenderCallback = { inRefCon, ioActionFlags, inTimeStamp, inBusNumber, inNumberFrames, ioData in
        
    var def: SineWaveDef = UnsafeMutablePointer(inRefCon).memory
        
    let freq = 440 * 2.0 * M_PI / def.sampleRate
    var phase = def.phase
        
    let ioDataMem: AudioBufferList = ioData.memory
    let ablP = UnsafeMutableAudioBufferListPointer(ioData)
    var outputs = [UnsafeMutablePointer<Float>]( count: Int( ioDataMem.mNumberBuffers ), repeatedValue: nil )
    var outputCount : Int = 0
    for buffer in ablP {
        outputs[ outputCount ] = UnsafeMutablePointer<Float>( buffer.mData )
        outputCount += 1
    }
        
    for i in 0 ..< inNumberFrames {
            
        // calc sine wave
        let wave = sin(phase)
            
        var sample = Float(wave) * Float(1 << kAudioUnitSampleFractionBits)
            
        memcpy( outputs[0], &sample, sizeof(Float) )
        outputs[0] += 1
        memcpy( outputs[1], &sample, sizeof(Float) )
        outputs[1] += 1
            
        phase += freq
    }
        
        
    def.phase = phase
        
    return noErr
}

そして、ASBDの登録は削除!
どうやら自動で8.24固定小数点形式で再生されるみたい。

ところが...

入力を2つマルチチャンネルミキサーに登録して再生しようとすると
コールバック内で受け取るデータにアクセスする際にBAD_ACCESS...
うーむ。