avaudiopcmbuffer

AVAudioPCMBuffer for music files

寵の児 提交于 2019-12-04 20:23:32
I've been trying to play music in my SpriteKit game and used the AVAudioPlayerNode class to do so via AVAudioPCMBuffer s. Every time I exported my OS X project, it would crash and give me an error regarding audio playback. After banging my head against the wall for the last 24 hours I decided to re-watch WWDC session 501 (see 54:17). My solution to this problem was what the presenter used, which is to break the frames of the buffer into smaller pieces to break up the audio file being read. NSError *error = nil; NSURL *someFileURL = ... AVAudioFile *audioFile = [[AVAudioFile alloc]

how to play sound with AVAudioPCMBuffer

那年仲夏 提交于 2019-12-03 14:01:31
I Cannot play sound with AVAudioPCMBuffer (though I could play with AVAudioFile). I got this error. ERROR: AVAudioBuffer.mm:169: -[AVAudioPCMBuffer initWithPCMFormat:frameCapacity:]: required condition is false: isCommonFormat here is my code below, and I'd really appreciate for your help. import UIKit import AVFoundation class ViewController: UIViewController { let audioEngine: AVAudioEngine = AVAudioEngine() let audioFilePlayer: AVAudioPlayerNode = AVAudioPlayerNode() override func viewDidLoad() { super.viewDidLoad() // Do any additional setup after loading the view, typically from a nib.

Convert AVAudioPCMBuffer to NSData and back

五迷三道 提交于 2019-11-27 22:58:20
How to convert AVAudioPCMBuffer to NSData ? If it should be done as let data = NSData(bytes: buffer.floatChannelData, length: bufferLength) then how to calculate bufferLength ? And how to convert NSData to AVAudioPCMBuffer ? Buffer length is frameCapacity * bytesPerFrame. Here are functions that can do conversion between NSData and AVAudioPCMBuffer. func toNSData(PCMBuffer: AVAudioPCMBuffer) -> NSData { let channelCount = 1 // given PCMBuffer channel count is 1 var channels = UnsafeBufferPointer(start: PCMBuffer.floatChannelData, count: channelCount) var ch0Data = NSData(bytes: channels[0],

Convert AVAudioPCMBuffer to NSData and back

巧了我就是萌 提交于 2019-11-26 23:03:15
问题 How to convert AVAudioPCMBuffer to NSData ? If it should be done as let data = NSData(bytes: buffer.floatChannelData, length: bufferLength) then how to calculate bufferLength ? And how to convert NSData to AVAudioPCMBuffer ? 回答1: Buffer length is frameCapacity * bytesPerFrame. Here are functions that can do conversion between NSData and AVAudioPCMBuffer. func toNSData(PCMBuffer: AVAudioPCMBuffer) -> NSData { let channelCount = 1 // given PCMBuffer channel count is 1 var channels =