Implement Duration() in BSound

Change-Id: I45244cd958acd7856a065af01625d2164b9ad033
Reviewed-on: https://review.haiku-os.org/c/963
Reviewed-by: Stephan Aßmus <[email protected]>
This commit is contained in:
CodeforEvolution
2019-02-01 15:49:07 +00:00
committed by Stephan Aßmus
parent 5186fb7ebd
commit aad79bda85
+16 -6
View File
@@ -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. * Distributed under the terms of the MIT License.
* *
* Authors: * Authors:
* Jacob Secunda
* Marcus Overhagen * Marcus Overhagen
* Michael Lotz <[email protected]> * Michael Lotz <[email protected]>
*/ */
#include <Sound.h> #include <Sound.h>
#include <File.h>
#include "TrackReader.h"
#include <MediaDebug.h>
#include <new> #include <new>
#include <string.h> #include <string.h>
#include <File.h>
#include <MediaDebug.h>
#include "TrackReader.h"
BSound::BSound(void* data, size_t size, const media_raw_audio_format& format, BSound::BSound(void* data, size_t size, const media_raw_audio_format& format,
bool freeWhenDone) bool freeWhenDone)
@@ -132,8 +134,16 @@ BSound::RefCount() const
bigtime_t bigtime_t
BSound::Duration() const BSound::Duration() const
{ {
UNIMPLEMENTED(); float frameRate = fFormat.frame_rate;
if (frameRate == 0.0)
return 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);
} }