1 year ago
#296707
PPreeti
AVAudioPlayerNode scheduleBuffer playing some glitchy noise while audio transmission
I am trying to use scheduleBuffer, audio is transmitting also but at receiver end playing with some glitchy sound
private func convertAudioToPCMBuffer(clip: Audio) -> AVAudioPCMBuffer? {
var PCMBuffer = AVAudioPCMBuffer()
guard let audioFormat = AVAudioFormat( commonFormat: .pcmFormatFloat32, sampleRate: clip.sampleRate, channels: 1, interleaved: false) else { return nil }
guard let audioPCMBuffer = AVAudioPCMBuffer( pcmFormat: audioFormat, frameCapacity: clip.frameCapacity) else { return nil }
audioPCMBuffer.frameLength = audioPCMBuffer.frameCapacity
guard let channelData = audioPCMBuffer.floatChannelData else { return nil }
let shortFloats = self.audioCompressor.decompress(byteArray: [UInt8](clip.audio))
let leftChannelIndex: Int = 0
if(shortFloats.count >= audioPCMBuffer.frameLength) {
for i in 0 ..< Int(audioPCMBuffer.frameLength) {
channelData[leftChannelIndex][i] = shortFloats[i] // ptr to audioPCMBuffer's Core Audio AudioBufferList
}
}
if clip.sampleRate != self.playbackSampleRate {
PCMBuffer = AudioSessionConfigurator.convertSampleRate( inSampleRate: clip.sampleRate, outSampleRate: self.playbackSampleRate, inBuffer: audioPCMBuffer
)
} else {
PCMBuffer = audioPCMBuffer
}
return PCMBuffer
swift
avfoundation
avaudioengine
avaudioplayernode
0 Answers
Your Answer