I'm trying to record audio output that is being dynamically generated out of local audio files.
So let's say I have one audio file "drums.mp3", and I'm currently playing it in a loop like this:
var drumSoundEffect: AVAudioPlayer!
var repeatTimer: NSTimer!
var url: NSURL!
let soundInterval: NSTimeInterval = 1
@IBAction func playSoundTapped(sender: AnyObject) {
initSound()
initAndStartTimer()
}
func initSound() {
let path = NSBundle.mainBundle().pathForResource("drums.mp3", ofType: nil)!
url = NSURL(fileURLWithPath: path);
}
func initAndStartTimer() {
repeatTimer = NSTimer.scheduledTimerWithTimeInterval(soundInterval, target: self, selector: #selector(playSound), userInfo: nil, repeats: true)
repeatTimer.fire()
}
func playSound() {
do {
let sound = try AVAudioPlayer(contentsOfURL: url)
drumSoundEffect = sound
sound.play()
} catch {
//an error occurred...
}
}
When I try to add the AVAudioRecorder functionality, it seems it is ONLY recording from the microphone, and not from the audio I'm generating... From what I found in the internet it seems that AVFoundation is only capable to record from mic so this is not the right choice for my scenario. This example seems to be quite promising, but I simply have no clue how to create a working sample app out of it. I know this question is quite generic, but maybe somebody could give me a hint on this anyway?
Thanks a lot.