Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Trying to figure out Core Audio's NBandEQ

So I am trying to figure out the ill documented NBandEQ that Apple added in iOS 5. I am able to get it to work great for anything under 16 bands but I want more :) What happens is that if I make it a 15 band EQ everything works but if I go any number 16 and up I get a -10851 (kAudioUnitErr_InvalidPropertyValue) error when I am setting kAUNBandEQProperty_NumberOfBands then the first 8 bands set up fine and the rest result in the -10878 (kAudioUnitErr_InvalidParameter) error. So 15 bands can successfully be done but when I go to 16 all of a sudden only 8 can be done. There is kAUNBandEQProperty_MaxNumberOfBands that I can read that I assumed would be the limit that the device in its current state could handle. Well it spits out erratic numbers everything from 12 digit numbers to 4 digit numbers. I think to myself does it not like the extreme frequencies I am giving it. I eliminated that possibility. Then I realized that the bandwidth of the bands may be overlapping and it doesn't like that. so I reduce the bandwidth from the default .5 to the min. .05 no help there ether.

I did realize that after all my messing around with the settings that was all silly because it starts complaining before I even get to those settings. It is already giving and error in the number of bands.

I am posting this question to see if any more experienced programers can see something in my code that is messing me up and point it out to me. I realize that not to many have venture into core audio much less NBandEQ but maybe I am messing up some basic C so please have a look. I will be very thankful. I am frustrated obviously. Also in posting this code (even tho it is ugly test code) maybe I can help others that come behind. I know I wish there was at least one snippet of code out there that I could have had a look at in relation to NBandEQ

Thanks in advance for the help!

    //Getting max bands for this device???
UInt32 maxNumOfBands;
UInt32 propSize = sizeof(maxNumOfBands);
AudioUnitGetProperty([_equilizer audioUnit],
                     kAUNBandEQProperty_MaxNumberOfBands,
                     kAudioUnitScope_Output,
                     0,
                     &maxNumOfBands,
                     &propSize);
NSLog(@"THIS IS THE MAX NUMBER OF BANDS?---%u",(unsigned int)maxNumOfBands);

UInt32 noBands = [eqFrequencies count];
// Set the number of bands first
NSLog(@"NumberOfBands atempted:%i with result:%ld", (unsigned int)noBands, AudioUnitSetProperty(_equilizer.audioUnit,
                     kAUNBandEQProperty_NumberOfBands,
                     kAudioUnitScope_Global,
                     0,
                     &noBands,
                     sizeof(noBands)));
// Set the frequencies
for (NSUInteger i=0; i<noBands; i++) {
   NSLog(@"Set Frequency for band:%i with result:%ld", i, AudioUnitSetParameter([_equilizer audioUnit],
                          kAUNBandEQParam_Frequency+i,
                          kAudioUnitScope_Global,
                          0,
                          (AudioUnitParameterValue)[[eqFrequencies objectAtIndex:i] floatValue],
                          0));
}
 //set bandwidth
for (NSUInteger i=0; i<noBands; i++) {
    NSLog(@"Set bandwidth for band:%i with result:%ld", i, AudioUnitSetParameter([_equilizer audioUnit],
                          kAUNBandEQParam_Bandwidth+i,
                          kAudioUnitScope_Global,
                          0,
                          0.05,//of octive
                          0));
}

// Set the bypass to off "0"
for (NSUInteger i=0; i<noBands; i++) {
    NSLog(@"Set Bypass for band:%i with result:%ld", i, AudioUnitSetParameter([_equilizer audioUnit],
                                                   kAUNBandEQParam_BypassBand+i,
                                                   kAudioUnitScope_Global,
                                                   0,
                                                   0,//off
                                                   0));
}

}

like image 672
Lucas Goossen Avatar asked Apr 02 '13 02:04

Lucas Goossen


1 Answers

Well I figured it out. I had used kAudioUnitScope_Output on the kAUNBandEQProperty_MaxNumberOfBands it should be kAudioUnitScope_Global.

kAUNBandEQProperty_MaxNumberOfBands resulted in 16 on Sim, iPhone 5, and Retina Ipad.

like image 198
Lucas Goossen Avatar answered Oct 01 '22 17:10

Lucas Goossen