I assume that presentationTimeNs it's the equivalent time in nanoseconds to actualRead bytes. But, using the code above, presentationTimeNs will always be 0.
If 1 second of data is equivalent to sampleRate * sampleSize * recordChannels bytes, then N bytes are processed in N / (sampleRate * sampleSize * recordChannels) seconds. So, to get nanoseconds correctly we should do:
In
org.m4m.android.MicrophoneSource
, insidepull(Frame frame)
, I found this:I assume that
presentationTimeNs
it's the equivalent time in nanoseconds toactualRead
bytes. But, using the code above,presentationTimeNs
will always be 0.If 1 second of data is equivalent to
sampleRate * sampleSize * recordChannels
bytes, then N bytes are processed inN / (sampleRate * sampleSize * recordChannels)
seconds. So, to get nanoseconds correctly we should do:long presentationTimeNs = (actualRead / (sampleRate * sampleSize * recordChannels)) * 1000000000;
But, look: denominator is an integer!, so we are still getting always 0. This is the correct way:
long presentationTimeNs = (long)((actualRead / (float)(sampleRate * sampleSize * recordChannels)) * 1000000000);
Is this correct?