iphoneiosobjective-caudiotoolbox

Use of undeclared identifier


I'm trying to use this project which is a synthesizer for Objective-C for an iPhone application I'm building. However, I'm having trouble with the MHAudioBufferPlayer class.

In the MHAudioBufferPlayer.m class, I'm getting a bunch of Use of undeclared identifier errors for _gain, _playing, and _audioFormat. This makes sense, as those identifiers are never declared with an underscore in front of them. However, they are declared in the MHAudioBufferPlayer.h class without the underscores.

I'm sort of confused by this as I'm new to Objective-C. Does an underscore denote a special action to be taken? Is it supposed to be translated into self.gain, self.playing, etc.? How can I fix this? Or is this code just buggy?

- (id)initWithSampleRate:(Float64)sampleRate channels:(UInt32)channels bitsPerChannel:(UInt32)bitsPerChannel packetsPerBuffer:(UInt32)packetsPerBuffer
{
    if ((self = [super init]))
    {
        _playing = NO;
        _playQueue = NULL;
        _gain = 1.0;

        _audioFormat.mFormatID         = kAudioFormatLinearPCM;
        _audioFormat.mSampleRate       = sampleRate;
        _audioFormat.mChannelsPerFrame = channels;
        _audioFormat.mBitsPerChannel   = bitsPerChannel;
        _audioFormat.mFramesPerPacket  = 1;  // uncompressed audio
        _audioFormat.mBytesPerFrame    = _audioFormat.mChannelsPerFrame * _audioFormat.mBitsPerChannel/8;
        _audioFormat.mBytesPerPacket   = _audioFormat.mBytesPerFrame * _audioFormat.mFramesPerPacket;
        _audioFormat.mFormatFlags      = kLinearPCMFormatFlagIsSignedInteger | kLinearPCMFormatFlagIsPacked;

        _packetsPerBuffer = packetsPerBuffer;
        _bytesPerBuffer = _packetsPerBuffer * _audioFormat.mBytesPerPacket;

        [self setUpAudio];
    }
    return self;
}

Solution

  • If you are using new compiler that comes with Xcode4.4 onwards, then for each of your property it creates an automatic synthesize with _(underscore) as prefix.

    Like, if you have created @property.... playing;

    then the compiler creates @synthesize playing=_playing;

    If you are in older versions of Xcode, this need to be done manually.