1 /* 2 * Copyright 2008 Stephan Aßmus, <superstippi@gmx.de> 3 * All rights reserved. Distributed under the terms of the MIT license. 4 */ 5 #ifndef SUPPORT_FUNCTIONS_H 6 #define SUPPORT_FUNCTIONS_H 7 8 #include <MediaDefs.h> 9 10 static inline int32 11 bytes_per_frame(const media_format& format) 12 { 13 int32 channelCount = format.u.raw_audio.channel_count; 14 size_t sampleSize = format.u.raw_audio.format 15 & media_raw_audio_format::B_AUDIO_SIZE_MASK; 16 return sampleSize * channelCount; 17 } 18 19 20 static inline bigtime_t 21 time_for_buffer(size_t size, const media_format& format) 22 { 23 int32 frameSize = bytes_per_frame(format); 24 float frameRate = format.u.raw_audio.frame_rate; 25 26 return (bigtime_t)((double)size * 1000000 / frameSize / frameRate); 27 } 28 29 30 #endif // SUPPORT_FUNCTIONS_H 31