Skip to content

Instantly share code, notes, and snippets.

View roselloryan's full-sized avatar

Ryan Rosello roselloryan

  • ReelBabble
  • Sunnyvale
View GitHub Profile
@brennanMKE
brennanMKE / ProcessBuffer.Swift
Last active November 2, 2023 09:25
Process a CMSampleBuffer to modify the audio using an AVAssetReader and AVAssetWriter in Swift
func processSampleBuffer(scale: Float, sampleBuffer: CMSampleBuffer, writerInput: AVAssetWriterInput) -> Bool {
guard let blockBuffer = CMSampleBufferGetDataBuffer(sampleBuffer) else {
return false
}
let length = CMBlockBufferGetDataLength(blockBuffer)
var sampleBytes = UnsafeMutablePointer<Int16>.allocate(capacity: length)
defer { sampleBytes.deallocate(capacity: length) }
guard checkStatus(CMBlockBufferCopyDataBytes(blockBuffer, 0, length, sampleBytes), message: "Copying block buffer") else {
return false