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); }