Search code examples
iosswiftavplayerequalizer

IOS: How to increase the Bass and Treble of a AVAudioPlayer in Swift?


  1. Anyone knows how to increase the bass and treble of a track ?

  2. Within the same track, if I do a split into 3 sections, can I adjust & have say 3 different level of reverb, ie one in each section ?

Thanks


Solution

  • I don't think it is possible to use EQ effects with an AVAudioPlayer.

    A quick search gave me answers like this from StackOverflow:

    can I use AVAudioPlayer to make an equalizer player?

    Or this sadly unanswered question from Apple Developer Forums:

    https://forums.developer.apple.com/thread/46998

    Instead

    What you can do instead is use the AVAudioEngine (https://developer.apple.com/reference/avfoundation/avaudioengine) which gives you the opportunity to add an EQ node (or other effect nodes) to your AVAudioPlayer node.

    AVAudioEngine may seem daunting at first, but think of it as a mixer. You have some input nodes that generate sound (AVAudioPlayer nodes for instance), and you can then attach and connect those notes to your AVAudioEngine. The AVAudioEngine has a AVAudioMixerNode so you can control things like volume and so forth.

    Between your input nodes and your mixer you can attach effect nodes, like an EQ node for instance and you can add a "tap" and record the final output to a file if so desired.

    Reading material

    This slideshare introduction helped me a great deal understanding what AVAudioEngine is (the code is Objective C though, but it should be understandable)

    The AVAudioEngine in Practice from WWDC 2014 is a great introduction too.

    So, I hope you are not frightened by the above, as said, it may seem daunting when you see it at first, but once you get it wired together it works fine and you have the option to add other effects than just EQ (pitch shifting, slowing down a file and so on).

    Hope that helps you.