Hi guys,
i'm tring to understand the Audio * things for iPhone
currently i'm reading: core audio overview
here i got a question:
from apple example codes:
- (void) calculateSizesFor: (Float64) seconds {
UInt32 maxPacketSize;
UInt32 propertySize = sizeof (maxPacketSize);
AudioFileGetProperty (
audioFileID,
kAudioFilePropertyPacketSizeUpperBound,
&propertySize,
&maxPacketSize
);
static const int maxBufferSize = 0x10000; // limit maximum size to 64K
static const int minBufferSize = 0x4000; // limit minimum size to 16K
if (audioFormat.mFramesPerPacket) {
Float64 numPacketsForTime =
audioFormat.mSampleRate / audioFormat.mFramesPerPacket * seconds;
[self setBufferByteSize: numPacketsForTime * maxPacketSize];
} else {
// if frames per packet is zero, then the codec doesn't know the
// relationship between packets and time. Return a default buffer size
[self setBufferByteSize:
maxBufferSize > maxPacketSize ? maxBufferSize : maxPacketSize];
}
// clamp buffer size to our specified range
if (bufferByteSize > maxBufferSize && bufferByteSize > maxPacketSize) {
[self setBufferByteSize: maxBufferSize];
} else {
if (bufferByteSize < minBufferSize) {
[self setBufferByteSize: minBufferSize];
}
}
[self setNumPacketsToRead: self.bufferByteSize / maxPacketSize];
}
i understood almost everything, but i just did not get WHY this:
Float64 numPacketsForTime = audioFormat.mSampleRate / audioFormat.mFramesPerPacket * seconds;
i thought something like this would work:
numPacketsForTime = seconds * packetsPerSecond
so, packetsPerSecond = audioFormat.mSampleRate / audioFormat.mFramesPerPacket
????
could you help me with the maths?
thanks!