4

I build a music player app using AVplayer. The app access and play songs from iPod library. This is how I play mediaItem using AVPlayer

MPMediaItem *mediaItem = ...
NSURL *assetUrl = [mediaItem valueForProperty:MPMediaItemPropertyAssetURL];
AVPlayerItem *playerItem = [AVPlayerItem playerItemWithURL:assetUrl];
self.player = [AVPlayer playerWithPlayerItem:playerItem];

I need to add graphical equaliser to my app to allow users to change the following values

enter image description here enter image description here

It seems audio processing in iOS is different from other frameworks. I did an R&D and found

  • Audio unit
  • MTAudioProcessingTap
  • NVDSP
  • Novocaine
  • OpenAL

My questions are, Is it possible to create custom equaliser with AVPlayer? What technology should I use for my requirement (creating a custom equaliser with AVPlayer)?

P.S. Can any one give a simple working example which I can add to the project and check the changes in the song (I tried the apple documentations, but it is not clear)

Update

btw I built my own eq & processing lib https://github.com/clementprem/CPAudioPlayer

Clement Prem
  • 3,112
  • 2
  • 23
  • 43

2 Answers2

2

AVPlayer will be of no use to you, since it only provides a high level interface.

I implemented an audio equaliser some time ago and my suggestion is going with Novocaine, which uses NVDSP and Audio Unit (and makes it simpler, actually). Novocaine even includes an Equalizer class, so you just need integrating it into your app (if you do not do streaming, that is really straightforward).

sergio
  • 68,819
  • 11
  • 102
  • 123
  • I need to support background & remote control event handling & other basic functionalities of a music app. Is it possible with Novocaine? – Clement Prem Aug 12 '14 at 10:27
  • 1
    background, remote control etc. are all fine with audio units. novocaine really gives you an almost ready-made solution for you. AVPlayer provides a very simple interface, audio unit is what you need. – sergio Aug 12 '14 at 10:52
  • I agree. I've made this in [KREAFUNK](https://itunes.apple.com/us/app/kreafunk-listen-to-anything/id807353001?mt=8). You need to build your own audio graph or use a 3rd party library like [Novocaine](https://github.com/alexbw/novocaine) or [The Amazing Audio Engine](http://theamazingaudioengine.com). – Trenskow Aug 12 '14 at 10:53
  • @Trenskow I checked you app it is cool. what did you use for the equaliser & for music player? (hope u don't have any NDA related issue :) ) – Clement Prem Aug 12 '14 at 12:17
  • I build an audio graph using the AUGraph and AudioUnit APIs. It's not for the faint of hearted. C API and very strict thread synchronization issues. I think I would have used something like Novocaine today if I should start over. :) – Trenskow Aug 13 '14 at 18:52
  • @Trenskow ok. Btw I created a music player using Augraph & audio unit. Btw I had a look at Navocaine but how can we add audio unit to novocaine player. For example iPod eq (kAudioUnitProperty_PresentPreset)? – Clement Prem Aug 20 '14 at 11:18
0

This can be done by NOVOCAINE.

Take the code to instantiate a NVPeakingEQFilter:

    NVPeakingEQFilter* PEQ = [[NVPeakingEQFilter alloc] initWithSamplingRate:self.samplingRate];
    PEQ.Q = QFactor;
    PEQ.G = gain;
    PEQ.centerFrequency = centerFrequencies;

you need define 3 parameters: Q, G, and centerFrequency. Both Q and centerFrequency are usually fixed (QFactor in my case is a constant equal to 2.0).

So, you have 10 sliders: each one corresponds to a fixed centerFrequency. I suggested iTunes values: 32Hz, 64Hz, 125Hz, 250Hz, 500Hz, 1KHz, 2KHz, 4KHz, 8KHz, 16KHz. You do not want to change those values when the slider value changes.

What you want to change when the slider value changes is the gain (G). At init time, G can be set to 0.0. This means "no amplification/attenuation".

When the slider moves, you change G, so actually you would do:

PEQ[sender.tag - 1].G = sender.value * kNominalGainRange;

where kNominalGainRange is 12.0, so if sender.value goes from -1.0 to +1.0, G goes from -12 to +12.

Hope this helps.