From aad79bda8510917f4a1ef1604b3644e54afbb0c3 Mon Sep 17 00:00:00 2001 From: CodeforEvolution Date: Mon, 28 Jan 2019 14:20:01 -0600 Subject: [PATCH] Implement Duration() in BSound MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: I45244cd958acd7856a065af01625d2164b9ad033 Reviewed-on: https://review.haiku-os.org/c/963 Reviewed-by: Stephan Aßmus --- src/kits/media/Sound.cpp | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/src/kits/media/Sound.cpp b/src/kits/media/Sound.cpp index d4ebd0398a..a5b1653c43 100644 --- a/src/kits/media/Sound.cpp +++ b/src/kits/media/Sound.cpp @@ -1,21 +1,23 @@ /* - * Copyright 2009, Haiku Inc. All Rights Reserved. + * Copyright 2009-2019, Haiku Inc. All Rights Reserved. * Distributed under the terms of the MIT License. * * Authors: + * Jacob Secunda * Marcus Overhagen * Michael Lotz */ #include -#include -#include "TrackReader.h" - -#include #include #include +#include +#include + +#include "TrackReader.h" + BSound::BSound(void* data, size_t size, const media_raw_audio_format& format, bool freeWhenDone) @@ -132,8 +134,16 @@ BSound::RefCount() const bigtime_t BSound::Duration() const { - UNIMPLEMENTED(); - return 0; + float frameRate = fFormat.frame_rate; + + if (frameRate == 0.0) + return 0; + + uint32 bytesPerSample = fFormat.format & + media_raw_audio_format::B_AUDIO_SIZE_MASK; + int64 frameCount = Size() / (fFormat.channel_count * bytesPerSample); + + return ceil((1000000LL * frameCount) / frameRate); }