我正在努力使用此API和Swift中的语法
>>>from os import cpu_count
>>>eval('[1,cores]', {'__builtins__': None}, {'cores': cpu_count()})
[1, 8]
我不知道(AudioBuffer)与()的含义是什么?任何想法以及如何初始化它?这来自标题:
audioBufferList = AudioBufferList(mNumberBuffers: 2, mBuffers: (AudioBuffer))
答案 0 :(得分:0)
这是一种初始化AudioBufferList的方法,它有一个空的单声道缓冲区数组,你可以传递给音频单元调用,例如AudioUnitRender(),然后根据需要分配和填充缓冲区:
var bufferList = AudioBufferList(
mNumberBuffers: 1,
mBuffers: AudioBuffer(
mNumberChannels: UInt32(1),
mDataByteSize: 1024,
mData: nil))
答案 1 :(得分:0)
通过使用AVAudioPCMBuffer
类以以下方式解决了该问题:
import AVFoundation
// noninterleaved stereo data
let processingFormat = AVAudioFormat(
commonFormat: .pcmFormatFloat32,
sampleRate: 44100,
channels: 2,
interleaved: false
)!
// this line also creates AudioBufferList instance.
let buffer = AVAudioPCMBuffer(
pcmFormat: processingFormat,
frameCapacity: 1024)!
// this line updates mDataByteSize properties
buffer.frameLength = 1024
let bufferList: UnsafePointer<AudioBufferList> = buffer.audioBufferList
print(bufferList.pointee) // Prints: AudioBufferList(mNumberBuffers: 2, mBuffers: __C.AudioBuffer(mNumberChannels: 1, mDataByteSize: 4096, mData: Optional(0x00007ff253840e00)))