2 * Copyright 2008, Axel Dörfler, axeld@pinc-software.de.
3 * Copyright (c) 2002-2007, Jerome Duval (jerome.duval@free.fr)
5 * Distributed under the terms of the MIT License.
9 #include "MultiAudioUtility.h"
13 #include <MediaDefs.h>
16 const float kSampleRates
[] = {
17 8000.0, 11025.0, 12000.0, 16000.0, 22050.0, 24000.0, 32000.0, 44100.0,
18 48000.0, 64000.0, 88200.0, 96000.0, 176400.0, 192000.0, 384000.0, 1536000.0
20 const uint32 kSampleRateCount
= sizeof(kSampleRates
) / sizeof(kSampleRates
[0]);
23 template<typename T
> static status_t
24 call_driver(int device
, int32 op
, T
* data
)
26 if (ioctl(device
, op
, data
, sizeof(T
)) != 0)
33 namespace MultiAudio
{
37 convert_to_sample_rate(uint32 rate
)
39 for (uint32 i
= 0; i
< kSampleRateCount
; i
++) {
41 return kSampleRates
[i
];
51 convert_from_sample_rate(float rate
)
53 for (uint32 i
= 0; i
< kSampleRateCount
; i
++) {
54 if (rate
<= kSampleRates
[i
])
63 convert_to_media_format(uint32 format
)
67 return media_raw_audio_format::B_AUDIO_FLOAT
;
72 return media_raw_audio_format::B_AUDIO_INT
;
74 return media_raw_audio_format::B_AUDIO_SHORT
;
76 return media_raw_audio_format::B_AUDIO_CHAR
;
78 return media_raw_audio_format::B_AUDIO_UCHAR
;
87 convert_to_valid_bits(uint32 format
)
106 convert_from_media_format(uint32 format
)
109 case media_raw_audio_format::B_AUDIO_FLOAT
:
111 case media_raw_audio_format::B_AUDIO_INT
:
113 case media_raw_audio_format::B_AUDIO_SHORT
:
115 case media_raw_audio_format::B_AUDIO_CHAR
:
117 case media_raw_audio_format::B_AUDIO_UCHAR
:
127 select_sample_rate(uint32 rate
)
130 uint32 crate
= B_SR_1536000
;
141 select_format(uint32 format
)
144 // TODO ensure we support this format
145 /*if (format & B_FMT_FLOAT)
146 return B_FMT_FLOAT;*/
147 if (format
& B_FMT_32BIT
)
149 if (format
& B_FMT_24BIT
)
151 if (format
& B_FMT_20BIT
)
153 if (format
& B_FMT_18BIT
)
155 if (format
& B_FMT_16BIT
)
157 if (format
& B_FMT_8BIT_S
)
159 if (format
& B_FMT_8BIT_U
)
167 get_description(int device
, multi_description
* description
)
169 return call_driver(device
, B_MULTI_GET_DESCRIPTION
, description
);
174 get_enabled_channels(int device
, multi_channel_enable
* enable
)
176 return call_driver(device
, B_MULTI_GET_ENABLED_CHANNELS
, enable
);
181 set_enabled_channels(int device
, multi_channel_enable
* enable
)
183 return call_driver(device
, B_MULTI_SET_ENABLED_CHANNELS
, enable
);
188 get_global_format(int device
, multi_format_info
* info
)
190 return call_driver(device
, B_MULTI_GET_GLOBAL_FORMAT
, info
);
195 set_global_format(int device
, multi_format_info
* info
)
197 return call_driver(device
, B_MULTI_SET_GLOBAL_FORMAT
, info
);
202 get_buffers(int device
, multi_buffer_list
* list
)
204 return call_driver(device
, B_MULTI_GET_BUFFERS
, list
);
209 buffer_exchange(int device
, multi_buffer_info
* info
)
211 return call_driver(device
, B_MULTI_BUFFER_EXCHANGE
, info
);
216 list_mix_controls(int device
, multi_mix_control_info
* info
)
218 return call_driver(device
, B_MULTI_LIST_MIX_CONTROLS
, info
);
223 get_mix(int device
, multi_mix_value_info
* info
)
225 return call_driver(device
, B_MULTI_GET_MIX
, info
);
230 set_mix(int device
, multi_mix_value_info
* info
)
232 return call_driver(device
, B_MULTI_SET_MIX
, info
);
236 } // namespace MultiAudio