Hello @Engineer, I am trying to convert PCM to AAC Format, the sample rate, channel is same to PCM.
I use the code modified upon, but when finish, the sound played was very rapid, What's the problem?
let bufferLength = buffer.frameLength
var offset: UInt32 = 0
var done = false
var data = Data()
while !done {
let aacBuffer = AVAudioCompressedBuffer(format: outputFormat, packetCapacity: 1, maximumPacketSize: converter.maximumOutputPacketSize)
converter.convert(to: aacBuffer, error: nil) { packetCount, inputStatus in
let count = min(packetCount, buffer.frameLength - offset)
if count == 0 {
inputStatus.pointee = .noDataNow
return nil
}
let buffer1 = self.getOffsetBuffer(buffer: buffer, offset: offset, count: count)
offset += count
inputStatus.pointee = .haveData
return buffer1
}
data.append(Data(bytes: aacBuffer.data, count: Int(aacBuffer.byteLength)))
if offset >= bufferLength {
done = true
}
}
return data // To add AAC Header
Post
Replies
Boosts
Views
Activity
Have you solved this problem?