How to use kAULowShelfParam_CutoffFrequency parameter of kAudioUnitSubType_LowShelfFilter which controls bass in Core Audio?

一笑奈何 提交于 2019-12-04 20:21:49

Before you can use an AudioUnit you need to create it. If you're using an AUGraph your code will look something like:

AudioComponentDescription filterDescription = { kAudioUnitType_Effect, kAudioUnitSubType_LowShelfFilter, kAudioUnitSubType_LowShelfFilter, 0, 0 };

AUNode filterNode = -1;
OSStatus result = AUGraphAddNode(mAUGraph, &filterDescription, &filterNode);
if(noErr != result) {
    // Handle error
}

AudioUnit filterUnit = nullptr;
result = AUGraphNodeInfo(mAUGraph, filterNode, nullptr, &filterUnit);
if(noErr != result) {
    // Handle error
}

// Set parameters on filterUnit

The reason your code is failing is that the line

AudioUnit lowShelfAU;

initializes lowShelfAU with an undetermined value. An AudioUnit is a pointer type so without initialization it points to an unknown area of memory. I think it is a programming best practice to always initialize your variables when they are declared, to catch these kinds of bugs:

AudioUnit lowShelfAU = nullptr;
`AudioUnit lowShelfAU;` <-- that is an uninitialized garbage value

you need to actually create an AU instance (the Low Shelf) and add it to an AUGraph.

Note: The compiler/analyzer will identify this problem for you. I recommend people turn the warning levels waaaay up, then build, analyze, and remove all issues. Repeat until clean.

`as you know ,apple create 3 audio units according their purpose. remoteIO --> for input and output;mixer --> for audio mixer ;for some audio effect is eq and Filter so,if u wanna cutoff the audio frequency,u need to create a filter unit and connect them together.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!