Advertise here




Advertise here

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

HELP Please. Sound effect and record using AVAUDIOENGINE

davut5davut5 Posts: 10New Users Noob
edited September 2015 in iOS SDK Development
i want to record my voice with reverb effect. i hear my voice with effect while recording.
When I listen to my voice after recording is finished, I hear my voice none-effect. WHY?
here is my code.

var reverb = AVAudioUnitReverb()
var engine = AVAudioEngine()
var file: AVAudioFile?
var player = AVAudioPlayerNode() // if you need play record later

override func viewDidLoad() {
super.viewDidLoad()



// Do any additional setup after loading the view, typically from a nib.
file = AVAudioFile(forWriting: URLFor("my_file.caf")!, settings: engine.inputNode.inputFormatForBus(0).settings, error: nil)

reverb.loadFactoryPreset(AVAudioUnitReverbPreset.Cathedral)
reverb.wetDryMix = 80
engine.attachNode(reverb)

engine.attachNode(player)

engine.connect(engine.inputNode, to: reverb, format: engine.inputNode.inputFormatForBus(0)) //configure graph

engine.connect(reverb, to: engine.mainMixerNode, format: engine.mainMixerNode.outputFormatForBus(0))



engine.startAndReturnError(nil)
}

@IBAction func record(sender: AnyObject) {
engine.inputNode.installTapOnBus(0, bufferSize: 1024, format: engine.mainMixerNode.outputFormatForBus(0)) { (buffer, time) -> Void in
self.file?.writeFromBuffer(buffer, error: nil)
return



}
}

@IBAction func stop(sender: AnyObject) {
engine.inputNode.removeTapOnBus(0)
}


func URLFor(filename: String) -> NSURL? {
if let dirs : [String] = NSSearchPathForDirectoriesInDomains(NSSearchPathDirectory.DocumentDirectory, NSSearchPathDomainMask.AllDomainsMask, true) as? [String] {
let dir = dirs[0] //documents directory
let path = dir.stringByAppendingPathComponent(filename)
return NSURL(fileURLWithPath: path)
}
return nil
}
Post edited by davut5 on
Sign In or Register to comment.