我正在尝试在Mac OS X API(音频队列服务)中但在Cocoa(实际上只是Foundation)应用程序(实际上只是一个“工具”)中遵循C++接口(interface)的教程。它具有如下结构:
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
};
将第4项转换为Objective-C时遇到了很多麻烦,因为我不知道如何
@synthesize
一个C数组。具体来说,这就是我到目前为止所拥有的: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
无法按以下方式进行编译:“错误:综合属性'buffers'必须与兼容的ivar命名相同,或者必须显式命名ivar”显然,这是因为相应的ivar被命名为
_buffers
而不是buffers
-但这是必要的,因为我无法将属性定义为数组(可以吗?@property(assign) *AudioQueueBufferRef buffers
是语法错误)如何将ivar定义为
AudioQueueBufferRef
结构数组,或综合属性使其引用_buffers
数组? 最佳答案
尝试:
@synthesize buffers = _buffers;