Protected Sub AVCaptureSession()
Dim error As Ptr
// 文字列を指定してクラスオブジェクトを取得する。最初に一回宣言しておけばよい。
Declare Function NSClassFromString Lib "Cocoa" (aClassName As CFStringRef) As Ptr
Declare Function alloc Lib "Cocoa" selector "alloc" (class_id As Ptr) As Ptr
Declare Function init Lib "Cocoa" selector "init" (obj_id As Ptr) As Ptr
// セッション初期化
pSession = NSClassFromString("AVCaptureSession")
pSession = init(alloc(pSession))
// 入力デバイスを指定
Dim device As Ptr = NSClassFromString("AVCaptureDevice")
Declare Function deviceWithUniqueID Lib "Cocoa" selector "deviceWithUniqueID:" (class_id As Ptr, dev As CFStringRef) As Ptr
device = deviceWithUniqueID(device, "SoundflowerEngine:0") // Soundflowerを直接指定
// 入力(入力デバイスを指定して初期化)
Dim input As Ptr = NSClassFromString("AVCaptureDeviceInput")
Declare Function deviceInputWithDevice Lib "Cocoa" selector "deviceInputWithDevice:error:" (obj_id As Ptr, dev As Ptr, byRef err As Ptr) As Ptr
input = deviceInputWithDevice(input, device, error)
Declare Function canAddInput Lib "Cocoa" selector "canAddInput:" (obj_id As Ptr, input As Ptr) As Boolean
Declare Sub addInput Lib "Cocoa" selector "addInput:" (obj_id As Ptr, input As Ptr)
Dim flgI As Boolean = canAddInput(pSession, input)
if flgI then
addInput(pSession, input)
else
msgBox "err in"
end if
// 出力
Dim output As Ptr = NSClassFromString("AVCaptureAudioFileOutput")
output = init(alloc(output))
Declare Function canAddOutput Lib "Cocoa" selector "canAddOutput:" (obj_id As Ptr, output As Ptr) As Boolean
Declare Sub addOutput Lib "Cocoa" selector "addOutput:" (obj_id As Ptr, output As Ptr)
Dim flgO As Boolean = canAddOutput(pSession, output)
if flgO then
addOutput(pSession, output)
else
msgBox "err out"
end if
// セッションスタート
Declare Sub startRunning Lib "Cocoa" selector "startRunning" (obj_id As Ptr)
startRunning(pSession)
// 出力ファイル(ここではAIFF形式)
Dim f As FolderItem = SpecialFolder.Desktop.Child("test.aiff")
Dim url As Ptr = NSClassFromString("NSURL") // クラスメソッドなので、まずNSURLクラスを取得
Declare Function fileURLWithPath Lib "Cocoa" Selector "fileURLWithPath:" (receiver As Ptr, path As CFStringRef) As Ptr
url = fileURLWithPath(url, f.NativePath)
// 録音開始
Declare Sub startRecordingToOutputFileURL Lib "Cocoa" selector "startRecordingToOutputFileURL:outputFileType:recordingDelegate:" (obj_id As Ptr, url As Ptr, type As CFStringRef, delegat As Ptr)
startRecordingToOutputFileURL(output, url, "public.aiff-audio", makeDelegate()) // delegateは必須(nilではダメ)
End Sub