如何使用kAudioUnitSubType_LowShelfFilter的kAULowShelfParam_CutoffFrequency参数来控制Core Audio中的低音? [英] How to use kAULowShelfParam_CutoffFrequency parameter of kAudioUnitSubType_LowShelfFilter which controls bass in Core Audio?

查看:182
本文介绍了如何使用kAudioUnitSubType_LowShelfFilter的kAULowShelfParam_CutoffFrequency参数来控制Core Audio中的低音?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在提出这个问题之前,你必须经历过这个问题。如何使用kAudioUnitType_Effect的kAudioUnitSubType_LowShelfFilter控制核心音频中的低音?慢慢地&稳定地掌握音乐的低音控制。但是我的目标却没有成功。现在我知道我必须改变 kAULowShelfParam_CutoffFrequency 来改变低音

You must had gone through this before coming to my this question.How to use kAudioUnitSubType_LowShelfFilter of kAudioUnitType_Effect which controls bass in core Audio? Slowly & Steadily getting the things right for bass control of music. But yet not got succeeded in my objective. Now i got to know that i have to change the kAULowShelfParam_CutoffFrequency to change the bass.

以下代码我在5到7天之前使用过。此代码正常播放音乐,但不能正确改变低音。看看这段代码: -

The following code i was using before 5 to 7 days. this code plays music properly but doesn't change bass properly. have a look on this code snippet:-

 - (void)awakeFromNib
{
printf("AUGraphController awakeFromNib\n");

mIsPlaying = false;

// clear the mSoundBuffer struct
memset(&mUserData.soundBuffer, 0, sizeof(mUserData.soundBuffer));

// create the URLs we'll use for source A and B
NSString *sourceA = [[NSBundle mainBundle] pathForResource:@"04 - Second Hand Jawaani - [rKmania.com]" ofType:@"mp3"];
NSString *sourceB = [[NSBundle mainBundle] pathForResource:@"Track2" ofType:@"mp4"];
sourceURL[0] = CFURLCreateWithFileSystemPath(kCFAllocatorDefault, (CFStringRef)sourceA, kCFURLPOSIXPathStyle, false);
sourceURL[1] = CFURLCreateWithFileSystemPath(kCFAllocatorDefault, (CFStringRef)sourceB, kCFURLPOSIXPathStyle, false);
[bassSlider addTarget:self action:@selector(selectEQPreset) forControlEvents:UIControlEventValueChanged];
}

// output unit
CAComponentDescription output_desc(kAudioUnitType_Output, kAudioUnitSubType_RemoteIO, kAudioUnitManufacturer_Apple);

// iPodEQ unit
CAComponentDescription eq_desc(kAudioUnitType_Effect, kAudioUnitSubType_AUiPodEQ, kAudioUnitManufacturer_Apple);

// multichannel mixer unit
CAComponentDescription mixer_desc(kAudioUnitType_Mixer, kAudioUnitSubType_MultiChannelMixer, kAudioUnitManufacturer_Apple);

printf("add nodes\n");

- (void)selectEQPreset;
{
AUPreset *aPreset = (AUPreset*)CFArrayGetValueAtIndex(mEQPresetsArray, value);
OSStatus result = AudioUnitSetProperty(mEQ, kAudioUnitProperty_PresentPreset, kAudioUnitScope_Global, 0, aPreset, sizeof(AUPreset));
if (result) { printf("AudioUnitSetProperty result %ld %08X %4.4s\n", result, (unsigned int)result, (char*)&result); return; };

printf("SET EQ PRESET %d ", value);
CFShow(aPreset->presetName);
}

现在在这段代码之后我知道我必须改变频率来改变低音,然后我使用下面的代码片段,但在下面的代码片段音乐没有播放,它也给予 excess_bad 。我只是写了我对代码所做的更改。看看当前的代码片段: -

Now after this code i got to know that i have to change frequency to change the bass, then i use the following code snippet but in the following code snippet music is not playing and its giving excess_bad too. i'm just writing the changes i made to the code.have a look on current code snippet:-

// iPodEQ unit
CAComponentDescription eq_desc(kAudioUnitType_Effect, kAudioUnitSubType_LowShelfFilter, kAudioUnitManufacturer_Apple);

- (void)selectEQPreset;
{
AudioUnit lowShelfAU;
assert(lowShelfAU);
float frequencyInHz = 120.0f;
frequencyInHz = bassSlider.value;
OSStatus result = AudioUnitSetParameter(lowShelfAU,kAULowShelfParam_CutoffFrequency,kAudioUnitScope_Global,0,frequencyInHz,0);
if (noErr != result) 
{
    assert(0 && "error!");
    return ;
}
}

此代码现在我正在使用但是这不是改变频率。它甚至停止播放音乐并在这行代码中给出了overs_bad错误..

 AudioUnitSetParameter(lowShelfAU,kAULowShelfParam_CutoffFrequency,kAudioUnitScope_Global,0,frequencyInHz,0);

请有人帮我这个告诉我如何更改kAULowShelfParam_CutoffFrequency以便我可以调整低音音乐通过滑块。任何有关这方面的帮助都会非常明显。

Please anybody help me regarding this tell me how can i change the kAULowShelfParam_CutoffFrequency so that i can adjust the bass of music Via slider. Any help regarding this would be highly appreciable.

谢谢:)

推荐答案

在使用 AudioUnit 之前,您需要创建它。如果您使用 AUGraph ,您的代码将类似于:

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;

使用未确定的值初始化 lowShelfAU AudioUnit 是指针类型,因此在没有初始化的情况下,它指向未知的内存区域。我认为在声明变量时始终初始化变量是一种编程最佳实践,以捕获这些类型的错误:

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;

这篇关于如何使用kAudioUnitSubType_LowShelfFilter的kAULowShelfParam_CutoffFrequency参数来控制Core Audio中的低音?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆