19 win32_wave_device(UINT
id, audio_direction direction) : _id(
id), _direction(direction)
21 hi_assert(_direction == audio_direction::input or _direction == audio_direction::output);
28 return message_string(DRV_QUERYFUNCTIONINSTANCEID, DRV_QUERYFUNCTIONINSTANCEIDSIZE);
37 auto device_name = message_string(DRV_QUERYDEVICEINTERFACE, DRV_QUERYDEVICEINTERFACESIZE);
41 [[nodiscard]]
static UINT num_devices(audio_direction direction)
noexcept
43 return direction == audio_direction::input ? waveInGetNumDevs() : waveOutGetNumDevs();
46 [[nodiscard]]
static generator<win32_wave_device> enumerate(audio_direction direction)
noexcept
48 auto num = num_devices(direction);
50 for (UINT
id = 0;
id != num; ++id) {
55 [[nodiscard]]
static win32_wave_device find_matching_end_point(audio_direction direction,
std::string end_point_id)
57 for (
auto wave_api : enumerate(direction)) {
62 throw io_error(std::format(
"Could not find matching wave device for end-point-id {}",
end_point_id));
67 audio_direction _direction;
69 [[nodiscard]]
std::wstring message_wstring(UINT message_id, UINT size_message_id)
const
73 auto const result = _direction == audio_direction::input ?
74 waveInMessage((HWAVEIN)IntToPtr(_id), size_message_id, std::bit_cast<DWORD_PTR>(&size), NULL) :
75 waveOutMessage((HWAVEOUT)IntToPtr(_id), size_message_id,
std::bit_cast<DWORD_PTR>(&size), NULL);
77 if (result != MMSYSERR_NOERROR) {
78 throw io_error(std::format(
79 "Could not get win32_wave_api wstring-message {} for wave-device-id:{}:{}",
87 hi_assert(size > 0 and size %
sizeof(
wchar_t) == 0);
88 auto str =
std::wstring(size /
sizeof(
wchar_t) - 1,
wchar_t{});
90 auto const result = _direction == audio_direction::input ?
91 waveInMessage((HWAVEIN)IntToPtr(_id), message_id, std::bit_cast<DWORD_PTR>(str.data()), size) :
92 waveOutMessage((HWAVEOUT)IntToPtr(_id), message_id,
std::bit_cast<DWORD_PTR>(str.data()), size);
94 if (result != MMSYSERR_NOERROR) {
95 throw io_error(std::format(
96 "Could not get win32_wave_api wstring-message {} for wave-device-id:{}:{}", message_id, _direction, _id));
103 [[nodiscard]]
std::string message_string(UINT message_id, UINT size_message_id)
const
105 return to_string(message_wstring(message_id, size_message_id));