avaudioplayernode

how to play sound with AVAudioPCMBuffer

你。 提交于 2019-12-21 04:49:08
问题 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

AVAudioPlayerNode playing unexpectedly multiple times

£可爱£侵袭症+ 提交于 2019-12-13 03:51:12
问题 On top of a background audio file, I want to play a sequence of 8 audio files. By touching a segmented control, the user has the possibility to choose which sounds will be played on top of the background file. playCountOneAndFive(index: index) playCountOneToSeven(index: index) playCountOneToEight(index: index) The problem I am facing is that when I try to switch playing from one function to another, some of the nodes end up playing simultaneously several times. For example instead of playing

AVAudioPlayer.play() works but AVAudioPlayerNode.play() fails

扶醉桌前 提交于 2019-12-11 11:45:47
问题 I have the following Swift playground code that plays an audio file using AVAudioPlayerNode. import AVFoundation import Foundation NSSetUncaughtExceptionHandler { exception in print("Exception thrown: \(exception)") } var filePath = "/Users/fractor/Desktop/TestFile.mp3" let file : AVAudioFile do { file = try AVAudioFile(forReading: URL(fileURLWithPath: filePath)) } catch let error { print(error.localizedDescription) throw error } let audioEngine = AVAudioEngine() let playerNode =

AVAudioPCMBuffer built programmatically, not playing back in stereo

眉间皱痕 提交于 2019-12-10 21:55:32
问题 I'm trying to fill an AVAudioPCMBuffer programmatically in Swift to build a metronome. This is the first real app I'm trying to build, so it's also my first audio app. Right now I'm experimenting with different frameworks and methods of getting the metronome looping accurately. I'm trying to build an AVAudioPCMBuffer with the length of a measure/bar so that I can use the .Loops option of the AVAudioPlayerNode's scheduleBuffer method. I start by loading my file(2 ch, 44100 Hz, Float32, non

How to cancel or remove echo/repeated sound with AVAudioEngine?

人盡茶涼 提交于 2019-12-08 09:19:27
问题 I am using the AVAudioEngine for audio streaming. But when I speak any word into the mic, it repeats multiple times, just like echo effect. I want when I speak, it sounds only one time, not multiple times. I want to cancel the echo or extra noise. How can I achieve this? var peerAudioEngine: AVAudioEngine = AVAudioEngine() var peerAudioPlayer: AVAudioPlayerNode = AVAudioPlayerNode() var peerInput: AVAudioInputNode? var peerInputFormat: AVAudioFormat? func setUpAVPlayer() { self.peerInput =

Playing Multiple WAV out Multiple Channels AVAudioEngine

随声附和 提交于 2019-12-08 02:01:36
问题 I have 15 WAV files that I need to play back in sequence all on individual channels. I'm starting out trying to get two files working with a left / right stereo separation. I’m creating an audio engine, a mixer and two AVAudioPlayerNodes. The audio files are mono and I’m trying to get the file from PlayerA to come out the left channel and the file from PlayerB to come out the right channel. What I’m having trouble understanding is how the AudioUnitSetProperty works. It seems to relate to a

AVAudioEngine inputNode's format changes when playing an AVAudioPlayerNode

我只是一个虾纸丫 提交于 2019-12-07 11:17:48
问题 I'll start with a simple "playground" view controller class I've made that demonstrates my problem: class AudioEnginePlaygroundViewController: UIViewController { private var audioEngine: AVAudioEngine! private var micTapped = false override func viewDidLoad() { super.viewDidLoad() configureAudioSession() audioEngine = AVAudioEngine() } @IBAction func toggleMicTap(_ sender: Any) { guard let mic = audioEngine.inputNode else { return } if micTapped { mic.removeTap(onBus: 0) micTapped = false

Playing Multiple WAV out Multiple Channels AVAudioEngine

ぐ巨炮叔叔 提交于 2019-12-06 10:53:08
I have 15 WAV files that I need to play back in sequence all on individual channels. I'm starting out trying to get two files working with a left / right stereo separation. I’m creating an audio engine, a mixer and two AVAudioPlayerNodes. The audio files are mono and I’m trying to get the file from PlayerA to come out the left channel and the file from PlayerB to come out the right channel. What I’m having trouble understanding is how the AudioUnitSetProperty works. It seems to relate to a single file only and seems to only be able to have one per audioUnit? I’m wondering if there is a way I

AVAudioEngine inputNode's format changes when playing an AVAudioPlayerNode

随声附和 提交于 2019-12-05 15:47:39
I'll start with a simple "playground" view controller class I've made that demonstrates my problem: class AudioEnginePlaygroundViewController: UIViewController { private var audioEngine: AVAudioEngine! private var micTapped = false override func viewDidLoad() { super.viewDidLoad() configureAudioSession() audioEngine = AVAudioEngine() } @IBAction func toggleMicTap(_ sender: Any) { guard let mic = audioEngine.inputNode else { return } if micTapped { mic.removeTap(onBus: 0) micTapped = false return } stopAudioPlayback() let micFormat = mic.inputFormat(forBus: 0) print("installing tap: \(micFormat

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.