简体   繁体   中英

exporting filtered audio using AudioKit 5

I've been unable to find any examples that walk one through how to export audio that you have piped through AudioKit's 5 filters.

I want to add some effect to the audio (like reverb..etc) then export filtered audio

here my try:

    // load empty file to write
    let docs = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first!
    let dstURL:URL =  docs.appendingPathComponent("rendred.caf")
    var audioFile:AVAudioFile!
    do {
        audioFile = try AVAudioFile(forReading: dstURL)
    } catch {
        Log("Could not load file")
    }
    
    // duration of audio after add some effects 
    let duration = self.conductor.player.duration
    let rendredTime = Double(duration)
    
    // using AudioEngine() to export mixed audio but it's not work <----🛑
    do {
        try? self.conductor.engine.renderToFile(audioFile, duration: rendredTime, prerender: {
            self.conductor.player.play()
        })
    }

I'm not sure how renderToFile() function work

It's hard to answer without your answers to what Mark Jeschke asked you but in general:

You can load the audio file, create a new reverb (like CostelloReverb for example). Put the loaded audio as a node to the reverb. Put the reverb as the output (again - it depends what exactly you want to do) to the AudioEngine output.

If you want to blend with playback you can use DryWetMixer.

Some general example:

import Foundation
import AudioKit
import SoundpipeAudioKit

class AudioProcessing {

let audioFile:(choose the way you want to load/play)
let playback :(same)
let reverb:CostelloReverb
let dryWetMix:DryWetMixer
let engine = AudioEngine()

    init() {
   
        (init the audioFile and playback here)

        reverb = CostelloReverb(audioFile)
        dryWetMix = DryWetMixer(playback, reverb)
        engine.output = dryWetMix
        
    }

}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM