Setting rate on AudioUnit subtype kAudioUnitSubType_NewTimePitch

不问归期 提交于 2019-12-12 03:59:49

问题


I'm trying to get/set the rate of an AudioUnit with subtype kAudioUnitSubType_NewTimePitch.

The audio unit is added to an AUGraph, through an AUNode, which has the following component description:

acd->componentType = kAudioUnitType_Effect;
acd->componentSubType = kAudioUnitSubType_NewTimePitch;
acd->componentManufacturer = kAudioUnitManufacturer_Apple;

According to AudioUnitParameters.h, get/set the rate should be as simple as get/set the rate parameter on the audio unit.

// rate control.
// Global, rate, 1/32 -> 32.0, 1.0
kNewTimePitchParam_Rate                         = 0,

However, while setting the value seems no problem (no error is returned) getting the value yields a OSStatus with value -10878 (kAudioUnitErr_InvalidParameter).

Here is how I set the value :

- (void)setTempo:(float)value {
    OSStatus err = noErr;
    err = AudioUnitSetParameter(tempoUnit, kNewTimePitchParam_Rate, kAudioUnitScope_Global, 0, (Float32)value, 0);
    if (err != noErr) {
        NSLog(@"Could not set tempo unit rate: %d", err);
    } // no error
}

and how I (try to) get it :

- (float)tempo {
    OSStatus err = noErr;
    Float32 value = 1.0;
    err = AudioUnitGetParameter(tempoUnit, kNewTimePitchParam_Rate, kAudioUnitScope_Global, 0, &value);
    if (err != noErr) {  // -10878
        NSLog(@"Could not get tempo unit rate: %d", err);
    }
    return value;
}

The input of the node is connected to a mixer node, and the output to the RemoteIO unit.

Any ideas ?


回答1:


It turns out the type of the Audio Unit was wrong.

I changed for kAudioUnitType_FormatConverter for the type and kept the same subtype.

Both get/set the tempo now works as expected.

I'm still unclear about why I didn't get any error, neither on setting up the audio unit, nor when setting the value for the rate.



来源:https://stackoverflow.com/questions/44744683/setting-rate-on-audiounit-subtype-kaudiounitsubtype-newtimepitch

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