xref: /haiku/src/add-ons/media/media-add-ons/mixer/MixerUtils.h (revision 4f00613311d0bd6b70fa82ce19931c41f071ea4e)
1 #ifndef _MIXER_UTILS_H
2 #define _MIXER_UTILS_H
3 
4 #if DEBUG > 0
5 	#define PRINT_CHANNEL_MASK(fmt) do { char s[200]; StringForChannelMask(s, (fmt).u.raw_audio.channel_mask); printf(" channel_mask 0x%08lX %s\n", (fmt).u.raw_audio.channel_mask, s); } while (0)
6 #else
7 	#define PRINT_CHANNEL_MASK(fmt) ((void)0)
8 #endif
9 
10 template<class t> const t & max(const t &t1, const t &t2) { return (t1 > t2) ?  t1 : t2; }
11 template<class t> const t & min(const t &t1, const t &t2) { return (t1 < t2) ?  t1 : t2; }
12 template<class t> const t abs(const t t1) { return (t1 < 0) ?  - t1 : t1; }
13 
14 void fix_multiaudio_format(media_multi_audio_format *format);
15 
16 int count_nonzero_bits(uint32 value);
17 
18 uint32 GetChannelMask(int channel, uint32 all_channel_masks);
19 int GetChannelType(int channel, uint32 all_channel_masks);
20 
21 bool HasKawamba();
22 
23 void ZeroFill(float *_dst, int32 _dst_sample_offset, int32 _sample_count);
24 
25 bigtime_t buffer_duration(const media_multi_audio_format & format);
26 
27 int bytes_per_sample(const media_multi_audio_format & format);
28 
29 int bytes_per_frame(const media_multi_audio_format & format);
30 int frames_per_buffer(const media_multi_audio_format & format);
31 
32 int64 frames_for_duration(double framerate, bigtime_t duration);
33 bigtime_t duration_for_frames(double framerate, int64 frames);
34 
35 int ChannelMaskToChannelType(uint32 mask);
36 uint32 ChannelTypeToChannelMask(int type);
37 
38 double us_to_s(bigtime_t usecs);
39 bigtime_t s_to_us(double secs);
40 
41 class MixerInput;
42 class MixerOutput;
43 
44 const char *StringForFormat(char *buf, MixerOutput *output);
45 const char *StringForFormat(char *buf, MixerInput *input);
46 const char *StringForChannelMask(char *buf, uint32 mask);
47 const char *StringForChannelType(char *buf, int type);
48 
49 #endif //_MIXER_UTILS_H
50