0

MatrixMixer AudioUnit をクエリするには、次のようにします。

// code from MatrixMixerTest sample project in c++

UInt32 dims[2];
UInt32 theSize =  sizeof(UInt32) * 2;
Float32 *theVols = NULL;
OSStatus result;


ca_require_noerr (result = AudioUnitGetProperty (au, kAudioUnitProperty_MatrixDimensions,   
                        kAudioUnitScope_Global, 0, dims, &theSize), home);

theSize = ((dims[0] + 1) * (dims[1] + 1)) * sizeof(Float32);

theVols = static_cast<Float32*> (malloc (theSize));

ca_require_noerr (result = AudioUnitGetProperty (au, kAudioUnitProperty_MatrixLevels,   
                        kAudioUnitScope_Global, 0, theVols, &theSize), home);

の戻り値AudioUnitGetPropertykAudioUnitProperty_MatrixLevels(ドキュメントとサンプル コードで定義されています) Float32 です。

私は迅速に行列レベルを見つけようとしていますが、行列の次元を問題なく取得できます。しかし、. である Float32 要素の空の配列を作成する方法がわかりませんUnsafeMutablePointer<Void>。これが私が成功せずに試したことです:

var size = ((dims[0] + 1) * (dims[1] + 1)) * UInt32(sizeof(Float32))
var vols = UnsafeMutablePointer<Float32>.alloc(Int(size))

MatrixMixerTest では、配列は次のように使用されます。theVols[0]

4

1 に答える 1

2

他の部分をどのように変換したかによって変更が必要になる場合がありますが、C++ コードの最後の部分は次のように Swift で記述できます。

    theSize = ((dims[0] + 1) * (dims[1] + 1)) * UInt32(sizeof(Float32))

    var theVols: [Float32] = Array(count: Int(theSize)/sizeof(Float32), repeatedValue: 0)

    result = AudioUnitGetProperty(au, kAudioUnitProperty_MatrixLevels,
            kAudioUnitScope_Global, 0, &theVols, &theSize)
    guard result == noErr else {
        //...
        fatalError()
    }

C 関数ベースの API が を要求しているUnsafeMutablePointer<Void>場合、必要なArrayのは任意の型の変数だけで、それを inout パラメーターとして渡します。

于 2016-07-11T22:18:24.123 に答える