Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Frames to milliseconds conversion in android

In Android the getPlaybackHeadPosition() method of AudioTrack class returns the playback head position expressed in frames ,what is its equivalent value in milli seconds?

like image 777
Raneez Ahmed Avatar asked May 01 '12 09:05

Raneez Ahmed


1 Answers

I'm guessing that it would be

( track.getPlaybackHeadPosition( ) / track.getSampleRate( ) ) * 1000.0

In other words, the number of frames played divided by the number of frames per second. You then multiply the result by 1000 to get milliseconds.

A frame consists of one sample per channel and so should be equivalent to sample rate.

For example, if getPlaybackHeadPosition( ) returns 8654 and getSampleRate( ) returns 8000 then the time since the start of the track would be ( 8654 / 8000 ) * 1000 or 1081.75ms. (Assuming floating point arithmetic)

like image 160
Nick Avatar answered Sep 22 '22 16:09

Nick