Sunday, April 19, 2026
HomeiOS Developmentios - My AVAudioUnitEQ doesn't works not like AVAudioUnitTimePitch for AVAudioEngine()

ios – My AVAudioUnitEQ doesn’t works not like AVAudioUnitTimePitch for AVAudioEngine()

[ad_1]

I used to be enjoying with AVAudioEngine to make use of it in an app.
I’m altering pitch and equalizer (acquire) parameters with sliders whereas music was enjoying.

Pitch works however equalizer just isn’t working.
I couldn’t discover the trigger.

var audioEngine = AVAudioEngine()
var audioFilePlayer = AVAudioPlayerNode()
let auTimePitch = AVAudioUnitTimePitch()
var equalizer = AVAudioUnitEQ()

func startEngine(){
 guard let filePath: String = Bundle.important.path(forResource: "testMusic", ofType: "mp3") else{ return }
    let fileURL: URL = URL(fileURLWithPath: filePath)
    guard let audioFile = attempt? AVAudioFile(forReading: fileURL) else { return }
    
    
    let audioFormat = audioFile.processingFormat
    let audioFrameCount = UInt32(audioFile.size)
    guard let audioFileBuffer = AVAudioPCMBuffer(pcmFormat: audioFormat,
                                                 frameCapacity: audioFrameCount)  else {  return }
    
    do{
        attempt audioFile.learn(into: audioFileBuffer)
    } catch{
        print("over")
    }
    
    let mainMixer = audioEngine.mainMixerNode
    



    auTimePitch.pitch = 1
    auTimePitch.charge = 1 


    equalizer = AVAudioUnitEQ(numberOfBands: 5)
    let bands = equalizer.bands
    let freqs = [60, 230, 910, 4000, 14000]
    
    for i in 0..<bands.rely {
        bands[i].frequency  = Float(freqs[i])
        bands[i].bypass     = false
        bands[i].filterType = .parametric
        bands[i].acquire = 0
        bands[i].bandwidth = 1
    }


    let format = mainMixer.outputFormat(forBus: 0)
    
    
    
    audioEngine.join(audioFilePlayer,
                        to: equalizer,
                        format: format)
    
    audioEngine.join(audioFilePlayer,
                        to:auTimePitch,
                        format: format)
    
    
    
  
    audioEngine.join(equalizer,
                        to: mainMixer,
                        format: format)
    
    audioEngine.join(auTimePitch,
                        to: mainMixer,
                        format: format)
    

   
        
    attempt? audioEngine.begin()
    audioFilePlayer.play()
    
    audioFilePlayer.scheduleBuffer(audioFileBuffer, at: nil,
                                   choices:AVAudioPlayerNodeBufferOptions.loops)
    
 }   
    

[ad_2]

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments