开发者

How to store a cfdictionaryref into an NSDictionary

开发者 https://www.devze.com 2023-03-04 21:17 出处:网络
I am trying to store the parameters of an audiounit into an NSDictionary using the following method. OSStatus AudioEngineModel::getParameterStateOfEffect(NSInteger nEffectID, CFDictionaryRef * pcfDic

I am trying to store the parameters of an audiounit into an NSDictionary using the following method.

OSStatus AudioEngineModel::getParameterStateOfEffect(NSInteger nEffectID, CFDictionaryRef * pcfDictRef_ParameterData, UInt32* pun32DataSize)
{
    Boolean outWritable;
    OSStatus err= AudioUnitGetPropertyInfo(m_aEffectNodes[nEffectID].audioUnit, kAudioUnitProperty_ClassInfo, kAudioUnitScope_Global, 0, &*pun32DataSize, &outWritable);
    if(err != noErr)
    {
        NSLog(@"ERROR AudioEngineModel::getParameterStateOfEffect:: AudioUnitGetPropertyInfo\n");
        return err;
    }

    *pcfDictRef_ParameterData= (CFDictionaryRef)malloc(*pun32DataSize);

    err= AudioUnitGetProperty (m_aEffectNodes[nEffectID].audioUnit, kAudioUnitProperty_ClassInfo, kAudioUnitScope_Globa开发者_运维技巧l, 0, (void*)*pcfDictRef_ParameterData, &*pun32DataSize);
    if(err != noErr)
    {
        NSLog(@"ERROR AudioEngineModel::getParameterStateOfEffect:: AudioUnitGetProperty\n");
        return err;
    }    


    m_cfDictRef_ParameterData= *pcfDictRef_ParameterData; 
    m_pdParameterData= [NSDictionary dictionaryWithDictionary:(NSDictionary*)m_cfDictRef_ParameterData];

    return noErr;                               
}

Everything works great until the NSDictionary dictionaryWithDictionary: call, where I consistently get exc_bad_access.

I call this method like so.

CFDictionaryRef cfDictRef_ParameterData;
UInt32 un32DataSize;    
OSStatus err= [[[NSApp delegate] getMainController] getParameterStateOfEffect:m_nEffectTypeID parameterData:&cfDictRef_ParameterData dataSize:&un32DataSize];


Your problem is in these lines:

*pcfDictRef_ParameterData= (CFDictionaryRef)malloc(*pun32DataSize);

err= AudioUnitGetProperty (m_aEffectNodes[nEffectID].audioUnit, kAudioUnitProperty_ClassInfo, kAudioUnitScope_Global, 0, (void*)*pcfDictRef_ParameterData, &*pun32DataSize);

The malloc is unnecessary. AudioUnitGetProperty will return a CFDictionaryRef for kAudioUnitProperty_ClassInfo. Since pcfDictRef_ParameterData is already a CFDictionaryRef*, you don't need to allocate anything.

You do need to pass the pointer to the CFDictionaryRef (not dereferenced) to AudioUnitGetProperty. So the second line should be:

err= AudioUnitGetProperty (m_aEffectNodes[nEffectID].audioUnit, kAudioUnitProperty_ClassInfo, kAudioUnitScope_Global, 0, (void*)pcfDictRef_ParameterData, pun32DataSize);

instead.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号