I'm trying to follow a tutorial for a C++ interface in the Mac OS X API (Audio Queue Services), but in a Cocoa (well, actually just Foundation) application (well, actually just a 'tool'). It has a struct that looks like this:
static const int kNumberBuffers = 3; // 1
struct AQPlayerState {
AudioStreamBasicDescription mDataFormat; // 2
AudioQueueRef mQueue; // 3
AudioQueueBufferRef mBuffers[kNumberBuffers]; // 4
AudioFileID mAudioFile; // 5
UInt32 bufferByteSize; // 6
SInt64 mCurrentPacket; // 7
UInt32 mNumPacketsToRead; // 8
AudioStreamPacketDescription *mPacketDescs; // 9
bool mIsRunning; // 10
};
I'm having a lot of trouble with translating item 4 into Objective-C, because I can't figure out how to @synthesize
a C array. Specifically, this is what I have so far:
PlayerState.h
#import <Foundation/Foundation.h>
#import <AudioToolbox/AudioQueue.h>
@interface PlayerState : NSObject {
AudioStreamBasicDescription dataFormat;
AudioQueueRef queue;
AudioQueueBufferRef _buffers[3];
int audioFile; // make this an actual type?
UInt32 bufferByteSize;
SInt64 currentPacket;
UInt32 numPacketsToRead;
AudioStreamPacketDescription* packetDescs;
bool isRunning;
}
@property(assign) AudioStreamBasicDescription dataFormat;
@property(assign) AudioQueueRef queue;
@property(assign) AudioQueueBufferRef buffers;
@property(assign) int audioFile;
@property(assign) UInt32 bufferByteSize;
@property(assign) SInt64 currentPacket;
@property(assign) UInt32 numPacketsToRead;
@property(assign) AudioStreamPacketDescription* packetDescs;
@property(assign) bool isRunning;
@end
PlayerState.m
#import "PlayerState.h"
@implementation PlayerState
@synthesize dataFormat;
@synthesize queue;
@synthesize buffers;
@synthesize audioFile;
@synthesize bufferByteSize;
@synthesize currentPacket;
@synthesize numPacketsToRead;
@synthesize packetDescs;
@synthesize isRunning;
@end
@synthesize buffers
fails to compile as follows: "error: synthesized property 'buffers' must either be named the same as a compatible ivar or must explicitly name an ivar"
This is obviously because the corresponding ivar is named _buffers
and not buffers
- but this is necessary, because I can't define a property as an array (can I? @property(assign) *AudioQueueBufferRef buffers
is a syntax error)
What can I do to either define the ivar as an array of AudioQueueBufferRef
structs, or synthesize the property such that it refers to the _buffers
array?