diff --git a/dxlibex/basic_types/bel.hpp b/dxlibex/basic_types/bel.hpp index 753e05c..63a342f 100644 --- a/dxlibex/basic_types/bel.hpp +++ b/dxlibex/basic_types/bel.hpp @@ -40,7 +40,7 @@ namespace dxle { bel_c(const bel_c&) = default; template::value && (std::is_floating_point::value || !std::is_floating_point::value), nullptr_t> = nullptr> - DXLE_CONSTEXPR explicit bel_c(const T2& o) : value_(static_cast(o.value_)) {} + DXLE_CONSTEXPR explicit bel_c(const T2& o) : value_(static_cast(o)) {} template::value || (std::ratio_divide::den == 1 && !std::is_floating_point::value), @@ -67,29 +67,29 @@ namespace dxle { template struct bel_cast_helper { static DXLE_CONSTEXPR To cast(const bel_c& o) { - return{ static_cast(static_cast(o.count())) }; + return To{ static_cast(static_cast(o.count())) }; } }; template struct bel_cast_helper { static DXLE_CONSTEXPR To cast(const bel_c& o) { - return{ static_cast(static_cast(o.count()) * static_cast(CF::num)) }; + return To{ static_cast(static_cast(o.count()) * static_cast(CF::num)) }; } }; template struct bel_cast_helper { static DXLE_CONSTEXPR To cast(const bel_c& o) { - return{ static_cast(static_cast(static_cast(o.count()) / static_cast(CF::den))) }; + return To{ static_cast(static_cast(static_cast(o.count()) / static_cast(CF::den))) }; } }; } template::value, nullptr_t>> inline DXLE_CONSTEXPR To bel_cast(const bel_c& o) { // convert duration to another duration - typedef std::ratio_divide CF; + typedef std::ratio_divide CF; typedef typename To::value_type ToT; - typedef typename common_type::type CR; + typedef std::common_type_t CR; return detail::bel_cast_helper::cast(o); //return (CF::num == 1 && CF::den == 1 //? To(static_cast(_Dur.count())) @@ -111,7 +111,17 @@ namespace dxle { typedef bel_c deci_bel; typedef bel_c> bel; } + using namespace sound_units; +} #ifdef DXLE_SUPPORT_CXX11_USER_DEFINED_LITERALS +namespace dxle { namespace sound_units { namespace sound_units_literals { + inline constexpr myrio_bel operator "" _myrioB(unsigned long long myrioB) { + return myrio_bel(static_cast(myrioB)); + } + inline constexpr myrio_bel operator "" _dB(unsigned long long myrioB) { + return deci_bel(static_cast(myrioB)); + } +} } } +using namespace dxle::sound_units::sound_units_literals; #endif -} #endif //DXLE_INC_BASIC_TYPES_BEL_HPP_ diff --git a/samples/sound_play/sound_play/main.cpp b/samples/sound_play/sound_play/main.cpp index a426b31..f8d90d0 100644 --- a/samples/sound_play/sound_play/main.cpp +++ b/samples/sound_play/sound_play/main.cpp @@ -1,4 +1,9 @@ -#include -int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { - SetCreateSoundPitchRate(100); +//#include +#include +#include +int WINAPI WinMain(HINSTANCE /*hInstance*/, HINSTANCE /*hPrevInstance*/, LPSTR /*lpCmdLine*/, int /*nCmdShow*/) { + //SetCreateSoundPitchRate(100); + constexpr auto rate = 300_dB; + constexpr auto rate2 = 4000_myrioB; + constexpr auto rate3 = dxle::bel_cast(rate); }