我正在开发一个使用扩展音频文件服务的iPhone应用程序。我尝试使用ExtAudioFileRead读取音频文件,并将数据存储在AudioBufferList结构中。
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中实际存储的数据类型?
发布于 2010-06-16 02:41:20
mData字段被标记为“无效”,因为不同的音频格式有不同的存储要求。
基本上,在C中,一个空指针可以指向任何东西。
所以你可以说
mData = (SInt32 *)malloc(sizeof(Sint32) * numElements);然后,当您想要使用它时,将其强制转换为所需的数据类型。
Sint32 *myBuffer = (SInt32 *)mData;发布于 2012-09-17 17:08:38
您可以使用以下方法确定mData数组中元素的大小(帧大小)
AudioStreamBasicDescription inputFileFormat;
UInt32 dataSize = (UInt32)sizeof(inputFileFormat);
ExtAudioFileGetProperty(inputFile, kExtAudioFileProperty_FileDataFormat, &dataSize, &inputFileFormat);
size_t sizeOfFrame = inputFileFormat.mBytesPerFrame;然后,您可以将其解释为具有相同大小的任何有符号类型(通常每帧4个字节,可以是Sint32或Float32)。
https://stackoverflow.com/questions/3048514
复制相似问题