2014-06-06 10 views
9

Swift kullanarak AVAudioPCMBuffer.floatChannelData erişmeye çalışıyorum ama UnsafePointer<UnsafePointer<CFloat>> türünde (Objective-C, @property(nonatomic, readonly) float *const *floatChannelData) ve erişmeye çalıştığım herhangi bir girişimde yürütme başarısız oldu. set-up için bir Swift Oyun hızlı bir AVAudioPCMBufferUnsafePointer öğesinden <UnsafePointer <CFloat>> Swift'deki bir dizi atlamaya mı?

Örnek kod bir önceki soruya dahildir:

Getting AVAudioPCMBuffer working (AVAudioFile.mm error code -50)

cevap

6

bu çalışır mı? Ayrıca yapabilecekleriniz

let channels = UnsafeBufferPointer(start: myAudioBuffer.floatChannelData, count: Int(myAudioBuffer.format.channelCount)) 
let floats = UnsafeBufferPointer(start: channels[0], count: Int(myAudioBuffer.frameLength)) 
+0

yılında bu konuda daha fazla bulabilirsiniz Hayır: Ben bir "ölümcül hatayı alıyorum: İsteğe bağlı olamaz. Yok Oyun alanı yürütme başarısız: hata: Yürütme durduruldu, nedeni: EXC_BAD_INSTRUCTION (kod = EXC_I386_INVOP, altkutu = 0x0). " – Matthew

+0

Bu hatayı '' let kanalları = ... '' satırı ile aldım. '' Int (myAudioBuffer.format.channelCount) '' kısmı doğru olarak değerlendirir. – Matthew

+0

Güncelleme: Bu işe yarıyor! Bunun için teşekkür ederim. Swift Playground'da bir kazaya neden olur, ancak uygulama içi çalışır. – Matthew

3

AVAudioBuffer erişmek için geçerli:

for var i = 0; i < Int(audioBuffer.frameLength); i+=Int(audioMixerNode.outputFormatForBus(0).channelCount) { 
    self.audioBuffer.floatChannelData.memory[i] = 0.0f; // or whatever 
} 

Sen Apple pre-release documentation:

The floatChannelData property returns pointers to the buffer’s audio samples, if the buffer’s format is 32-bit float. It returns nil if it is another format. The returned pointer is to format.channelCount pointers to float. Each of these pointers is to frameLength valid samples, which are spaced by stride samples.

İlgili konular