![]() 384000bps) int bytesWritten = track.write(. Either way, you will need to know the bitrate of your AC3 stream (i.e. You will either need to convert it to bytes, or convert the number of bytes you've written in back into samples. If you're working with ENCODING_AC3, the playhead position reported by AudioTrack is still in terms of samples. WrittenPos += bytesWritten / pcmFrameSize ![]() This position can then be compared against how many frames you've written into the AudioTrack, by maintaining another counter which increments every time AudioTrack.write() completes: int bytesWritten = track.write(.) (System.nanoTime() - timestamp.nanoTime) * samplerate / 1e9 So the trick to getting the "current" position is to use your last snapshot and linearly interpolate what the current value should be: playheadPos = amePosition + The caveat is that this timestamp is only a snapshot, and the docs recommend you don't call this new method very often. Thus there's no need to call any other APIs now to add/remove latency. As such, it is fully accurate and already accounts for device latency. With the new AudioTrack.getTimestamp() API, you get a snapshot of the playhead position at a given time, taken directly at the output. With the new AudioTrack.getTimestamp () API, you get a snapshot of the playhead position at a given time, taken directly at the output. Thus, to account for latency you had to offset that value with a latency value from one of two hidden methods: AudioManager.getOutputLatency() or AudioTrack.getLatency(). So prior to this API, you would use AudioTrack.getPlaybackHeadPosition() which was just an approximation.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |