Implement Duration() in BSound

Change-Id: I45244cd958acd7856a065af01625d2164b9ad033
Reviewed-on: https://review.haiku-os.org/c/963
Reviewed-by: Stephan Aßmus <superstippi@gmx.de>
This commit is contained in:
CodeforEvolution 2019-01-28 14:20:01 -06:00 committed by Stephan Aßmus
parent 5186fb7ebd
commit aad79bda85

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.
*
* Authors:
* Jacob Secunda
* Marcus Overhagen
* Michael Lotz <mmlr@mlotz.ch>
*/
#include <Sound.h>
#include <File.h>
#include "TrackReader.h"
#include <MediaDebug.h>
#include <new>
#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,
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);
}