How to populate AudioStreamBasicDescription for AMR_WB playback?

160 views Asked by At

I have an android device sending me audio in AMR_WB format with 16_000 sample rate and channel is mono.

var asbd = AudioStreamBasicDescription()
asbd.mSampleRate = Float64(sampleRate) // value: 16_000
asbd.mFormatID = kAudioFormatAMR_WB
asbd.mFormatFlags = 0
asbd.mFramesPerPacket = 1
asbd.mChannelsPerFrame = UInt32(channels) // value: 1
asbd.mBitsPerChannel = 8 * UInt32(MemoryLayout<UInt8>.size)
asbd.mReserved = 0
asbd.mBytesPerFrame = asbd.mChannelsPerFrame * UInt32(MemoryLayout<UInt8>.size)
asbd.mBytesPerPacket = asbd.mBytesPerFrame * asbd.mFramesPerPacket
let _audioFormat = AVAudioFormat(streamDescription: &asbd)!
return _audioFormat

When I am sending this to the AVSampleBufferAudioRenderer, but I am getting the following error

Error Domain=AVFoundationErrorDomain Code=-11800 "The operation could not be completed" 
UserInfo={NSLocalizedFailureReason=An unknown error occurred (1885696621), 
NSLocalizedDescription=The operation could not be completed, 
NSUnderlyingError=0x283fb1920 {Error Domain=NSOSStatusErrorDomain Code=1885696621 "(null)" 
UserInfo={AVErrorFourCharCode='perm'}}}

Some old questions say that AMR is not supported on iOS, but I am able to find the codec ID in the documentation here

0

There are 0 answers