2010-06-15 40 views
3

我正在开发一个使用扩展音频文件服务的iPhone应用程序。我尝试使用ExtAudioFileRead读取音频文件,并将数据存储在AudioBufferList结构中。ExtAudioFileRead和AudioBuffer for iPhone SDK问题

AudioBufferList被定义为:

struct AudioBufferList { 
UInt32  mNumberBuffers; 
AudioBuffer mBuffers[1]; 
}; 
typedef struct AudioBufferList AudioBufferList; 

AudioBuffer被定义为

struct AudioBuffer { 
    UInt32 mNumberChannels; 
    UInt32 mDataByteSize; 
    void* mData; 
}; 
typedef struct AudioBuffer AudioBuffer; 

我想操纵MDATA但我不知道什么是无效*意思。为什么它无效*?我怎样才能决定实际存储在mData中的数据类型?

回答

1

mData字段被标记为无效,因为不同的音频格式有不同的存储要求。

基本上在C中void指针可以指向任何东西。

所以你可以说

mData = (SInt32 *)malloc(sizeof(Sint32) * numElements); 

,然后当你要使用它,它转换为你想要的数据类型。

Sint32 *myBuffer = (SInt32 *)mData; 
1

可以与

AudioStreamBasicDescription inputFileFormat; 
UInt32 dataSize = (UInt32)sizeof(inputFileFormat); 
ExtAudioFileGetProperty(inputFile, kExtAudioFileProperty_FileDataFormat, &dataSize, &inputFileFormat); 
size_t sizeOfFrame = inputFileFormat.mBytesPerFrame; 

确定元件的大小在MDATA阵列(帧的大小)然后可以将其解释任何符号的类型与相同的大小(对于每个帧是可以在通常的4个字节是Sint32或Float32)。