I have certain data in the AudioBuffer(from the recording). Before I write this buffer to file, I want to do something with the PCM samples. How do I read from the AudioBuffer's mData field like I can read using fread? Can I use fread in a .mm or .m file?
The AudioBuffer struct holds it's data in the memory, not in a file. Therefore fread is not relevant.
The mBuffer is just a pointer to the beginning of the data, and you can use the other two fields of the struct in order to read the data correctly. From this link:
struct AudioBuffer {
UInt32 mNumberChannels;
UInt32 mDataByteSize;
void *mData;
};
mDataByteSize tells you how many bytes the buffer holds (so you won't access memory pass the end of the buffer), and the mNumberChannels tells you how to re-order your data, e.g. if the buffer holds two channels, then the data is interlaced, i.e samples 1,3,5,... are from channel 1, and 2,4,6,... from channel 2.
Keep in mind you are also responsible for casting the data to the correct type.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With