Index: soundbase/Dither.cpp =================================================================== --- soundbase/Dither.cpp (revision 14154) +++ soundbase/Dither.cpp (working copy) @@ -23,11 +23,11 @@ mpt::ustring result; switch(mode) { - case DitherNone : result = U_("no" ); break; + case DitherNone: result = U_("no"); break; case DitherDefault: result = U_("default"); break; case DitherModPlug: result = U_("0.5 bit"); break; - case DitherSimple : result = U_("1 bit" ); break; - default : result = U_("" ); break; + case DitherSimple: result = U_("1 bit"); break; + default: result = U_(""); break; } return result; } Index: soundbase/Dither.h =================================================================== --- soundbase/Dither.h (revision 14154) +++ soundbase/Dither.h (working copy) @@ -24,10 +24,10 @@ enum DitherMode { - DitherNone = 0, - DitherDefault = 1, // chosen by OpenMPT code, might change - DitherModPlug = 2, // rectangular, 0.5 bit depth, no noise shaping (original ModPlug Tracker) - DitherSimple = 3, // rectangular, 1 bit depth, simple 1st order noise shaping + DitherNone = 0, + DitherDefault = 1, // chosen by OpenMPT code, might change + DitherModPlug = 2, // rectangular, 0.5 bit depth, no noise shaping (original ModPlug Tracker) + DitherSimple = 3, // rectangular, 1 bit depth, simple 1st order noise shaping NumDitherModes }; @@ -78,11 +78,12 @@ }; -template +template struct Dither_SimpleImpl { private: int32 error = 0; + public: template MPT_FORCEINLINE MixSampleInt process(MixSampleInt sample, Trng &prng) @@ -94,7 +95,7 @@ } else { static_assert(sizeof(MixSampleInt) == 4); - constexpr int rshift = (32-targetbits) - MixSampleIntTraits::mix_headroom_bits(); + constexpr int rshift = (32 - targetbits) - MixSampleIntTraits::mix_headroom_bits(); if constexpr(rshift <= 1) { MPT_UNREFERENCED_PARAMETER(prng); @@ -102,13 +103,13 @@ return sample; } else { - constexpr int rshiftpositive = (rshift > 1) ? rshift : 1; // work-around warnings about negative shift with C++14 compilers - constexpr int round_mask = ~((1< 1) ? rshift : 1; // work-around warnings about negative shift with C++14 compilers + constexpr int round_mask = ~((1 << rshiftpositive) - 1); + constexpr int round_offset = 1 << (rshiftpositive - 1); + constexpr int noise_bits = rshiftpositive + (ditherdepth - 1); + constexpr int noise_bias = (1 << (noise_bits - 1)); + int32 e = error; + unsigned int unoise = 0; if constexpr(triangular) { unoise = (mpt::random(prng, noise_bits) + mpt::random(prng, noise_bits)) >> 1; @@ -116,16 +117,16 @@ { unoise = mpt::random(prng, noise_bits); } - int noise = static_cast(unoise) - noise_bias; // un-bias - int val = sample; + int noise = static_cast(unoise) - noise_bias; // un-bias + int val = sample; if constexpr(shaped) { val += (e >> 1); } int rounded = (val + noise + round_offset) & round_mask; - e = val - rounded; - sample = rounded; - error = e; + e = val - rounded; + sample = rounded; + error = e; return sample; } } @@ -147,6 +148,7 @@ { private: std::array DitherChannels; + public: void Reset() { @@ -172,7 +174,10 @@ class DitherTemplate : public MultiChannelDither { - struct {} prng; + struct + { + } prng; + public: template DitherTemplate(Trd &) @@ -197,6 +202,7 @@ { private: mpt::rng::modplug_dither prng; + public: template DitherTemplate(Trd &) @@ -222,9 +228,10 @@ { private: mpt::fast_prng prng; + public: template - DitherTemplate(Trd & rd) + DitherTemplate(Trd &rd) : prng(rd) { return; @@ -255,7 +262,6 @@ { private: - DitherTemplate ditherNone; DitherTemplate ditherModPlug; DitherTemplate ditherSimple; @@ -263,9 +269,8 @@ DitherMode mode = DitherDefault; public: - template - DitherChannels(Trd & rd) + DitherChannels(Trd &rd) : ditherNone(rd) , ditherModPlug(rd) , ditherSimple(rd) @@ -278,22 +283,22 @@ ditherSimple.Reset(); } - DitherTemplate & NoDither() + DitherTemplate &NoDither() { MPT_ASSERT(mode == DitherNone); return ditherNone; } - DitherTemplate & DefaultDither() + DitherTemplate &DefaultDither() { MPT_ASSERT(mode == DitherDefault); return ditherModPlug; } - DitherTemplate & ModPlugDither() + DitherTemplate &ModPlugDither() { MPT_ASSERT(mode == DitherModPlug); return ditherModPlug; } - DitherTemplate & SimpleDither() + DitherTemplate &SimpleDither() { MPT_ASSERT(mode == DitherSimple); return ditherSimple; @@ -304,11 +309,11 @@ { switch(GetMode()) { - case DitherNone: return fn(NoDither()); break; - case DitherModPlug: return fn(ModPlugDither()); break; - case DitherSimple: return fn(SimpleDither()); break; - case DitherDefault: return fn(DefaultDither()); break; - default: return fn(DefaultDither()); break; + case DitherNone: return fn(NoDither()); break; + case DitherModPlug: return fn(ModPlugDither()); break; + case DitherSimple: return fn(SimpleDither()); break; + case DitherDefault: return fn(DefaultDither()); break; + default: return fn(DefaultDither()); break; } } @@ -320,7 +325,6 @@ { return mode; } - }; Index: soundbase/SampleBuffer.h =================================================================== --- soundbase/SampleBuffer.h (revision 14154) +++ soundbase/SampleBuffer.h (working copy) @@ -23,13 +23,15 @@ { public: using sample_type = SampleType; + private: - SampleType * const * m_buffers; + SampleType *const *m_buffers; std::size_t m_channels; std::size_t m_frames; std::size_t m_offset; + public: - constexpr audio_buffer_planar(SampleType * const * buffers, std::size_t channels, std::size_t frames) + constexpr audio_buffer_planar(SampleType *const *buffers, std::size_t channels, std::size_t frames) : m_buffers(buffers) , m_channels(channels) , m_frames(frames) @@ -37,11 +39,11 @@ { return; } - SampleType & operator()(std::size_t channel, std::size_t frame) + SampleType &operator()(std::size_t channel, std::size_t frame) { return m_buffers[channel][m_offset + frame]; } - const SampleType & operator()(std::size_t channel, std::size_t frame) const + const SampleType &operator()(std::size_t channel, std::size_t frame) const { return m_buffers[channel][m_offset + frame]; } @@ -53,7 +55,7 @@ { return m_frames; } - audio_buffer_planar & advance(std::size_t numFrames) + audio_buffer_planar &advance(std::size_t numFrames) { m_offset += numFrames; m_frames -= numFrames; @@ -66,12 +68,14 @@ { public: using sample_type = SampleType; + private: - SampleType * m_buffer; + SampleType *m_buffer; std::size_t m_channels; std::size_t m_frames; + public: - constexpr audio_buffer_interleaved(SampleType* buffer, std::size_t channels, std::size_t frames) + constexpr audio_buffer_interleaved(SampleType *buffer, std::size_t channels, std::size_t frames) : m_buffer(buffer) , m_channels(channels) , m_frames(frames) @@ -78,19 +82,19 @@ { return; } - SampleType * data() + SampleType *data() { return m_buffer; } - const SampleType * data() const + const SampleType *data() const { return m_buffer; } - SampleType & operator()(std::size_t channel, std::size_t frame) + SampleType &operator()(std::size_t channel, std::size_t frame) { return m_buffer[m_channels * frame + channel]; } - const SampleType & operator()(std::size_t channel, std::size_t frame) const + const SampleType &operator()(std::size_t channel, std::size_t frame) const { return m_buffer[m_channels * frame + channel]; } @@ -102,7 +106,7 @@ { return m_frames; } - audio_buffer_interleaved & advance(std::size_t numFrames) + audio_buffer_interleaved &advance(std::size_t numFrames) { m_buffer += size_channels() * numFrames; m_frames -= numFrames; @@ -111,7 +115,7 @@ }; template -std::size_t planar_audio_buffer_valid_channels(SampleType * const * buffers, std::size_t maxChannels) +std::size_t planar_audio_buffer_valid_channels(SampleType *const *buffers, std::size_t maxChannels) { std::size_t channel; for(channel = 0; channel < maxChannels; ++channel) Index: soundbase/SampleFormat.h =================================================================== --- soundbase/SampleFormat.h (revision 14154) +++ soundbase/SampleFormat.h (working copy) @@ -20,45 +20,103 @@ enum SampleFormatEnum : uint8 { - SampleFormatUnsigned8 = 9, // do not change value (for compatibility with old configuration settings) - SampleFormatInt8 = 8, // do not change value (for compatibility with old configuration settings) - SampleFormatInt16 = 16, // do not change value (for compatibility with old configuration settings) - SampleFormatInt24 = 24, // do not change value (for compatibility with old configuration settings) - SampleFormatInt32 = 32, // do not change value (for compatibility with old configuration settings) - SampleFormatFloat32 = 32 + 128, // do not change value (for compatibility with old configuration settings) - SampleFormatFloat64 = 64 + 128, // do not change value (for compatibility with old configuration settings) - SampleFormatInvalid = 0 + SampleFormatUnsigned8 = 9, // do not change value (for compatibility with old configuration settings) + SampleFormatInt8 = 8, // do not change value (for compatibility with old configuration settings) + SampleFormatInt16 = 16, // do not change value (for compatibility with old configuration settings) + SampleFormatInt24 = 24, // do not change value (for compatibility with old configuration settings) + SampleFormatInt32 = 32, // do not change value (for compatibility with old configuration settings) + SampleFormatFloat32 = 32 + 128, // do not change value (for compatibility with old configuration settings) + SampleFormatFloat64 = 64 + 128, // do not change value (for compatibility with old configuration settings) + SampleFormatInvalid = 0 }; template Container AllSampleFormats() { - return { SampleFormatFloat64, SampleFormatFloat32, SampleFormatInt32, SampleFormatInt24, SampleFormatInt16, SampleFormatInt8, SampleFormatUnsigned8 }; + return {SampleFormatFloat64, SampleFormatFloat32, SampleFormatInt32, SampleFormatInt24, SampleFormatInt16, SampleFormatInt8, SampleFormatUnsigned8}; } template Container DefaultSampleFormats() { - return { SampleFormatFloat32, SampleFormatInt32, SampleFormatInt24, SampleFormatInt16, SampleFormatInt8 }; + return {SampleFormatFloat32, SampleFormatInt32, SampleFormatInt24, SampleFormatInt16, SampleFormatInt8}; } -template struct SampleFormatTraits; -template<> struct SampleFormatTraits { static MPT_CONSTEXPRINLINE SampleFormatEnum sampleFormat() { return SampleFormatUnsigned8; } }; -template<> struct SampleFormatTraits { static MPT_CONSTEXPRINLINE SampleFormatEnum sampleFormat() { return SampleFormatInt8; } }; -template<> struct SampleFormatTraits { static MPT_CONSTEXPRINLINE SampleFormatEnum sampleFormat() { return SampleFormatInt16; } }; -template<> struct SampleFormatTraits { static MPT_CONSTEXPRINLINE SampleFormatEnum sampleFormat() { return SampleFormatInt24; } }; -template<> struct SampleFormatTraits { static MPT_CONSTEXPRINLINE SampleFormatEnum sampleFormat() { return SampleFormatInt32; } }; -template<> struct SampleFormatTraits { static MPT_CONSTEXPRINLINE SampleFormatEnum sampleFormat() { return SampleFormatFloat32; } }; -template<> struct SampleFormatTraits { static MPT_CONSTEXPRINLINE SampleFormatEnum sampleFormat() { return SampleFormatFloat64; } }; +template +struct SampleFormatTraits; +template <> +struct SampleFormatTraits +{ + static MPT_CONSTEXPRINLINE SampleFormatEnum sampleFormat() { return SampleFormatUnsigned8; } +}; +template <> +struct SampleFormatTraits +{ + static MPT_CONSTEXPRINLINE SampleFormatEnum sampleFormat() { return SampleFormatInt8; } +}; +template <> +struct SampleFormatTraits +{ + static MPT_CONSTEXPRINLINE SampleFormatEnum sampleFormat() { return SampleFormatInt16; } +}; +template <> +struct SampleFormatTraits +{ + static MPT_CONSTEXPRINLINE SampleFormatEnum sampleFormat() { return SampleFormatInt24; } +}; +template <> +struct SampleFormatTraits +{ + static MPT_CONSTEXPRINLINE SampleFormatEnum sampleFormat() { return SampleFormatInt32; } +}; +template <> +struct SampleFormatTraits +{ + static MPT_CONSTEXPRINLINE SampleFormatEnum sampleFormat() { return SampleFormatFloat32; } +}; +template <> +struct SampleFormatTraits +{ + static MPT_CONSTEXPRINLINE SampleFormatEnum sampleFormat() { return SampleFormatFloat64; } +}; -template struct SampleFormatToType; -template<> struct SampleFormatToType { typedef uint8 type; }; -template<> struct SampleFormatToType { typedef int8 type; }; -template<> struct SampleFormatToType { typedef int16 type; }; -template<> struct SampleFormatToType { typedef int24 type; }; -template<> struct SampleFormatToType { typedef int32 type; }; -template<> struct SampleFormatToType { typedef float type; }; -template<> struct SampleFormatToType { typedef double type; }; +template +struct SampleFormatToType; +template <> +struct SampleFormatToType +{ + typedef uint8 type; +}; +template <> +struct SampleFormatToType +{ + typedef int8 type; +}; +template <> +struct SampleFormatToType +{ + typedef int16 type; +}; +template <> +struct SampleFormatToType +{ + typedef int24 type; +}; +template <> +struct SampleFormatToType +{ + typedef int32 type; +}; +template <> +struct SampleFormatToType +{ + typedef float type; +}; +template <> +struct SampleFormatToType +{ + typedef double type; +}; class SampleFormat @@ -65,7 +123,6 @@ { private: - SampleFormatEnum value; template @@ -72,10 +129,10 @@ static MPT_CONSTEXPRINLINE SampleFormatEnum Sanitize(T x) noexcept { using uT = typename std::make_unsigned::type; - uT ux = x; + uT ux = x; if(ux == static_cast(-8)) { - ux = 8+1; + ux = 8 + 1; } // float|64|32|16|8|?|?|unsigned ux &= 0b11111001; @@ -83,7 +140,6 @@ } public: - MPT_CONSTEXPRINLINE SampleFormat() noexcept : value(SampleFormatInvalid) { @@ -113,19 +169,10 @@ } MPT_CONSTEXPRINLINE uint8 GetBitsPerSample() const noexcept { - return - !IsValid() ? 0 : - (value == SampleFormatUnsigned8) ? 8 : - (value == SampleFormatInt8) ? 8 : - (value == SampleFormatInt16) ? 16 : - (value == SampleFormatInt24) ? 24 : - (value == SampleFormatInt32) ? 32 : - (value == SampleFormatFloat32) ? 32 : - (value == SampleFormatFloat64) ? 64 : - 0; + return !IsValid() ? 0 : (value == SampleFormatUnsigned8) ? 8 : (value == SampleFormatInt8) ? 8 : (value == SampleFormatInt16) ? 16 : (value == SampleFormatInt24) ? 24 : (value == SampleFormatInt32) ? 32 : (value == SampleFormatFloat32) ? 32 : (value == SampleFormatFloat64) ? 64 : 0; } - MPT_CONSTEXPRINLINE operator SampleFormatEnum () const noexcept + MPT_CONSTEXPRINLINE operator SampleFormatEnum() const noexcept { return value; } @@ -143,7 +190,6 @@ { return value; } - }; Index: soundbase/SampleFormatConverters.h =================================================================== --- soundbase/SampleFormatConverters.h (revision 14154) +++ soundbase/SampleFormatConverters.h (working copy) @@ -31,7 +31,8 @@ #define bigEndian16 1, 0 -namespace SC { // SC = _S_ample_C_onversion +namespace SC +{ // SC = _S_ample_C_onversion @@ -74,7 +75,7 @@ typedef std::byte input_t; typedef int8 output_t; static constexpr std::size_t input_inc = 1; - MPT_FORCEINLINE output_t operator() (const input_t *inBuf) + MPT_FORCEINLINE output_t operator()(const input_t *inBuf) { return Clamp(mpt::byte_cast(*inBuf), static_cast(-64), static_cast(63)) * 2; } @@ -85,7 +86,7 @@ typedef std::byte input_t; typedef int8 output_t; static constexpr std::size_t input_inc = 1; - MPT_FORCEINLINE output_t operator() (const input_t *inBuf) + MPT_FORCEINLINE output_t operator()(const input_t *inBuf) { return mpt::byte_cast(*inBuf); } @@ -96,7 +97,7 @@ typedef std::byte input_t; typedef int8 output_t; static constexpr std::size_t input_inc = 1; - MPT_FORCEINLINE output_t operator() (const input_t *inBuf) + MPT_FORCEINLINE output_t operator()(const input_t *inBuf) { return static_cast(int(mpt::byte_cast(*inBuf)) - 128); } @@ -108,8 +109,9 @@ typedef int8 output_t; static constexpr std::size_t input_inc = 1; uint8 delta; - DecodeInt8Delta() : delta(0) { } - MPT_FORCEINLINE output_t operator() (const input_t *inBuf) + DecodeInt8Delta() + : delta(0) {} + MPT_FORCEINLINE output_t operator()(const input_t *inBuf) { delta += mpt::byte_cast(*inBuf); return static_cast(delta); @@ -122,7 +124,7 @@ typedef std::byte input_t; typedef int16 output_t; static constexpr std::size_t input_inc = 2; - MPT_FORCEINLINE output_t operator() (const input_t *inBuf) + MPT_FORCEINLINE output_t operator()(const input_t *inBuf) { return (mpt::byte_cast(inBuf[loByteIndex]) | (mpt::byte_cast(inBuf[hiByteIndex]) << 8)) - offset; } @@ -135,8 +137,9 @@ typedef int16 output_t; static constexpr std::size_t input_inc = 2; uint16 delta; - DecodeInt16Delta() : delta(0) { } - MPT_FORCEINLINE output_t operator() (const input_t *inBuf) + DecodeInt16Delta() + : delta(0) {} + MPT_FORCEINLINE output_t operator()(const input_t *inBuf) { delta += mpt::byte_cast(inBuf[loByteIndex]) | (mpt::byte_cast(inBuf[hiByteIndex]) << 8); return static_cast(delta); @@ -149,8 +152,9 @@ typedef int16 output_t; static constexpr std::size_t input_inc = 2; uint16 delta; - DecodeInt16Delta8() : delta(0) { } - MPT_FORCEINLINE output_t operator() (const input_t *inBuf) + DecodeInt16Delta8() + : delta(0) {} + MPT_FORCEINLINE output_t operator()(const input_t *inBuf) { delta += mpt::byte_cast(inBuf[0]); int16 result = delta & 0xFF; @@ -166,7 +170,7 @@ typedef std::byte input_t; typedef int32 output_t; static constexpr std::size_t input_inc = 3; - MPT_FORCEINLINE output_t operator() (const input_t *inBuf) + MPT_FORCEINLINE output_t operator()(const input_t *inBuf) { return ((mpt::byte_cast(inBuf[loByteIndex]) << 8) | (mpt::byte_cast(inBuf[midByteIndex]) << 16) | (mpt::byte_cast(inBuf[hiByteIndex]) << 24)) - offset; } @@ -178,7 +182,7 @@ typedef std::byte input_t; typedef int32 output_t; static constexpr std::size_t input_inc = 4; - MPT_FORCEINLINE output_t operator() (const input_t *inBuf) + MPT_FORCEINLINE output_t operator()(const input_t *inBuf) { return (mpt::byte_cast(inBuf[loLoByteIndex]) | (mpt::byte_cast(inBuf[loHiByteIndex]) << 8) | (mpt::byte_cast(inBuf[hiLoByteIndex]) << 16) | (mpt::byte_cast(inBuf[hiHiByteIndex]) << 24)) - offset; } @@ -190,18 +194,18 @@ typedef std::byte input_t; typedef int64 output_t; static constexpr std::size_t input_inc = 8; - MPT_FORCEINLINE output_t operator() (const input_t *inBuf) + MPT_FORCEINLINE output_t operator()(const input_t *inBuf) { return (uint64(0) - | (static_cast(mpt::byte_cast(inBuf[b0])) << 0) - | (static_cast(mpt::byte_cast(inBuf[b1])) << 8) - | (static_cast(mpt::byte_cast(inBuf[b2])) << 16) - | (static_cast(mpt::byte_cast(inBuf[b3])) << 24) - | (static_cast(mpt::byte_cast(inBuf[b4])) << 32) - | (static_cast(mpt::byte_cast(inBuf[b5])) << 40) - | (static_cast(mpt::byte_cast(inBuf[b6])) << 48) - | (static_cast(mpt::byte_cast(inBuf[b7])) << 56) - ) - offset; + | (static_cast(mpt::byte_cast(inBuf[b0])) << 0) + | (static_cast(mpt::byte_cast(inBuf[b1])) << 8) + | (static_cast(mpt::byte_cast(inBuf[b2])) << 16) + | (static_cast(mpt::byte_cast(inBuf[b3])) << 24) + | (static_cast(mpt::byte_cast(inBuf[b4])) << 32) + | (static_cast(mpt::byte_cast(inBuf[b5])) << 40) + | (static_cast(mpt::byte_cast(inBuf[b6])) << 48) + | (static_cast(mpt::byte_cast(inBuf[b7])) << 56)) + - offset; } }; @@ -211,7 +215,7 @@ typedef std::byte input_t; typedef float32 output_t; static constexpr std::size_t input_inc = 4; - MPT_FORCEINLINE output_t operator() (const input_t *inBuf) + MPT_FORCEINLINE output_t operator()(const input_t *inBuf) { return IEEE754binary32LE(inBuf[loLoByteIndex], inBuf[loHiByteIndex], inBuf[hiLoByteIndex], inBuf[hiHiByteIndex]); } @@ -224,7 +228,7 @@ typedef float32 output_t; static constexpr std::size_t input_inc = 4; float factor; - MPT_FORCEINLINE output_t operator() (const input_t *inBuf) + MPT_FORCEINLINE output_t operator()(const input_t *inBuf) { return factor * IEEE754binary32LE(inBuf[loLoByteIndex], inBuf[loHiByteIndex], inBuf[hiLoByteIndex], inBuf[hiHiByteIndex]); } @@ -241,7 +245,7 @@ typedef std::byte input_t; typedef float64 output_t; static constexpr std::size_t input_inc = 8; - MPT_FORCEINLINE output_t operator() (const input_t *inBuf) + MPT_FORCEINLINE output_t operator()(const input_t *inBuf) { return IEEE754binary64LE(inBuf[b0], inBuf[b1], inBuf[b2], inBuf[b3], inBuf[b4], inBuf[b5], inBuf[b6], inBuf[b7]); } @@ -253,7 +257,7 @@ typedef Tsample input_t; typedef Tsample output_t; static constexpr std::size_t input_inc = 1; - MPT_FORCEINLINE output_t operator() (const input_t *inBuf) + MPT_FORCEINLINE output_t operator()(const input_t *inBuf) { return *inBuf; } @@ -267,7 +271,7 @@ { typedef Tsrc input_t; typedef Tdst output_t; - MPT_FORCEINLINE output_t operator() (input_t val) + MPT_FORCEINLINE output_t operator()(input_t val) { return mpt::saturate_cast(MPT_SC_RSHIFT_SIGNED(val, shift)); } @@ -281,7 +285,7 @@ { typedef Tsrc input_t; typedef Tdst output_t; - MPT_FORCEINLINE output_t operator() (input_t val) + MPT_FORCEINLINE output_t operator()(input_t val) { return mpt::saturate_cast(MPT_SC_LSHIFT_SIGNED(val, shift)); } @@ -303,7 +307,7 @@ { typedef Tid input_t; typedef Tid output_t; - MPT_FORCEINLINE output_t operator() (input_t val) + MPT_FORCEINLINE output_t operator()(input_t val) { return val; } @@ -314,9 +318,9 @@ { typedef int8 input_t; typedef uint8 output_t; - MPT_FORCEINLINE output_t operator() (input_t val) + MPT_FORCEINLINE output_t operator()(input_t val) { - return static_cast(val+0x80); + return static_cast(val + 0x80); } }; @@ -325,9 +329,9 @@ { typedef int16 input_t; typedef uint8 output_t; - MPT_FORCEINLINE output_t operator() (input_t val) + MPT_FORCEINLINE output_t operator()(input_t val) { - return static_cast(static_cast(MPT_SC_RSHIFT_SIGNED(val, 8))+0x80); + return static_cast(static_cast(MPT_SC_RSHIFT_SIGNED(val, 8)) + 0x80); } }; @@ -336,9 +340,9 @@ { typedef int24 input_t; typedef uint8 output_t; - MPT_FORCEINLINE output_t operator() (input_t val) + MPT_FORCEINLINE output_t operator()(input_t val) { - return static_cast(static_cast(MPT_SC_RSHIFT_SIGNED(static_cast(val), 16))+0x80); + return static_cast(static_cast(MPT_SC_RSHIFT_SIGNED(static_cast(val), 16)) + 0x80); } }; @@ -347,9 +351,9 @@ { typedef int32 input_t; typedef uint8 output_t; - MPT_FORCEINLINE output_t operator() (input_t val) + MPT_FORCEINLINE output_t operator()(input_t val) { - return static_cast(static_cast(MPT_SC_RSHIFT_SIGNED(val, 24))+0x80); + return static_cast(static_cast(MPT_SC_RSHIFT_SIGNED(val, 24)) + 0x80); } }; @@ -358,9 +362,9 @@ { typedef int64 input_t; typedef uint8 output_t; - MPT_FORCEINLINE output_t operator() (input_t val) + MPT_FORCEINLINE output_t operator()(input_t val) { - return static_cast(static_cast(MPT_SC_RSHIFT_SIGNED(val, 56))+0x80); + return static_cast(static_cast(MPT_SC_RSHIFT_SIGNED(val, 56)) + 0x80); } }; @@ -369,11 +373,11 @@ { typedef float32 input_t; typedef uint8 output_t; - MPT_FORCEINLINE output_t operator() (input_t val) + MPT_FORCEINLINE output_t operator()(input_t val) { Limit(val, -1.0f, 1.0f); val *= 128.0f; - return static_cast(mpt::saturate_cast(static_cast(MPT_SC_FASTROUND(val)))+0x80); + return static_cast(mpt::saturate_cast(static_cast(MPT_SC_FASTROUND(val))) + 0x80); } }; @@ -382,11 +386,11 @@ { typedef double input_t; typedef uint8 output_t; - MPT_FORCEINLINE output_t operator() (input_t val) + MPT_FORCEINLINE output_t operator()(input_t val) { Limit(val, -1.0, 1.0); val *= 128.0; - return static_cast(mpt::saturate_cast(static_cast(MPT_SC_FASTROUND(val)))+0x80); + return static_cast(mpt::saturate_cast(static_cast(MPT_SC_FASTROUND(val))) + 0x80); } }; @@ -395,9 +399,9 @@ { typedef uint8 input_t; typedef int8 output_t; - MPT_FORCEINLINE output_t operator() (input_t val) + MPT_FORCEINLINE output_t operator()(input_t val) { - return static_cast(static_cast(val)-0x80); + return static_cast(static_cast(val) - 0x80); } }; @@ -406,7 +410,7 @@ { typedef int16 input_t; typedef int8 output_t; - MPT_FORCEINLINE output_t operator() (input_t val) + MPT_FORCEINLINE output_t operator()(input_t val) { return static_cast(MPT_SC_RSHIFT_SIGNED(val, 8)); } @@ -417,7 +421,7 @@ { typedef int24 input_t; typedef int8 output_t; - MPT_FORCEINLINE output_t operator() (input_t val) + MPT_FORCEINLINE output_t operator()(input_t val) { return static_cast(MPT_SC_RSHIFT_SIGNED(static_cast(val), 16)); } @@ -428,7 +432,7 @@ { typedef int32 input_t; typedef int8 output_t; - MPT_FORCEINLINE output_t operator() (input_t val) + MPT_FORCEINLINE output_t operator()(input_t val) { return static_cast(MPT_SC_RSHIFT_SIGNED(val, 24)); } @@ -439,7 +443,7 @@ { typedef int64 input_t; typedef int8 output_t; - MPT_FORCEINLINE output_t operator() (input_t val) + MPT_FORCEINLINE output_t operator()(input_t val) { return static_cast(MPT_SC_RSHIFT_SIGNED(val, 56)); } @@ -450,7 +454,7 @@ { typedef float32 input_t; typedef int8 output_t; - MPT_FORCEINLINE output_t operator() (input_t val) + MPT_FORCEINLINE output_t operator()(input_t val) { Limit(val, -1.0f, 1.0f); val *= 128.0f; @@ -463,7 +467,7 @@ { typedef double input_t; typedef int8 output_t; - MPT_FORCEINLINE output_t operator() (input_t val) + MPT_FORCEINLINE output_t operator()(input_t val) { Limit(val, -1.0, 1.0); val *= 128.0; @@ -476,9 +480,9 @@ { typedef uint8 input_t; typedef int16 output_t; - MPT_FORCEINLINE output_t operator() (input_t val) + MPT_FORCEINLINE output_t operator()(input_t val) { - return static_cast(MPT_SC_LSHIFT_SIGNED(static_cast(val)-0x80, 8)); + return static_cast(MPT_SC_LSHIFT_SIGNED(static_cast(val) - 0x80, 8)); } }; @@ -487,7 +491,7 @@ { typedef int8 input_t; typedef int16 output_t; - MPT_FORCEINLINE output_t operator() (input_t val) + MPT_FORCEINLINE output_t operator()(input_t val) { return static_cast(MPT_SC_LSHIFT_SIGNED(val, 8)); } @@ -498,7 +502,7 @@ { typedef int24 input_t; typedef int16 output_t; - MPT_FORCEINLINE output_t operator() (input_t val) + MPT_FORCEINLINE output_t operator()(input_t val) { return static_cast(MPT_SC_RSHIFT_SIGNED(static_cast(val), 8)); } @@ -509,7 +513,7 @@ { typedef int32 input_t; typedef int16 output_t; - MPT_FORCEINLINE output_t operator() (input_t val) + MPT_FORCEINLINE output_t operator()(input_t val) { return static_cast(MPT_SC_RSHIFT_SIGNED(val, 16)); } @@ -520,7 +524,7 @@ { typedef int64 input_t; typedef int16 output_t; - MPT_FORCEINLINE output_t operator() (input_t val) + MPT_FORCEINLINE output_t operator()(input_t val) { return static_cast(MPT_SC_RSHIFT_SIGNED(val, 48)); } @@ -531,7 +535,7 @@ { typedef float32 input_t; typedef int16 output_t; - MPT_FORCEINLINE output_t operator() (input_t val) + MPT_FORCEINLINE output_t operator()(input_t val) { Limit(val, -1.0f, 1.0f); val *= 32768.0f; @@ -544,7 +548,7 @@ { typedef double input_t; typedef int16 output_t; - MPT_FORCEINLINE output_t operator() (input_t val) + MPT_FORCEINLINE output_t operator()(input_t val) { Limit(val, -1.0, 1.0); val *= 32768.0; @@ -557,9 +561,9 @@ { typedef uint8 input_t; typedef int24 output_t; - MPT_FORCEINLINE output_t operator() (input_t val) + MPT_FORCEINLINE output_t operator()(input_t val) { - return static_cast(MPT_SC_LSHIFT_SIGNED(static_cast(val)-0x80, 16)); + return static_cast(MPT_SC_LSHIFT_SIGNED(static_cast(val) - 0x80, 16)); } }; @@ -568,7 +572,7 @@ { typedef int8 input_t; typedef int24 output_t; - MPT_FORCEINLINE output_t operator() (input_t val) + MPT_FORCEINLINE output_t operator()(input_t val) { return static_cast(MPT_SC_LSHIFT_SIGNED(val, 16)); } @@ -579,7 +583,7 @@ { typedef int16 input_t; typedef int24 output_t; - MPT_FORCEINLINE output_t operator() (input_t val) + MPT_FORCEINLINE output_t operator()(input_t val) { return static_cast(MPT_SC_LSHIFT_SIGNED(val, 8)); } @@ -590,7 +594,7 @@ { typedef int32 input_t; typedef int24 output_t; - MPT_FORCEINLINE output_t operator() (input_t val) + MPT_FORCEINLINE output_t operator()(input_t val) { return static_cast(MPT_SC_RSHIFT_SIGNED(val, 8)); } @@ -601,7 +605,7 @@ { typedef int64 input_t; typedef int24 output_t; - MPT_FORCEINLINE output_t operator() (input_t val) + MPT_FORCEINLINE output_t operator()(input_t val) { return static_cast(MPT_SC_RSHIFT_SIGNED(val, 40)); } @@ -612,7 +616,7 @@ { typedef float32 input_t; typedef int24 output_t; - MPT_FORCEINLINE output_t operator() (input_t val) + MPT_FORCEINLINE output_t operator()(input_t val) { Limit(val, -1.0f, 1.0f); val *= 2147483648.0f; @@ -625,7 +629,7 @@ { typedef double input_t; typedef int24 output_t; - MPT_FORCEINLINE output_t operator() (input_t val) + MPT_FORCEINLINE output_t operator()(input_t val) { Limit(val, -1.0, 1.0); val *= 2147483648.0; @@ -638,9 +642,9 @@ { typedef uint8 input_t; typedef int32 output_t; - MPT_FORCEINLINE output_t operator() (input_t val) + MPT_FORCEINLINE output_t operator()(input_t val) { - return static_cast(MPT_SC_LSHIFT_SIGNED(static_cast(val)-0x80, 24)); + return static_cast(MPT_SC_LSHIFT_SIGNED(static_cast(val) - 0x80, 24)); } }; @@ -649,7 +653,7 @@ { typedef int8 input_t; typedef int32 output_t; - MPT_FORCEINLINE output_t operator() (input_t val) + MPT_FORCEINLINE output_t operator()(input_t val) { return static_cast(MPT_SC_LSHIFT_SIGNED(val, 24)); } @@ -660,7 +664,7 @@ { typedef int16 input_t; typedef int32 output_t; - MPT_FORCEINLINE output_t operator() (input_t val) + MPT_FORCEINLINE output_t operator()(input_t val) { return static_cast(MPT_SC_LSHIFT_SIGNED(val, 16)); } @@ -671,7 +675,7 @@ { typedef int24 input_t; typedef int32 output_t; - MPT_FORCEINLINE output_t operator() (input_t val) + MPT_FORCEINLINE output_t operator()(input_t val) { return static_cast(MPT_SC_LSHIFT_SIGNED(static_cast(val), 8)); } @@ -682,7 +686,7 @@ { typedef int64 input_t; typedef int32 output_t; - MPT_FORCEINLINE output_t operator() (input_t val) + MPT_FORCEINLINE output_t operator()(input_t val) { return static_cast(MPT_SC_RSHIFT_SIGNED(val, 32)); } @@ -693,7 +697,7 @@ { typedef float32 input_t; typedef int32 output_t; - MPT_FORCEINLINE output_t operator() (input_t val) + MPT_FORCEINLINE output_t operator()(input_t val) { Limit(val, -1.0f, 1.0f); val *= 2147483648.0f; @@ -706,7 +710,7 @@ { typedef double input_t; typedef int32 output_t; - MPT_FORCEINLINE output_t operator() (input_t val) + MPT_FORCEINLINE output_t operator()(input_t val) { Limit(val, -1.0, 1.0); val *= 2147483648.0; @@ -719,9 +723,9 @@ { typedef uint8 input_t; typedef int64 output_t; - MPT_FORCEINLINE output_t operator() (input_t val) + MPT_FORCEINLINE output_t operator()(input_t val) { - return MPT_SC_LSHIFT_SIGNED(static_cast(val)-0x80, 56); + return MPT_SC_LSHIFT_SIGNED(static_cast(val) - 0x80, 56); } }; @@ -730,7 +734,7 @@ { typedef int8 input_t; typedef int64 output_t; - MPT_FORCEINLINE output_t operator() (input_t val) + MPT_FORCEINLINE output_t operator()(input_t val) { return MPT_SC_LSHIFT_SIGNED(static_cast(val), 56); } @@ -741,7 +745,7 @@ { typedef int16 input_t; typedef int64 output_t; - MPT_FORCEINLINE output_t operator() (input_t val) + MPT_FORCEINLINE output_t operator()(input_t val) { return MPT_SC_LSHIFT_SIGNED(static_cast(val), 48); } @@ -752,7 +756,7 @@ { typedef int24 input_t; typedef int64 output_t; - MPT_FORCEINLINE output_t operator() (input_t val) + MPT_FORCEINLINE output_t operator()(input_t val) { return MPT_SC_LSHIFT_SIGNED(static_cast(val), 40); } @@ -763,7 +767,7 @@ { typedef int32 input_t; typedef int64 output_t; - MPT_FORCEINLINE output_t operator() (input_t val) + MPT_FORCEINLINE output_t operator()(input_t val) { return MPT_SC_LSHIFT_SIGNED(static_cast(val), 32); } @@ -774,10 +778,10 @@ { typedef float32 input_t; typedef int64 output_t; - MPT_FORCEINLINE output_t operator() (input_t val) + MPT_FORCEINLINE output_t operator()(input_t val) { Limit(val, -1.0f, 1.0f); - val *= static_cast(uint64(1)<<63); + val *= static_cast(uint64(1) << 63); return mpt::saturate_cast(MPT_SC_FASTROUND(val)); } }; @@ -787,10 +791,10 @@ { typedef double input_t; typedef int64 output_t; - MPT_FORCEINLINE output_t operator() (input_t val) + MPT_FORCEINLINE output_t operator()(input_t val) { Limit(val, -1.0, 1.0); - val *= static_cast(uint64(1)<<63); + val *= static_cast(uint64(1) << 63); return mpt::saturate_cast(MPT_SC_FASTROUND(val)); } }; @@ -800,9 +804,9 @@ { typedef uint8 input_t; typedef float32 output_t; - MPT_FORCEINLINE output_t operator() (input_t val) + MPT_FORCEINLINE output_t operator()(input_t val) { - return (static_cast(val)-0x80) * (1.0f / static_cast(static_cast(1)<<7)); + return (static_cast(val) - 0x80) * (1.0f / static_cast(static_cast(1) << 7)); } }; @@ -811,9 +815,9 @@ { typedef int8 input_t; typedef float32 output_t; - MPT_FORCEINLINE output_t operator() (input_t val) + MPT_FORCEINLINE output_t operator()(input_t val) { - return val * (1.0f / static_cast(static_cast(1)<<7)); + return val * (1.0f / static_cast(static_cast(1) << 7)); } }; @@ -822,9 +826,9 @@ { typedef int16 input_t; typedef float32 output_t; - MPT_FORCEINLINE output_t operator() (input_t val) + MPT_FORCEINLINE output_t operator()(input_t val) { - return val * (1.0f / static_cast(static_cast(1)<<15)); + return val * (1.0f / static_cast(static_cast(1) << 15)); } }; @@ -833,9 +837,9 @@ { typedef int24 input_t; typedef float32 output_t; - MPT_FORCEINLINE output_t operator() (input_t val) + MPT_FORCEINLINE output_t operator()(input_t val) { - return val * (1.0f / static_cast(static_cast(1)<<23)); + return val * (1.0f / static_cast(static_cast(1) << 23)); } }; @@ -844,9 +848,9 @@ { typedef int32 input_t; typedef float32 output_t; - MPT_FORCEINLINE output_t operator() (input_t val) + MPT_FORCEINLINE output_t operator()(input_t val) { - return val * (1.0f / static_cast(static_cast(1)<<31)); + return val * (1.0f / static_cast(static_cast(1) << 31)); } }; @@ -855,9 +859,9 @@ { typedef int64 input_t; typedef float32 output_t; - MPT_FORCEINLINE output_t operator() (input_t val) + MPT_FORCEINLINE output_t operator()(input_t val) { - return val * (1.0f / static_cast(static_cast(1)<<63)); + return val * (1.0f / static_cast(static_cast(1) << 63)); } }; @@ -866,9 +870,9 @@ { typedef uint8 input_t; typedef double output_t; - MPT_FORCEINLINE output_t operator() (input_t val) + MPT_FORCEINLINE output_t operator()(input_t val) { - return (static_cast(val)-0x80) * (1.0 / static_cast(static_cast(1)<<7)); + return (static_cast(val) - 0x80) * (1.0 / static_cast(static_cast(1) << 7)); } }; @@ -877,9 +881,9 @@ { typedef int8 input_t; typedef double output_t; - MPT_FORCEINLINE output_t operator() (input_t val) + MPT_FORCEINLINE output_t operator()(input_t val) { - return val * (1.0 / static_cast(static_cast(1)<<7)); + return val * (1.0 / static_cast(static_cast(1) << 7)); } }; @@ -888,9 +892,9 @@ { typedef int16 input_t; typedef double output_t; - MPT_FORCEINLINE output_t operator() (input_t val) + MPT_FORCEINLINE output_t operator()(input_t val) { - return val * (1.0 / static_cast(static_cast(1)<<15)); + return val * (1.0 / static_cast(static_cast(1) << 15)); } }; @@ -899,9 +903,9 @@ { typedef int24 input_t; typedef double output_t; - MPT_FORCEINLINE output_t operator() (input_t val) + MPT_FORCEINLINE output_t operator()(input_t val) { - return val * (1.0 / static_cast(static_cast(1)<<23)); + return val * (1.0 / static_cast(static_cast(1) << 23)); } }; @@ -910,9 +914,9 @@ { typedef int32 input_t; typedef double output_t; - MPT_FORCEINLINE output_t operator() (input_t val) + MPT_FORCEINLINE output_t operator()(input_t val) { - return val * (1.0 / static_cast(static_cast(1)<<31)); + return val * (1.0 / static_cast(static_cast(1) << 31)); } }; @@ -921,9 +925,9 @@ { typedef int64 input_t; typedef double output_t; - MPT_FORCEINLINE output_t operator() (input_t val) + MPT_FORCEINLINE output_t operator()(input_t val) { - return val * (1.0 / static_cast(static_cast(1)<<63)); + return val * (1.0 / static_cast(static_cast(1) << 63)); } }; @@ -932,7 +936,7 @@ { typedef float input_t; typedef double output_t; - MPT_FORCEINLINE output_t operator() (input_t val) + MPT_FORCEINLINE output_t operator()(input_t val) { return static_cast(val); } @@ -943,7 +947,7 @@ { typedef double input_t; typedef float output_t; - MPT_FORCEINLINE output_t operator() (input_t val) + MPT_FORCEINLINE output_t operator()(input_t val) { return static_cast(val); } @@ -959,14 +963,14 @@ typedef int32 input_t; typedef uint8 output_t; static constexpr int shiftBits = fractionalBits + 1 - sizeof(output_t) * 8; - MPT_FORCEINLINE output_t operator() (input_t val) + MPT_FORCEINLINE output_t operator()(input_t val) { - static_assert(fractionalBits >= 0 && fractionalBits <= sizeof(input_t)*8-1); + static_assert(fractionalBits >= 0 && fractionalBits <= sizeof(input_t) * 8 - 1); static_assert(shiftBits >= 1); - val = MPT_SC_RSHIFT_SIGNED((val + (1<<(shiftBits-1))), shiftBits); // round + val = MPT_SC_RSHIFT_SIGNED((val + (1 << (shiftBits - 1))), shiftBits); // round if(val < int8_min) val = int8_min; if(val > int8_max) val = int8_max; - return static_cast(val+0x80); // unsigned + return static_cast(val + 0x80); // unsigned } }; @@ -976,11 +980,11 @@ typedef int32 input_t; typedef int8 output_t; static constexpr int shiftBits = fractionalBits + 1 - sizeof(output_t) * 8; - MPT_FORCEINLINE output_t operator() (input_t val) + MPT_FORCEINLINE output_t operator()(input_t val) { - static_assert(fractionalBits >= 0 && fractionalBits <= sizeof(input_t)*8-1); + static_assert(fractionalBits >= 0 && fractionalBits <= sizeof(input_t) * 8 - 1); static_assert(shiftBits >= 1); - val = MPT_SC_RSHIFT_SIGNED((val + (1<<(shiftBits-1))), shiftBits); // round + val = MPT_SC_RSHIFT_SIGNED((val + (1 << (shiftBits - 1))), shiftBits); // round if(val < int8_min) val = int8_min; if(val > int8_max) val = int8_max; return static_cast(val); @@ -993,11 +997,11 @@ typedef int32 input_t; typedef int16 output_t; static constexpr int shiftBits = fractionalBits + 1 - sizeof(output_t) * 8; - MPT_FORCEINLINE output_t operator() (input_t val) + MPT_FORCEINLINE output_t operator()(input_t val) { - static_assert(fractionalBits >= 0 && fractionalBits <= sizeof(input_t)*8-1); + static_assert(fractionalBits >= 0 && fractionalBits <= sizeof(input_t) * 8 - 1); static_assert(shiftBits >= 1); - val = MPT_SC_RSHIFT_SIGNED((val + (1<<(shiftBits-1))), shiftBits); // round + val = MPT_SC_RSHIFT_SIGNED((val + (1 << (shiftBits - 1))), shiftBits); // round if(val < int16_min) val = int16_min; if(val > int16_max) val = int16_max; return static_cast(val); @@ -1010,11 +1014,11 @@ typedef int32 input_t; typedef int24 output_t; static constexpr int shiftBits = fractionalBits + 1 - sizeof(output_t) * 8; - MPT_FORCEINLINE output_t operator() (input_t val) + MPT_FORCEINLINE output_t operator()(input_t val) { - static_assert(fractionalBits >= 0 && fractionalBits <= sizeof(input_t)*8-1); + static_assert(fractionalBits >= 0 && fractionalBits <= sizeof(input_t) * 8 - 1); static_assert(shiftBits >= 1); - val = MPT_SC_RSHIFT_SIGNED((val + (1<<(shiftBits-1))), shiftBits); // round + val = MPT_SC_RSHIFT_SIGNED((val + (1 << (shiftBits - 1))), shiftBits); // round if(val < int24_min) val = int24_min; if(val > int24_max) val = int24_max; return static_cast(val); @@ -1026,10 +1030,10 @@ { typedef int32 input_t; typedef int32 output_t; - MPT_FORCEINLINE output_t operator() (input_t val) + MPT_FORCEINLINE output_t operator()(input_t val) { - static_assert(fractionalBits >= 0 && fractionalBits <= sizeof(input_t)*8-1); - return static_cast(Clamp(val, static_cast(-((1<(1<= 0 && fractionalBits <= sizeof(input_t) * 8 - 1); + return static_cast(Clamp(val, static_cast(-((1 << fractionalBits) - 1)), static_cast(1 << fractionalBits) - 1)) << (sizeof(input_t) * 8 - 1 - fractionalBits); } }; @@ -1040,13 +1044,13 @@ typedef float32 output_t; const float factor; MPT_FORCEINLINE ConvertFixedPoint() - : factor( 1.0f / static_cast(1 << fractionalBits) ) + : factor(1.0f / static_cast(1 << fractionalBits)) { return; } - MPT_FORCEINLINE output_t operator() (input_t val) + MPT_FORCEINLINE output_t operator()(input_t val) { - static_assert(fractionalBits >= 0 && fractionalBits <= sizeof(input_t)*8-1); + static_assert(fractionalBits >= 0 && fractionalBits <= sizeof(input_t) * 8 - 1); return val * factor; } }; @@ -1058,13 +1062,13 @@ typedef float64 output_t; const double factor; MPT_FORCEINLINE ConvertFixedPoint() - : factor( 1.0 / static_cast(1 << fractionalBits) ) + : factor(1.0 / static_cast(1 << fractionalBits)) { return; } - MPT_FORCEINLINE output_t operator() (input_t val) + MPT_FORCEINLINE output_t operator()(input_t val) { - static_assert(fractionalBits >= 0 && fractionalBits <= sizeof(input_t)*8-1); + static_assert(fractionalBits >= 0 && fractionalBits <= sizeof(input_t) * 8 - 1); return val * factor; } }; @@ -1079,11 +1083,11 @@ typedef uint8 input_t; typedef int32 output_t; static constexpr int shiftBits = fractionalBits + 1 - sizeof(input_t) * 8; - MPT_FORCEINLINE output_t operator() (input_t val) + MPT_FORCEINLINE output_t operator()(input_t val) { - static_assert(fractionalBits >= 0 && fractionalBits <= sizeof(output_t)*8-1); + static_assert(fractionalBits >= 0 && fractionalBits <= sizeof(output_t) * 8 - 1); static_assert(shiftBits >= 1); - return MPT_SC_LSHIFT_SIGNED(static_cast(static_cast(val)-0x80), shiftBits); + return MPT_SC_LSHIFT_SIGNED(static_cast(static_cast(val) - 0x80), shiftBits); } }; @@ -1093,9 +1097,9 @@ typedef int8 input_t; typedef int32 output_t; static constexpr int shiftBits = fractionalBits + 1 - sizeof(input_t) * 8; - MPT_FORCEINLINE output_t operator() (input_t val) + MPT_FORCEINLINE output_t operator()(input_t val) { - static_assert(fractionalBits >= 0 && fractionalBits <= sizeof(output_t)*8-1); + static_assert(fractionalBits >= 0 && fractionalBits <= sizeof(output_t) * 8 - 1); static_assert(shiftBits >= 1); return MPT_SC_LSHIFT_SIGNED(static_cast(val), shiftBits); } @@ -1107,9 +1111,9 @@ typedef int16 input_t; typedef int32 output_t; static constexpr int shiftBits = fractionalBits + 1 - sizeof(input_t) * 8; - MPT_FORCEINLINE output_t operator() (input_t val) + MPT_FORCEINLINE output_t operator()(input_t val) { - static_assert(fractionalBits >= 0 && fractionalBits <= sizeof(output_t)*8-1); + static_assert(fractionalBits >= 0 && fractionalBits <= sizeof(output_t) * 8 - 1); static_assert(shiftBits >= 1); return MPT_SC_LSHIFT_SIGNED(static_cast(val), shiftBits); } @@ -1121,9 +1125,9 @@ typedef int24 input_t; typedef int32 output_t; static constexpr int shiftBits = fractionalBits + 1 - sizeof(input_t) * 8; - MPT_FORCEINLINE output_t operator() (input_t val) + MPT_FORCEINLINE output_t operator()(input_t val) { - static_assert(fractionalBits >= 0 && fractionalBits <= sizeof(output_t)*8-1); + static_assert(fractionalBits >= 0 && fractionalBits <= sizeof(output_t) * 8 - 1); static_assert(shiftBits >= 1); return MPT_SC_LSHIFT_SIGNED(static_cast(val), shiftBits); } @@ -1134,10 +1138,10 @@ { typedef int32 input_t; typedef int32 output_t; - MPT_FORCEINLINE output_t operator() (input_t val) + MPT_FORCEINLINE output_t operator()(input_t val) { - static_assert(fractionalBits >= 0 && fractionalBits <= sizeof(output_t)*8-1); - return MPT_SC_RSHIFT_SIGNED(static_cast(val), (sizeof(input_t)*8-1-fractionalBits)); + static_assert(fractionalBits >= 0 && fractionalBits <= sizeof(output_t) * 8 - 1); + return MPT_SC_RSHIFT_SIGNED(static_cast(val), (sizeof(input_t) * 8 - 1 - fractionalBits)); } }; @@ -1148,13 +1152,13 @@ typedef int32 output_t; const float factor; MPT_FORCEINLINE ConvertToFixedPoint() - : factor( static_cast(1 << fractionalBits) ) + : factor(static_cast(1 << fractionalBits)) { return; } - MPT_FORCEINLINE output_t operator() (input_t val) + MPT_FORCEINLINE output_t operator()(input_t val) { - static_assert(fractionalBits >= 0 && fractionalBits <= sizeof(input_t)*8-1); + static_assert(fractionalBits >= 0 && fractionalBits <= sizeof(input_t) * 8 - 1); return mpt::saturate_cast(MPT_SC_FASTROUND(val * factor)); } }; @@ -1166,13 +1170,13 @@ typedef int32 output_t; const double factor; MPT_FORCEINLINE ConvertToFixedPoint() - : factor( static_cast(1 << fractionalBits) ) + : factor(static_cast(1 << fractionalBits)) { return; } - MPT_FORCEINLINE output_t operator() (input_t val) + MPT_FORCEINLINE output_t operator()(input_t val) { - static_assert(fractionalBits >= 0 && fractionalBits <= sizeof(input_t)*8-1); + static_assert(fractionalBits >= 0 && fractionalBits <= sizeof(input_t) * 8 - 1); return mpt::saturate_cast(MPT_SC_FASTROUND(val * factor)); } }; @@ -1189,7 +1193,7 @@ static constexpr std::size_t input_inc = Func1::input_inc; Func1 func1; Func2 func2; - MPT_FORCEINLINE output_t operator() (const input_t *inBuf) + MPT_FORCEINLINE output_t operator()(const input_t *inBuf) { return func2(func1(inBuf)); } @@ -1207,9 +1211,9 @@ { typedef Tfixed input_t; typedef Tfixed output_t; - MPT_FORCEINLINE Tfixed operator() (Tfixed val) + MPT_FORCEINLINE Tfixed operator()(Tfixed val) { - static_assert(fractionalBits >= 0 && fractionalBits <= sizeof(output_t)*8-1); + static_assert(fractionalBits >= 0 && fractionalBits <= sizeof(output_t) * 8 - 1); if constexpr(clipOutput) { constexpr Tfixed clip_max = (Tfixed(1) << fractionalBits) - Tfixed(1); @@ -1233,7 +1237,7 @@ { typedef float input_t; typedef float output_t; - MPT_FORCEINLINE float operator() (float val) + MPT_FORCEINLINE float operator()(float val) { if constexpr(clipOutput) { @@ -1252,7 +1256,7 @@ { typedef double input_t; typedef double output_t; - MPT_FORCEINLINE double operator() (double val) + MPT_FORCEINLINE double operator()(double val) { if constexpr(clipOutput) { @@ -1277,7 +1281,8 @@ typedef int32 output_t; typedef uint32 peak_t; uint32 maxVal; - MPT_FORCEINLINE Normalize() : maxVal(0) { } + MPT_FORCEINLINE Normalize() + : maxVal(0) {} MPT_FORCEINLINE void FindMax(input_t val) { if(val < 0) @@ -1298,7 +1303,7 @@ { return maxVal == 0; } - MPT_FORCEINLINE output_t operator() (input_t val) + MPT_FORCEINLINE output_t operator()(input_t val) { return Util::muldivrfloor(val, static_cast(1) << 31, maxVal); } @@ -1316,7 +1321,8 @@ typedef float32 peak_t; float maxVal; float maxValInv; - MPT_FORCEINLINE Normalize() : maxVal(0.0f), maxValInv(1.0f) { } + MPT_FORCEINLINE Normalize() + : maxVal(0.0f), maxValInv(1.0f) {} MPT_FORCEINLINE void FindMax(input_t val) { float absval = std::fabs(val); @@ -1337,7 +1343,7 @@ return false; } } - MPT_FORCEINLINE output_t operator() (input_t val) + MPT_FORCEINLINE output_t operator()(input_t val) { return val * maxValInv; } @@ -1355,7 +1361,8 @@ typedef float64 peak_t; double maxVal; double maxValInv; - MPT_FORCEINLINE Normalize() : maxVal(0.0), maxValInv(1.0) { } + MPT_FORCEINLINE Normalize() + : maxVal(0.0), maxValInv(1.0) {} MPT_FORCEINLINE void FindMax(input_t val) { double absval = std::fabs(val); @@ -1376,7 +1383,7 @@ return false; } } - MPT_FORCEINLINE output_t operator() (input_t val) + MPT_FORCEINLINE output_t operator()(input_t val) { return val * maxValInv; } @@ -1410,7 +1417,7 @@ { return normalize.IsSilent(); } - MPT_FORCEINLINE output_t operator() (const input_t *inBuf) + MPT_FORCEINLINE output_t operator()(const input_t *inBuf) { return func2(normalize(func1(inBuf))); } @@ -1434,7 +1441,7 @@ -} // namespace SC +} // namespace SC Index: soundbase/SampleFormatCopy.h =================================================================== --- soundbase/SampleFormatCopy.h (revision 14154) +++ soundbase/SampleFormatCopy.h (working copy) @@ -35,7 +35,7 @@ // Template arguments: // SampleConversion: Functor of type SampleConversionFunctor to apply sample conversion (see above for existing functors). template -size_t CopySample(typename SampleConversion::output_t * MPT_RESTRICT outBuf, size_t numSamples, size_t incTarget, const typename SampleConversion::input_t * MPT_RESTRICT inBuf, size_t sourceSize, size_t incSource, SampleConversion conv = SampleConversion()) +size_t CopySample(typename SampleConversion::output_t *MPT_RESTRICT outBuf, size_t numSamples, size_t incTarget, const typename SampleConversion::input_t *MPT_RESTRICT inBuf, size_t sourceSize, size_t incSource, SampleConversion conv = SampleConversion()) { const size_t sampleSize = incSource * SampleConversion::input_inc * sizeof(typename SampleConversion::input_t); LimitMax(numSamples, sourceSize / sampleSize); @@ -55,7 +55,7 @@ // Copy numChannels interleaved sample streams. template -void CopyInterleavedSampleStreams(typename SampleConversion::output_t * MPT_RESTRICT outBuf, const typename SampleConversion::input_t * MPT_RESTRICT inBuf, size_t numFrames, size_t numChannels, SampleConversion *conv) +void CopyInterleavedSampleStreams(typename SampleConversion::output_t *MPT_RESTRICT outBuf, const typename SampleConversion::input_t *MPT_RESTRICT inBuf, size_t numFrames, size_t numChannels, SampleConversion *conv) { while(numFrames--) { @@ -71,7 +71,7 @@ // Copy numChannels interleaved sample streams. template -void CopyInterleavedSampleStreams(typename SampleConversion::output_t * MPT_RESTRICT outBuf, const typename SampleConversion::input_t * MPT_RESTRICT inBuf, size_t numFrames, size_t numChannels, std::vector &conv) +void CopyInterleavedSampleStreams(typename SampleConversion::output_t *MPT_RESTRICT outBuf, const typename SampleConversion::input_t *MPT_RESTRICT inBuf, size_t numFrames, size_t numChannels, std::vector &conv) { MPT_ASSERT(conv.size() >= numChannels); CopyInterleavedSampleStreams(outBuf, inBuf, numFrames, numChannels, &(conv[0])); @@ -78,18 +78,18 @@ } -template -void ConvertBufferMixFixedToBuffer(TOutBuf outBuf, TInBuf inBuf, Tdither & dither, std::size_t channels, std::size_t count) +template +void ConvertBufferMixFixedToBuffer(TOutBuf outBuf, TInBuf inBuf, Tdither &dither, std::size_t channels, std::size_t count) { using TOutSample = typename std::remove_const::type; - using TInSample = typename std::remove_const::type; + using TInSample = typename std::remove_const::type; MPT_ASSERT(inBuf.size_channels() >= channels); MPT_ASSERT(outBuf.size_channels() >= channels); MPT_ASSERT(inBuf.size_frames() >= count); MPT_ASSERT(outBuf.size_frames() >= count); constexpr int ditherBits = SampleFormat(SampleFormatTraits::sampleFormat()).IsInt() - ? SampleFormat(SampleFormatTraits::sampleFormat()).GetBitsPerSample() - : 0; + ? SampleFormat(SampleFormatTraits::sampleFormat()).GetBitsPerSample() + : 0; SC::ClipFixed clip; SC::ConvertFixedPoint conv; for(std::size_t i = 0; i < count; ++i) @@ -102,11 +102,11 @@ } -template +template void ConvertBufferToBufferMixFixed(TOutBuf outBuf, TInBuf inBuf, std::size_t channels, std::size_t count) { using TOutSample = typename std::remove_const::type; - using TInSample = typename std::remove_const::type; + using TInSample = typename std::remove_const::type; MPT_ASSERT(inBuf.size_channels() >= channels); MPT_ASSERT(outBuf.size_channels() >= channels); MPT_ASSERT(inBuf.size_frames() >= count); @@ -122,18 +122,18 @@ } -template -void ConvertBufferMixFloatToBuffer(TOutBuf outBuf, TInBuf inBuf, Tdither & dither, std::size_t channels, std::size_t count) +template +void ConvertBufferMixFloatToBuffer(TOutBuf outBuf, TInBuf inBuf, Tdither &dither, std::size_t channels, std::size_t count) { using TOutSample = typename std::remove_const::type; - using TInSample = typename std::remove_const::type; + using TInSample = typename std::remove_const::type; MPT_ASSERT(inBuf.size_channels() >= channels); MPT_ASSERT(outBuf.size_channels() >= channels); MPT_ASSERT(inBuf.size_frames() >= count); MPT_ASSERT(outBuf.size_frames() >= count); constexpr int ditherBits = SampleFormat(SampleFormatTraits::sampleFormat()).IsInt() - ? SampleFormat(SampleFormatTraits::sampleFormat()).GetBitsPerSample() - : 0; + ? SampleFormat(SampleFormatTraits::sampleFormat()).GetBitsPerSample() + : 0; SC::ClipFloat clip; SC::Convert conv; for(std::size_t i = 0; i < count; ++i) @@ -146,11 +146,11 @@ } -template +template void ConvertBufferToBufferMixFloat(TOutBuf outBuf, TInBuf inBuf, std::size_t channels, std::size_t count) { using TOutSample = typename std::remove_const::type; - using TInSample = typename std::remove_const::type; + using TInSample = typename std::remove_const::type; MPT_ASSERT(inBuf.size_channels() >= channels); MPT_ASSERT(outBuf.size_channels() >= channels); MPT_ASSERT(inBuf.size_frames() >= count); @@ -166,11 +166,11 @@ } -template +template void ConvertBufferToBuffer(TOutBuf outBuf, TInBuf inBuf, std::size_t channels, std::size_t count) { using TOutSample = typename std::remove_const::type; - using TInSample = typename std::remove_const::type; + using TInSample = typename std::remove_const::type; MPT_ASSERT(inBuf.size_channels() >= channels); MPT_ASSERT(outBuf.size_channels() >= channels); MPT_ASSERT(inBuf.size_frames() >= count); @@ -188,7 +188,7 @@ // Copy from an interleaed buffer of #channels. template -void CopyInterleavedToChannel(typename SampleConversion::output_t * MPT_RESTRICT dst, const typename SampleConversion::input_t * MPT_RESTRICT src, std::size_t channels, std::size_t countChunk, std::size_t channel, SampleConversion conv = SampleConversion()) +void CopyInterleavedToChannel(typename SampleConversion::output_t *MPT_RESTRICT dst, const typename SampleConversion::input_t *MPT_RESTRICT src, std::size_t channels, std::size_t countChunk, std::size_t channel, SampleConversion conv = SampleConversion()) { SampleConversion sampleConv(conv); src += channel; @@ -203,7 +203,7 @@ // Copy buffer to an interleaed buffer of #channels. template -void CopyChannelToInterleaved(typename SampleConversion::output_t * MPT_RESTRICT dst, const typename SampleConversion::input_t * MPT_RESTRICT src, std::size_t channels, std::size_t countChunk, std::size_t channel, SampleConversion conv = SampleConversion()) +void CopyChannelToInterleaved(typename SampleConversion::output_t *MPT_RESTRICT dst, const typename SampleConversion::input_t *MPT_RESTRICT src, std::size_t channels, std::size_t countChunk, std::size_t channel, SampleConversion conv = SampleConversion()) { SampleConversion sampleConv(conv); dst += channel; Index: soundbase/SampleTypes.h =================================================================== --- soundbase/SampleTypes.h (revision 14154) +++ soundbase/SampleTypes.h (working copy) @@ -21,7 +21,7 @@ OPENMPT_NAMESPACE_BEGIN -using AudioSampleInt = int16; +using AudioSampleInt = int16; using AudioSampleFloat = nativefloat; using AudioSample = std::conditional::is_hard, AudioSampleFloat, AudioSampleInt>::type; @@ -35,7 +35,9 @@ static_assert((sizeof(Tsample) * 8u) - 1 > MIX_HEADROOM_BITS); static_assert((sizeof(Tsample) * 8u) - 1 > FILTER_HEADROOM_BITS); using sample_type = Tsample; - enum class sample_type_strong : sample_type {}; + enum class sample_type_strong : sample_type + { + }; static constexpr int mix_headroom_bits() noexcept { return static_cast(MIX_HEADROOM_BITS); } static constexpr int mix_precision_bits() noexcept { return static_cast((sizeof(Tsample) * 8) - MIX_HEADROOM_BITS); } // including sign bit static constexpr int mix_fractional_bits() noexcept { return static_cast((sizeof(Tsample) * 8) - 1 - MIX_HEADROOM_BITS); } // excluding sign bit @@ -45,12 +47,15 @@ static constexpr int filter_precision_bits() noexcept { return static_cast((sizeof(Tsample) * 8) - FILTER_HEADROOM_BITS); } // including sign bit static constexpr int filter_fractional_bits() noexcept { return static_cast((sizeof(Tsample) * 8) - 1 - FILTER_HEADROOM_BITS); } // excluding sign bit template - static constexpr Tfloat mix_scale() noexcept { return static_cast(sample_type(1) << mix_fractional_bits()); } + static constexpr Tfloat mix_scale() noexcept + { + return static_cast(sample_type(1) << mix_fractional_bits()); + } }; using MixSampleIntTraits = FixedPointSampleTraits; -using MixSampleInt = MixSampleIntTraits::sample_type; +using MixSampleInt = MixSampleIntTraits::sample_type; using MixSampleFloat = AudioSampleFloat; using MixSample = std::conditional::is_hard, MixSampleFloat, MixSampleInt>::type; Index: sounddev/SoundDevice.cpp =================================================================== --- sounddev/SoundDevice.cpp (revision 14154) +++ sounddev/SoundDevice.cpp (working copy) @@ -22,7 +22,8 @@ OPENMPT_NAMESPACE_BEGIN -namespace SoundDevice { +namespace SoundDevice +{ SysInfo::SysInfo() @@ -34,7 +35,7 @@ { mpt::OS::Wine::VersionContext wineVersionContext; WineHostClass = wineVersionContext.HostClass(); - WineVersion = wineVersionContext.Version(); + WineVersion = wineVersionContext.Version(); } @@ -60,21 +61,21 @@ mpt::ustring result = apiName + U_(" - ") + mpt::String::Trim(name); switch(flags.usability) { - case SoundDevice::Info::Usability::Experimental: - result += U_(" [experimental]"); - break; - case SoundDevice::Info::Usability::Deprecated: - result += U_(" [deprecated]"); - break; - case SoundDevice::Info::Usability::Broken: - result += U_(" [broken]"); - break; - case SoundDevice::Info::Usability::NotAvailable: - result += U_(" [alien]"); - break; - default: - // nothing - break; + case SoundDevice::Info::Usability::Experimental: + result += U_(" [experimental]"); + break; + case SoundDevice::Info::Usability::Deprecated: + result += U_(" [deprecated]"); + break; + case SoundDevice::Info::Usability::Broken: + result += U_(" [broken]"); + break; + case SoundDevice::Info::Usability::NotAvailable: + result += U_(" [alien]"); + break; + default: + // nothing + break; } if(default_ == SoundDevice::Info::Default::Named) { @@ -159,7 +160,7 @@ } -} // namespace SoundDevice +} // namespace SoundDevice OPENMPT_NAMESPACE_END Index: sounddev/SoundDevice.h =================================================================== --- sounddev/SoundDevice.h (revision 14154) +++ sounddev/SoundDevice.h (working copy) @@ -26,7 +26,8 @@ OPENMPT_NAMESPACE_BEGIN -namespace SoundDevice { +namespace SoundDevice +{ class IMessageReceiver @@ -38,16 +39,18 @@ struct StreamPosition { - int64 Frames; // relative to Start() - double Seconds; // relative to Start() - StreamPosition() : Frames(0), Seconds(0.0) { } - StreamPosition(int64 frames, double seconds) : Frames(frames), Seconds(seconds) { } + int64 Frames; // relative to Start() + double Seconds; // relative to Start() + StreamPosition() + : Frames(0), Seconds(0.0) {} + StreamPosition(int64 frames, double seconds) + : Frames(frames), Seconds(seconds) {} }; struct TimeInfo { - + int64 SyncPointStreamFrames; uint64 SyncPointSystemTimestamp; double Speed; @@ -55,9 +58,9 @@ SoundDevice::StreamPosition RenderStreamPositionBefore; SoundDevice::StreamPosition RenderStreamPositionAfter; // int64 chunkSize = After - Before - - double Latency; // seconds + double Latency; // seconds + TimeInfo() : SyncPointStreamFrames(0) , SyncPointSystemTimestamp(0) @@ -66,7 +69,6 @@ { return; } - }; @@ -84,27 +86,27 @@ { public: // main thread - virtual uint64 SoundSourceGetReferenceClockNowNanoseconds() const = 0; // timeGetTime()*1000000 on Windows - virtual void SoundSourcePreStartCallback() = 0; - virtual void SoundSourcePostStopCallback() = 0; - virtual bool SoundSourceIsLockedByCurrentThread() const = 0; + virtual uint64 SoundSourceGetReferenceClockNowNanoseconds() const = 0; // timeGetTime()*1000000 on Windows + virtual void SoundSourcePreStartCallback() = 0; + virtual void SoundSourcePostStopCallback() = 0; + virtual bool SoundSourceIsLockedByCurrentThread() const = 0; // audio thread - virtual void SoundSourceLock() = 0; - virtual uint64 SoundSourceLockedGetReferenceClockNowNanoseconds() const = 0; // timeGetTime()*1000000 on Windows - virtual void SoundSourceLockedReadPrepare(SoundDevice::TimeInfo timeInfo) = 0; + virtual void SoundSourceLock() = 0; + virtual uint64 SoundSourceLockedGetReferenceClockNowNanoseconds() const = 0; // timeGetTime()*1000000 on Windows + virtual void SoundSourceLockedReadPrepare(SoundDevice::TimeInfo timeInfo) = 0; virtual void SoundSourceLockedRead(SoundDevice::BufferFormat bufferFormat, std::size_t numFrames, void *buffer, const void *inputBuffer) = 0; - virtual void SoundSourceLockedReadDone(SoundDevice::TimeInfo timeInfo) = 0; - virtual void SoundSourceUnlock() = 0; + virtual void SoundSourceLockedReadDone(SoundDevice::TimeInfo timeInfo) = 0; + virtual void SoundSourceUnlock() = 0; }; -static constexpr mpt::uchar TypeWAVEOUT [] = UL_("WaveOut"); -static constexpr mpt::uchar TypeDSOUND [] = UL_("DirectSound"); -static constexpr mpt::uchar TypeASIO [] = UL_("ASIO"); -static constexpr mpt::uchar TypePORTAUDIO_WASAPI [] = UL_("WASAPI"); -static constexpr mpt::uchar TypePORTAUDIO_WDMKS [] = UL_("WDM-KS"); -static constexpr mpt::uchar TypePORTAUDIO_WMME [] = UL_("MME"); -static constexpr mpt::uchar TypePORTAUDIO_DS [] = UL_("DS"); +static constexpr mpt::uchar TypeWAVEOUT[] = UL_("WaveOut"); +static constexpr mpt::uchar TypeDSOUND[] = UL_("DirectSound"); +static constexpr mpt::uchar TypeASIO[] = UL_("ASIO"); +static constexpr mpt::uchar TypePORTAUDIO_WASAPI[] = UL_("WASAPI"); +static constexpr mpt::uchar TypePORTAUDIO_WDMKS[] = UL_("WDM-KS"); +static constexpr mpt::uchar TypePORTAUDIO_WMME[] = UL_("MME"); +static constexpr mpt::uchar TypePORTAUDIO_DS[] = UL_("DS"); typedef mpt::ustring Type; @@ -118,10 +120,11 @@ { SoundDevice::Type type; mpt::ustring internalID; - mpt::ustring name; // user visible (and configuration key if useNameAsIdentifier) - mpt::ustring apiName; // user visible - std::vector apiPath; // i.e. Wine-support, PortAudio - enum class Default { + mpt::ustring name; // user visible (and configuration key if useNameAsIdentifier) + mpt::ustring apiName; // user visible + std::vector apiPath; // i.e. Wine-support, PortAudio + enum class Default + { None = 0, Named = 1, Managed = 2, @@ -129,68 +132,78 @@ Default default_; bool useNameAsIdentifier; - enum class DefaultFor : int8 { + enum class DefaultFor : int8 + { System = 3, ProAudio = 2, LowLevel = 1, None = 0, }; - struct ManagerFlags { - DefaultFor defaultFor = DefaultFor::None; + struct ManagerFlags + { + DefaultFor defaultFor = DefaultFor::None; }; ManagerFlags managerFlags; - enum class Usability : int8 { - Usable = 2, - Experimental = 1, - Unknown = 0, - Deprecated = -3, - Broken = -4, - NotAvailable = -5, + enum class Usability : int8 + { + Usable = 2, + Experimental = 1, + Unknown = 0, + Deprecated = -3, + Broken = -4, + NotAvailable = -5, }; - enum class Level : int8 { - Primary = 1, - Unknown = 0, + enum class Level : int8 + { + Primary = 1, + Unknown = 0, Secondary = -1, }; - enum class Compatible : int8 { - Yes = 1, - Unknown = 0, + enum class Compatible : int8 + { + Yes = 1, + Unknown = 0, No = -1, }; - enum class Api : int8 { - Native = 1, - Unknown = 0, + enum class Api : int8 + { + Native = 1, + Unknown = 0, Emulated = -1, }; - enum class Io : int8 { - FullDuplex = 1, - Unknown = 0, + enum class Io : int8 + { + FullDuplex = 1, + Unknown = 0, OutputOnly = -1, }; - enum class Mixing : int8 { - Server = 2, - Software = 1, - Unknown = 0, + enum class Mixing : int8 + { + Server = 2, + Software = 1, + Unknown = 0, Hardware = -1, }; - enum class Implementor : int8 { - OpenMPT = 1, - Unknown = 0, + enum class Implementor : int8 + { + OpenMPT = 1, + Unknown = 0, External = -1, }; - struct Flags { - Usability usability = Usability::Unknown; - Level level = Level::Unknown; - Compatible compatible = Compatible::Unknown; - Api api = Api::Unknown; - Io io = Io::Unknown; - Mixing mixing = Mixing::Unknown; + struct Flags + { + Usability usability = Usability::Unknown; + Level level = Level::Unknown; + Compatible compatible = Compatible::Unknown; + Api api = Api::Unknown; + Io io = Io::Unknown; + Mixing mixing = Mixing::Unknown; Implementor implementor = Implementor::Unknown; }; Flags flags; - std::map extraData; // user visible (hidden by default) + std::map extraData; // user visible (hidden by default) Info() : default_(Default::None) @@ -226,13 +239,12 @@ result += hexString; } else { - result += internalID; // safe to not contain special characters + result += internalID; // safe to not contain special characters } return result; } mpt::ustring GetDisplayName() const; - }; @@ -240,15 +252,12 @@ { private: - std::vector ChannelToDeviceChannel; public: - static constexpr int32 MaxDeviceChannel = 32000; public: - // Construct default identity mapping ChannelMapping(uint32 numHostChannels = 2); @@ -260,32 +269,30 @@ static ChannelMapping BaseChannel(uint32 channels, int32 baseChannel); private: - // check that the channel mapping is actually a 1:1 mapping static bool IsValid(const std::vector &mapping); public: - - operator int () const + operator int() const { return GetNumHostChannels(); } - ChannelMapping & operator = (int channels) + ChannelMapping &operator=(int channels) { return (*this = ChannelMapping(channels)); } - bool operator == (const SoundDevice::ChannelMapping &cmp) const + bool operator==(const SoundDevice::ChannelMapping &cmp) const { return (ChannelToDeviceChannel == cmp.ChannelToDeviceChannel); } - + uint32 GetNumHostChannels() const { return static_cast(ChannelToDeviceChannel.size()); } - + // Get the number of required device channels for this mapping. Derived from the maximum mapped-to channel number. int32 GetRequiredDeviceChannels() const { @@ -303,7 +310,7 @@ } return maxChannel + 1; } - + // Convert OpenMPT channel number to the mapped device channel number. int32 ToDevice(uint32 channel) const { @@ -317,7 +324,6 @@ mpt::ustring ToUString() const; static SoundDevice::ChannelMapping FromString(const mpt::ustring &str); - }; @@ -329,12 +335,15 @@ bool IsWine; mpt::OS::Class WineHostClass; mpt::OS::Wine::Version WineVersion; + public: bool IsOriginal() const { return !IsWine; } bool IsWindowsOriginal() const { return !IsWine; } bool IsWindowsWine() const { return IsWine; } + public: static SysInfo Current(); + private: SysInfo(); }; @@ -343,7 +352,7 @@ struct AppInfo { mpt::ustring Name; - uintptr_t UIHandle; // HWND on Windows + uintptr_t UIHandle; // HWND on Windows int BoostedThreadPriorityXP; mpt::ustring BoostedThreadMMCSSClassVista; bool BoostedThreadRealtimePosix; @@ -363,25 +372,33 @@ { return; } - AppInfo &SetName(const mpt::ustring &name) { Name = name; return *this; } + AppInfo &SetName(const mpt::ustring &name) + { + Name = name; + return *this; + } mpt::ustring GetName() const { return Name; } #if MPT_OS_WINDOWS - AppInfo &SetHWND(HWND hwnd) { UIHandle = reinterpret_cast(hwnd); return *this; } + AppInfo &SetHWND(HWND hwnd) + { + UIHandle = reinterpret_cast(hwnd); + return *this; + } HWND GetHWND() const { return reinterpret_cast(UIHandle); } -#endif // MPT_OS_WINDOWS +#endif // MPT_OS_WINDOWS }; struct Settings { - double Latency; // seconds - double UpdateInterval; // seconds + double Latency; // seconds + double UpdateInterval; // seconds uint32 Samplerate; SoundDevice::ChannelMapping Channels; uint8 InputChannels; SampleFormat sampleFormat; - bool ExclusiveMode; // Use hardware buffers directly - bool BoostThreadPriority; // Boost thread priority for glitch-free audio rendering + bool ExclusiveMode; // Use hardware buffers directly + bool BoostThreadPriority; // Boost thread priority for glitch-free audio rendering bool KeepDeviceRunning; bool UseHardwareTiming; int DitherType; @@ -402,30 +419,29 @@ { return; } - bool operator == (const SoundDevice::Settings &cmp) const + bool operator==(const SoundDevice::Settings &cmp) const { return true - && mpt::saturate_round(Latency * 1000000000.0) == mpt::saturate_round(cmp.Latency * 1000000000.0) // compare in nanoseconds - && mpt::saturate_round(UpdateInterval * 1000000000.0) == mpt::saturate_round(cmp.UpdateInterval * 1000000000.0) // compare in nanoseconds - && Samplerate == cmp.Samplerate - && Channels == cmp.Channels - && InputChannels == cmp.InputChannels - && sampleFormat == cmp.sampleFormat - && ExclusiveMode == cmp.ExclusiveMode - && BoostThreadPriority == cmp.BoostThreadPriority - && KeepDeviceRunning == cmp.KeepDeviceRunning - && UseHardwareTiming == cmp.UseHardwareTiming - && DitherType == cmp.DitherType - && InputSourceID == cmp.InputSourceID - ; + && mpt::saturate_round(Latency * 1000000000.0) == mpt::saturate_round(cmp.Latency * 1000000000.0) // compare in nanoseconds + && mpt::saturate_round(UpdateInterval * 1000000000.0) == mpt::saturate_round(cmp.UpdateInterval * 1000000000.0) // compare in nanoseconds + && Samplerate == cmp.Samplerate + && Channels == cmp.Channels + && InputChannels == cmp.InputChannels + && sampleFormat == cmp.sampleFormat + && ExclusiveMode == cmp.ExclusiveMode + && BoostThreadPriority == cmp.BoostThreadPriority + && KeepDeviceRunning == cmp.KeepDeviceRunning + && UseHardwareTiming == cmp.UseHardwareTiming + && DitherType == cmp.DitherType + && InputSourceID == cmp.InputSourceID; } - bool operator != (const SoundDevice::Settings &cmp) const + bool operator!=(const SoundDevice::Settings &cmp) const { return !(*this == cmp); } std::size_t GetBytesPerFrame() const { - return (sampleFormat.GetBitsPerSample()/8) * Channels; + return (sampleFormat.GetBitsPerSample() / 8) * Channels; } std::size_t GetBytesPerSecond() const { @@ -491,10 +507,10 @@ , CanDriverPanel(false) , HasInternalDither(false) , ExclusiveModeDescription(U_("Use device exclusively")) - , LatencyMin(0.002) // 2ms - , LatencyMax(0.5) // 500ms - , UpdateIntervalMin(0.001) // 1ms - , UpdateIntervalMax(0.2) // 200ms + , LatencyMin(0.002) // 2ms + , LatencyMax(0.5) // 500ms + , UpdateIntervalMin(0.001) // 1ms + , UpdateIntervalMax(0.2) // 200ms { return; } @@ -506,10 +522,10 @@ uint32 currentSampleRate = 0; std::vector supportedSampleRates; std::vector supportedExclusiveSampleRates; - std::vector supportedSampleFormats = DefaultSampleFormats>(); + std::vector supportedSampleFormats = DefaultSampleFormats>(); std::vector supportedExclusiveModeSampleFormats = DefaultSampleFormats>(); std::vector channelNames; - std::vector > inputSourceNames; + std::vector> inputSourceNames; }; @@ -526,8 +542,8 @@ struct BufferAttributes { - double Latency; // seconds - double UpdateInterval; // seconds + double Latency; // seconds + double UpdateInterval; // seconds int NumBuffers; BufferAttributes() : Latency(0.0) @@ -544,9 +560,9 @@ enum RequestFlags : uint32 { - RequestFlagClose = 1<<0, - RequestFlagReset = 1<<1, - RequestFlagRestart = 1<<2, + RequestFlagClose = 1 << 0, + RequestFlagReset = 1 << 1, + RequestFlagRestart = 1 << 2, }; MPT_DECLARE_ENUM(RequestFlags) @@ -569,51 +585,48 @@ { protected: + IBase() {} - IBase() { } - public: + virtual ~IBase() {} - virtual ~IBase() { } - public: - virtual void SetMessageReceiver(SoundDevice::IMessageReceiver *receiver) = 0; - virtual void SetSource(SoundDevice::ISource *source) = 0; + virtual void SetSource(SoundDevice::ISource *source) = 0; virtual SoundDevice::Info GetDeviceInfo() const = 0; - virtual SoundDevice::Caps GetDeviceCaps() const = 0; + virtual SoundDevice::Caps GetDeviceCaps() const = 0; virtual SoundDevice::DynamicCaps GetDeviceDynamicCaps(const std::vector &baseSampleRates) = 0; - virtual bool Init(const SoundDevice::AppInfo &appInfo) = 0; + virtual bool Init(const SoundDevice::AppInfo &appInfo) = 0; virtual bool Open(const SoundDevice::Settings &settings) = 0; - virtual bool Close() = 0; - virtual bool Start() = 0; - virtual void Stop() = 0; + virtual bool Close() = 0; + virtual bool Start() = 0; + virtual void Stop() = 0; virtual FlagSet GetRequestFlags() const = 0; - virtual bool IsInited() const = 0; - virtual bool IsOpen() const = 0; + virtual bool IsInited() const = 0; + virtual bool IsOpen() const = 0; virtual bool IsAvailable() const = 0; - virtual bool IsPlaying() const = 0; + virtual bool IsPlaying() const = 0; - virtual bool IsPlayingSilence() const = 0; + virtual bool IsPlayingSilence() const = 0; virtual void StopAndAvoidPlayingSilence() = 0; - virtual void EndPlayingSilence() = 0; + virtual void EndPlayingSilence() = 0; - virtual bool OnIdle() = 0; // return true if any work has been done + virtual bool OnIdle() = 0; // return true if any work has been done - virtual SoundDevice::Settings GetSettings() const = 0; - virtual SampleFormat GetActualSampleFormat() const = 0; + virtual SoundDevice::Settings GetSettings() const = 0; + virtual SampleFormat GetActualSampleFormat() const = 0; virtual SoundDevice::BufferAttributes GetEffectiveBufferAttributes() const = 0; - virtual SoundDevice::TimeInfo GetTimeInfo() const = 0; + virtual SoundDevice::TimeInfo GetTimeInfo() const = 0; virtual SoundDevice::StreamPosition GetStreamPosition() const = 0; // Debugging aids in case of a crash - virtual bool DebugIsFragileDevice() const = 0; + virtual bool DebugIsFragileDevice() const = 0; virtual bool DebugInRealtimeCallback() const = 0; // Informational only, do not use for timing. @@ -621,7 +634,6 @@ virtual SoundDevice::Statistics GetStatistics() const = 0; virtual bool OpenDriverSettings() = 0; - }; @@ -628,10 +640,10 @@ namespace Legacy { typedef uint16 ID; -static constexpr SoundDevice::Legacy::ID MaskType = 0xff00; -static constexpr SoundDevice::Legacy::ID MaskIndex = 0x00ff; -static constexpr int ShiftType = 8; -static constexpr int ShiftIndex = 0; +static constexpr SoundDevice::Legacy::ID MaskType = 0xff00; +static constexpr SoundDevice::Legacy::ID MaskIndex = 0x00ff; +static constexpr int ShiftType = 8; +static constexpr int ShiftIndex = 0; static constexpr SoundDevice::Legacy::ID TypeWAVEOUT = 0; static constexpr SoundDevice::Legacy::ID TypeDSOUND = 1; static constexpr SoundDevice::Legacy::ID TypeASIO = 2; @@ -639,10 +651,10 @@ static constexpr SoundDevice::Legacy::ID TypePORTAUDIO_WDMKS = 4; static constexpr SoundDevice::Legacy::ID TypePORTAUDIO_WMME = 5; static constexpr SoundDevice::Legacy::ID TypePORTAUDIO_DS = 6; -} +} // namespace Legacy -} // namespace SoundDevice +} // namespace SoundDevice OPENMPT_NAMESPACE_END Index: sounddev/SoundDeviceASIO.cpp =================================================================== --- sounddev/SoundDeviceASIO.cpp (revision 14154) +++ sounddev/SoundDeviceASIO.cpp (working copy) @@ -23,7 +23,7 @@ #if !defined(MPT_BUILD_WINESUPPORT) #include "../mptrack/ExceptionHandler.h" -#endif // !MPT_BUILD_WINESUPPORT +#endif // !MPT_BUILD_WINESUPPORT #include #include @@ -34,13 +34,14 @@ #include //#include -#endif // MPT_WITH_ASIO +#endif // MPT_WITH_ASIO OPENMPT_NAMESPACE_BEGIN -namespace SoundDevice { +namespace SoundDevice +{ #ifdef MPT_WITH_ASIO @@ -49,8 +50,8 @@ MPT_REGISTERED_COMPONENT(ComponentASIO, "ASIO") -static constexpr uint64 AppID1 = 0x4f70656e4d50542dull; // "OpenMPT-" -static constexpr uint64 AppID2 = 0x4153494f00000000ull; // "ASIO" +static constexpr uint64 AppID1 = 0x4f70656e4d50542dull; // "OpenMPT-" +static constexpr uint64 AppID2 = 0x4153494f00000000ull; // "ASIO" static constexpr double AsioSampleRateTolerance = 0.05; @@ -95,7 +96,7 @@ }; -static mpt::winstring AsWinstring(const std::basic_string & str) +static mpt::winstring AsWinstring(const std::basic_string &str) { return mpt::winstring(str.data(), str.length()); } @@ -106,30 +107,33 @@ MPT_TRACE_SCOPE(); std::vector devices; std::vector drivers = ASIO::Windows::EnumerateDrivers(); - for(const auto & driver : drivers) + for(const auto &driver : drivers) { SoundDevice::Info info; - info.type = TypeASIO; - info.internalID = mpt::ToUnicode(Util::CLSIDToString(driver.Clsid)); - info.apiName = U_("ASIO"); - info.name = mpt::ToUnicode(AsWinstring(driver.DisplayName())); + info.type = TypeASIO; + info.internalID = mpt::ToUnicode(Util::CLSIDToString(driver.Clsid)); + info.apiName = U_("ASIO"); + info.name = mpt::ToUnicode(AsWinstring(driver.DisplayName())); info.useNameAsIdentifier = false; - info.default_ = Info::Default::None; - info.flags = { - sysInfo.SystemClass == mpt::OS::Class::Windows ? sysInfo.IsWindowsOriginal() ? Info::Usability::Usable : Info::Usability::Experimental : Info::Usability::NotAvailable, - Info::Level::Primary, - Info::Compatible::No, - sysInfo.SystemClass == mpt::OS::Class::Windows && sysInfo.IsWindowsOriginal() ? Info::Api::Native : Info::Api::Emulated, - Info::Io::FullDuplex, - Info::Mixing::Hardware, - Info::Implementor::OpenMPT - }; - info.extraData[U_("Key")] = mpt::ToUnicode(AsWinstring(driver.Key));; - info.extraData[U_("Id")] = mpt::ToUnicode(AsWinstring(driver.Id)); + info.default_ = Info::Default::None; + info.flags = { + sysInfo.SystemClass == mpt::OS::Class::Windows ? sysInfo.IsWindowsOriginal() ? Info::Usability::Usable : Info::Usability::Experimental : Info::Usability::NotAvailable, + Info::Level::Primary, + Info::Compatible::No, + sysInfo.SystemClass == mpt::OS::Class::Windows && sysInfo.IsWindowsOriginal() ? Info::Api::Native : Info::Api::Emulated, + Info::Io::FullDuplex, + Info::Mixing::Hardware, + Info::Implementor::OpenMPT}; + info.extraData[U_("Key")] = mpt::ToUnicode(AsWinstring(driver.Key)); + ; + info.extraData[U_("Id")] = mpt::ToUnicode(AsWinstring(driver.Id)); info.extraData[U_("CLSID")] = mpt::ToUnicode(Util::CLSIDToString(driver.Clsid)); - info.extraData[U_("Name")] = mpt::ToUnicode(AsWinstring(driver.Name));; - info.extraData[U_("Description")] = mpt::ToUnicode(AsWinstring(driver.Description));; - info.extraData[U_("DisplayName")] = mpt::ToUnicode(AsWinstring(driver.DisplayName()));; + info.extraData[U_("Name")] = mpt::ToUnicode(AsWinstring(driver.Name)); + ; + info.extraData[U_("Description")] = mpt::ToUnicode(AsWinstring(driver.Description)); + ; + info.extraData[U_("DisplayName")] = mpt::ToUnicode(AsWinstring(driver.DisplayName())); + ; MPT_LOG(LogDebug, "sounddev", MPT_UFORMAT("ASIO: Found driver:")()); MPT_LOG(LogDebug, "sounddev", MPT_UFORMAT("ASIO: Key = '{}'")(info.extraData[U_("Key")])); MPT_LOG(LogDebug, "sounddev", MPT_UFORMAT("ASIO: Id = '{}'")(info.extraData[U_("Id")])); @@ -152,9 +156,9 @@ , m_DebugRealtimeThreadID(0) { MPT_TRACE_SCOPE(); - #if !defined(MPT_BUILD_WINESUPPORT) - m_Ectx.description = MPT_UFORMAT("ASIO Driver: {}")(GetDeviceInternalID()); - #endif // !MPT_BUILD_WINESUPPORT +#if !defined(MPT_BUILD_WINESUPPORT) + m_Ectx.description = MPT_UFORMAT("ASIO Driver: {}")(GetDeviceInternalID()); +#endif // !MPT_BUILD_WINESUPPORT InitMembers(); } @@ -163,9 +167,9 @@ { MPT_TRACE_SCOPE(); m_DeferredBufferSwitchDispatcher = nullptr; - m_Driver = nullptr; + m_Driver = nullptr; - m_BufferLatency = 0.0; + m_BufferLatency = 0.0; m_nAsioBufferLen = 0; m_BufferInfo.clear(); m_BuffersCreated = false; @@ -182,17 +186,16 @@ m_SampleInputBufferInt32.clear(); m_CanOutputReady = false; - m_DeviceRunning = false; + m_DeviceRunning = false; m_TotalFramesWritten = 0; m_DeferredProcessing = false; - m_BufferIndex = 0; - m_RenderSilence = false; - m_RenderingSilence = false; + m_BufferIndex = 0; + m_RenderSilence = false; + m_RenderingSilence = false; m_AsioRequest.store(0); m_DebugRealtimeThreadID.store(0); - } @@ -199,7 +202,7 @@ bool CASIODevice::HandleRequests() { MPT_TRACE_SCOPE(); - bool result = false; + bool result = false; uint32 flags = m_AsioRequest.exchange(0); if(flags & AsioRequest::LatenciesChanged) { @@ -225,14 +228,7 @@ InitMembers(); - MPT_LOG(LogDebug, "sounddev", MPT_UFORMAT("ASIO: Open('{}'): {}-bit, ({},{}) channels, {}Hz, hw-timing={}") - ( GetDeviceInternalID() - , m_Settings.sampleFormat.GetBitsPerSample() - , m_Settings.InputChannels - , m_Settings.Channels - , m_Settings.Samplerate - , m_Settings.UseHardwareTiming - )); + MPT_LOG(LogDebug, "sounddev", MPT_UFORMAT("ASIO: Open('{}'): {}-bit, ({},{}) channels, {}Hz, hw-timing={}")(GetDeviceInternalID(), m_Settings.sampleFormat.GetBitsPerSample(), m_Settings.InputChannels, m_Settings.Channels, m_Settings.Samplerate, m_Settings.UseHardwareTiming)); SoundDevice::ChannelMapping inputChannelMapping = SoundDevice::ChannelMapping::BaseChannel(m_Settings.InputChannels, m_Settings.InputSourceID); @@ -274,11 +270,10 @@ AsioDriver()->setSampleRate(m_Settings.Samplerate); ASIO::BufferSizes bufferSizes = AsioDriver()->getBufferSizes(); - MPT_LOG(LogDebug, "sounddev", MPT_UFORMAT("ASIO: getBufferSize() => minSize={} maxSize={} preferredSize={} granularity={}")( - bufferSizes.Min, bufferSizes.Max, bufferSizes.Preferred, bufferSizes.Granularity)); + MPT_LOG(LogDebug, "sounddev", MPT_UFORMAT("ASIO: getBufferSize() => minSize={} maxSize={} preferredSize={} granularity={}")(bufferSizes.Min, bufferSizes.Max, bufferSizes.Preferred, bufferSizes.Granularity)); m_nAsioBufferLen = mpt::saturate_round(m_Settings.Latency * m_Settings.Samplerate / 2.0); if(bufferSizes.Min <= 0 || bufferSizes.Max <= 0 || bufferSizes.Min > bufferSizes.Max) - { // limits make no sense + { // limits make no sense if(bufferSizes.Preferred > 0) { m_nAsioBufferLen = bufferSizes.Preferred; @@ -287,10 +282,10 @@ // just leave the user value, perhaps it works } } else if(bufferSizes.Granularity < -1) - { // bufferSizes.Granularity value not allowed, just clamp value + { // bufferSizes.Granularity value not allowed, just clamp value m_nAsioBufferLen = std::clamp(m_nAsioBufferLen, bufferSizes.Min, bufferSizes.Max); } else if(bufferSizes.Granularity == -1 && (mpt::popcount(static_cast(bufferSizes.Min)) != 1 || mpt::popcount(static_cast(bufferSizes.Max)) != 1)) - { // bufferSizes.Granularity tells us we need power-of-2 sizes, but min or max sizes are no power-of-2 + { // bufferSizes.Granularity tells us we need power-of-2 sizes, but min or max sizes are no power-of-2 m_nAsioBufferLen = std::clamp(m_nAsioBufferLen, bufferSizes.Min, bufferSizes.Max); // just start at 1 and find a matching power-of-2 in range const ASIO::Long bufTarget = m_nAsioBufferLen; @@ -303,7 +298,7 @@ } // if no power-of-2 in range is found, just leave the clamped value alone, perhaps it works } else if(bufferSizes.Granularity == -1) - { // sane values, power-of-2 size required between min and max + { // sane values, power-of-2 size required between min and max m_nAsioBufferLen = std::clamp(m_nAsioBufferLen, bufferSizes.Min, bufferSizes.Max); // get the largest allowed buffer size that is smaller or equal to the target size const ASIO::Long bufTarget = m_nAsioBufferLen; @@ -312,7 +307,7 @@ m_nAsioBufferLen = bufSize; } } else if(bufferSizes.Granularity > 0) - { // buffer size in bufferSizes.Granularity steps from min to max allowed + { // buffer size in bufferSizes.Granularity steps from min to max allowed m_nAsioBufferLen = std::clamp(m_nAsioBufferLen, bufferSizes.Min, bufferSizes.Max); // get the largest allowed buffer size that is smaller or equal to the target size const ASIO::Long bufTarget = m_nAsioBufferLen; @@ -321,22 +316,22 @@ m_nAsioBufferLen = bufSize; } } else if(bufferSizes.Granularity == 0) - { // no bufferSizes.Granularity given, we should use bufferSizes.Preferred if possible + { // no bufferSizes.Granularity given, we should use bufferSizes.Preferred if possible if(bufferSizes.Preferred > 0) { m_nAsioBufferLen = bufferSizes.Preferred; } else if(m_nAsioBufferLen >= bufferSizes.Max) - { // a large latency was requested, use bufferSizes.Max + { // a large latency was requested, use bufferSizes.Max m_nAsioBufferLen = bufferSizes.Max; } else - { // use bufferSizes.Min otherwise + { // use bufferSizes.Min otherwise m_nAsioBufferLen = bufferSizes.Min; } } else - { // should not happen + { // should not happen MPT_ASSERT_NOTREACHED(); } - + m_BufferInfo.resize(m_Settings.GetTotalChannels()); for(uint32 channel = 0; channel < m_Settings.GetTotalChannels(); ++channel) { @@ -343,11 +338,11 @@ m_BufferInfo[channel] = ASIO::BufferInfo(); if(channel < m_Settings.InputChannels) { - m_BufferInfo[channel].isInput = true; + m_BufferInfo[channel].isInput = true; m_BufferInfo[channel].channelNum = inputChannelMapping.ToDevice(channel); } else { - m_BufferInfo[channel].isInput = false; + m_BufferInfo[channel].isInput = false; m_BufferInfo[channel].channelNum = m_Settings.Channels.ToDevice(channel - m_Settings.InputChannels); } } @@ -373,28 +368,21 @@ m_ChannelInfo[channel] = AsioDriver()->getChannelInfo(m_Settings.Channels.ToDevice(channel - m_Settings.InputChannels), false); } MPT_ASSERT(m_ChannelInfo[channel].isActive); - MPT_LOG(LogDebug, "sounddev", MPT_UFORMAT("ASIO: getChannelInfo(isInput={} channel={}) => isActive={} channelGroup={} type={} name='{}'") - ( (channel < m_Settings.InputChannels) - , m_Settings.Channels.ToDevice(channel) - , value_cast(m_ChannelInfo[channel].isActive) - , m_ChannelInfo[channel].channelGroup - , value_cast(m_ChannelInfo[channel].type) - , mpt::ToUnicode(mpt::Charset::Locale, m_ChannelInfo[channel].name) - )); + MPT_LOG(LogDebug, "sounddev", MPT_UFORMAT("ASIO: getChannelInfo(isInput={} channel={}) => isActive={} channelGroup={} type={} name='{}'")((channel < m_Settings.InputChannels), m_Settings.Channels.ToDevice(channel), value_cast(m_ChannelInfo[channel].isActive), m_ChannelInfo[channel].channelGroup, value_cast(m_ChannelInfo[channel].type), mpt::ToUnicode(mpt::Charset::Locale, m_ChannelInfo[channel].name))); } - bool allChannelsAreInt = true; + bool allChannelsAreInt = true; bool allChannelsAreInt16ValidBits = true; - bool allChannelsAreNativeInt24 = true; - bool allChannelsAreFloat32 = true; + bool allChannelsAreNativeInt24 = true; + bool allChannelsAreFloat32 = true; for(std::size_t channel = 0; channel < m_Settings.GetTotalChannels(); ++channel) { ASIO::Sample::Traits sampleTraits = ASIO::Sample::Traits(m_ChannelInfo[channel].type); - bool isFloat = sampleTraits.is_float; - bool isFloat32 = sampleTraits.is_float && sampleTraits.valid_bits == 32; - bool isInt16ValidBits = !sampleTraits.is_float && sampleTraits.valid_bits == 16; - bool isInt24 = !sampleTraits.is_float && sampleTraits.size_bytes == 3 && sampleTraits.valid_bits == 24; - bool isNative = (mpt::endian_is_little() && !sampleTraits.is_be) || (mpt::endian_is_big() && sampleTraits.is_be); + bool isFloat = sampleTraits.is_float; + bool isFloat32 = sampleTraits.is_float && sampleTraits.valid_bits == 32; + bool isInt16ValidBits = !sampleTraits.is_float && sampleTraits.valid_bits == 16; + bool isInt24 = !sampleTraits.is_float && sampleTraits.size_bytes == 3 && sampleTraits.valid_bits == 24; + bool isNative = (mpt::endian_is_little() && !sampleTraits.is_be) || (mpt::endian_is_big() && sampleTraits.is_be); if(isFloat) { allChannelsAreInt = false; @@ -445,7 +433,8 @@ ASIO::Sample::ClearBufferASIO(m_BufferInfo[channel].buffers[1], m_ChannelInfo[channel].type, m_nAsioBufferLen); } - m_CanOutputReady = AsioDriver()->canOutputReady();; + m_CanOutputReady = AsioDriver()->canOutputReady(); + ; m_StreamPositionOffset = m_nAsioBufferLen; @@ -478,7 +467,7 @@ } if(latencies.Output >= m_nAsioBufferLen) { - m_BufferLatency = static_cast(latencies.Output + m_nAsioBufferLen) / static_cast(m_Settings.Samplerate); // ASIO and OpenMPT semantics of 'latency' differ by one chunk/buffer + m_BufferLatency = static_cast(latencies.Output + m_nAsioBufferLen) / static_cast(m_Settings.Samplerate); // ASIO and OpenMPT semantics of 'latency' differ by one chunk/buffer } else { // pointless value returned from asio driver, use a sane estimate @@ -663,7 +652,7 @@ } m_BufferInfo.clear(); m_nAsioBufferLen = 0; - m_BufferLatency = 0.0; + m_BufferLatency = 0.0; CloseDriver(); @@ -683,10 +672,10 @@ { if(GetAppInfo().AllowDeferredProcessing) { - m_DeferredBufferSwitchDispatcher = ASIO::Windows::CreateBufferSwitchDispatcher([=](ASIO::BufferIndex bufferIndex) { this->RealtimeBufferSwitchImpl(bufferIndex); } ); + m_DeferredBufferSwitchDispatcher = ASIO::Windows::CreateBufferSwitchDispatcher([=](ASIO::BufferIndex bufferIndex) { this->RealtimeBufferSwitchImpl(bufferIndex); }); } { - CrashContextGuard guard{ &m_Ectx }; + CrashContextGuard guard{&m_Ectx}; if(GetAppInfo().MaskDriverCrashes) { m_Driver = std::make_unique(std::make_unique(clsid, GetAppInfo().GetHWND())); @@ -705,8 +694,8 @@ std::string driverErrorMessage; try { - driverName = AsioDriver()->getDriverName(); - driverVersion = AsioDriver()->getDriverVersion(); + driverName = AsioDriver()->getDriverName(); + driverVersion = AsioDriver()->getDriverVersion(); driverErrorMessage = AsioDriver()->getErrorMessage(); } catch(...) { @@ -728,7 +717,7 @@ try { { - CrashContextGuard guard{ &m_Ectx }; + CrashContextGuard guard{&m_Ectx}; m_Driver = nullptr; } m_DeferredBufferSwitchDispatcher = nullptr; @@ -749,14 +738,14 @@ void CASIODevice::FillAsioBuffer(bool useSource) { MPT_TRACE_SCOPE(); - const bool rendersilence = !useSource; - const std::size_t countChunk = m_nAsioBufferLen; - const std::size_t inputChannels = m_Settings.InputChannels; + const bool rendersilence = !useSource; + const std::size_t countChunk = m_nAsioBufferLen; + const std::size_t inputChannels = m_Settings.InputChannels; const std::size_t outputChannels = m_Settings.Channels; for(std::size_t inputChannel = 0; inputChannel < inputChannels; ++inputChannel) { - std::size_t channel = inputChannel; - const void *src = m_BufferInfo[channel].buffers[m_BufferIndex]; + std::size_t channel = inputChannel; + const void *src = m_BufferInfo[channel].buffers[m_BufferIndex]; ASIO::SampleType sampleType = m_ChannelInfo[channel].type; if(m_Settings.sampleFormat == SampleFormatFloat64) { @@ -854,8 +843,8 @@ } for(std::size_t outputChannel = 0; outputChannel < outputChannels; ++outputChannel) { - std::size_t channel = outputChannel + m_Settings.InputChannels; - void *dst = m_BufferInfo[channel].buffers[m_BufferIndex]; + std::size_t channel = outputChannel + m_Settings.InputChannels; + void *dst = m_BufferInfo[channel].buffers[m_BufferIndex]; ASIO::SampleType sampleType = m_ChannelInfo[channel].type; if(m_Settings.sampleFormat == SampleFormatFloat64) { @@ -911,7 +900,7 @@ { try { - AsioDriver()->outputReady(); // do not handle errors, there is nothing we could do about them + AsioDriver()->outputReady(); // do not handle errors, there is nothing we could do about them } catch(...) { ExceptionHandler(__func__); @@ -934,18 +923,19 @@ SoundDevice::BufferAttributes CASIODevice::InternalGetEffectiveBufferAttributes() const { SoundDevice::BufferAttributes bufferAttributes; - bufferAttributes.Latency = m_BufferLatency; + bufferAttributes.Latency = m_BufferLatency; bufferAttributes.UpdateInterval = static_cast(m_nAsioBufferLen) / static_cast(m_Settings.Samplerate); - bufferAttributes.NumBuffers = 2; + bufferAttributes.NumBuffers = 2; return bufferAttributes; } -namespace { +namespace +{ struct DebugRealtimeThreadIdGuard { - std::atomic & ThreadID; - DebugRealtimeThreadIdGuard(std::atomic & ThreadID) + std::atomic &ThreadID; + DebugRealtimeThreadIdGuard(std::atomic &ThreadID) : ThreadID(ThreadID) { ThreadID.store(GetCurrentThreadId()); @@ -955,7 +945,7 @@ ThreadID.store(0); } }; -} +} // namespace void CASIODevice::RealtimeSampleRateDidChange(ASIO::SampleRate sRate) noexcept @@ -1006,19 +996,19 @@ { speed *= asioTime.timeInfo.sampleRate / m_Settings.Samplerate; } - timeInfo.SyncPointStreamFrames = asioTime.timeInfo.samplePosition - m_StreamPositionOffset; + timeInfo.SyncPointStreamFrames = asioTime.timeInfo.samplePosition - m_StreamPositionOffset; timeInfo.SyncPointSystemTimestamp = asioTime.timeInfo.systemTime; - timeInfo.Speed = speed; + timeInfo.Speed = speed; } else - { // spec violation or nothing provided at all, better to estimate this stuff ourselves - const uint64 asioNow = SourceLockedGetReferenceClockNowNanoseconds(); - timeInfo.SyncPointStreamFrames = m_TotalFramesWritten + m_nAsioBufferLen - m_StreamPositionOffset; + { // spec violation or nothing provided at all, better to estimate this stuff ourselves + const uint64 asioNow = SourceLockedGetReferenceClockNowNanoseconds(); + timeInfo.SyncPointStreamFrames = m_TotalFramesWritten + m_nAsioBufferLen - m_StreamPositionOffset; timeInfo.SyncPointSystemTimestamp = asioNow + mpt::saturate_round(m_BufferLatency * 1000.0 * 1000.0 * 1000.0); - timeInfo.Speed = 1.0; + timeInfo.Speed = 1.0; } timeInfo.RenderStreamPositionBefore = StreamPositionFromFrames(m_TotalFramesWritten - m_StreamPositionOffset); - timeInfo.RenderStreamPositionAfter = StreamPositionFromFrames(m_TotalFramesWritten - m_StreamPositionOffset + m_nAsioBufferLen); - timeInfo.Latency = GetEffectiveBufferAttributes().Latency; + timeInfo.RenderStreamPositionAfter = StreamPositionFromFrames(m_TotalFramesWritten - m_StreamPositionOffset + m_nAsioBufferLen); + timeInfo.Latency = GetEffectiveBufferAttributes().Latency; SetTimeInfo(timeInfo); } } @@ -1041,7 +1031,7 @@ { MPT_TRACE_SCOPE(); DebugRealtimeThreadIdGuard debugThreadIdGuard(m_DebugRealtimeThreadID); - m_BufferIndex = bufferIndex; + m_BufferIndex = bufferIndex; bool rendersilence = m_RenderSilence; m_RenderingSilence = rendersilence; if(rendersilence) @@ -1103,11 +1093,11 @@ { MPT_TRACE_SCOPE(); SoundDevice::Statistics result; - result.InstantaneousLatency = m_BufferLatency; - result.LastUpdateInterval = static_cast(m_nAsioBufferLen) / static_cast(m_Settings.Samplerate); - result.text = mpt::ustring(); - const AsioFeatures unsupported = AsioFeature::Overload | AsioFeature::BufferSizeChange | AsioFeature::SampleRateChange; - AsioFeatures usedFeatures = m_UsedFeatures.fetch_or(0); + result.InstantaneousLatency = m_BufferLatency; + result.LastUpdateInterval = static_cast(m_nAsioBufferLen) / static_cast(m_Settings.Samplerate); + result.text = mpt::ustring(); + const AsioFeatures unsupported = AsioFeature::Overload | AsioFeature::BufferSizeChange | AsioFeature::SampleRateChange; + AsioFeatures usedFeatures = m_UsedFeatures.fetch_or(0); AsioFeatures unsupportedFeatues = usedFeatures & unsupported; if(unsupportedFeatues) { @@ -1154,16 +1144,11 @@ m_AsioRequest.fetch_or(AsioRequest::LatenciesChanged); } -ASIO::Long CASIODevice::MessageMMCCommand(ASIO::Long value, const void * message, const ASIO::Double * opt) noexcept +ASIO::Long CASIODevice::MessageMMCCommand(ASIO::Long value, const void *message, const ASIO::Double *opt) noexcept { MPT_TRACE_SCOPE(); ASIO::Long result = 0; - MPT_LOG(LogDebug, "sounddev", MPT_UFORMAT("ASIO: MMCCommand(value={}, message={}, opt={}) => result={}") - ( value - , reinterpret_cast(message) - , opt ? mpt::ufmt::val(*opt) : U_("NULL") - , result - )); + MPT_LOG(LogDebug, "sounddev", MPT_UFORMAT("ASIO: MMCCommand(value={}, message={}, opt={}) => result={}")(value, reinterpret_cast(message), opt ? mpt::ufmt::val(*opt) : U_("NULL"), result)); return result; } @@ -1173,32 +1158,26 @@ m_UsedFeatures.fetch_or(AsioFeature::Overload); } -ASIO::Long CASIODevice::MessageUnknown(ASIO::MessageSelector selector, ASIO::Long value, const void * message, const ASIO::Double * opt) noexcept +ASIO::Long CASIODevice::MessageUnknown(ASIO::MessageSelector selector, ASIO::Long value, const void *message, const ASIO::Double *opt) noexcept { MPT_TRACE_SCOPE(); ASIO::Long result = 0; - MPT_LOG(LogDebug, "sounddev", MPT_UFORMAT("ASIO: AsioMessage(selector={}, value={}, message={}, opt={}) => result={}") - ( value_cast(selector) - , value - , reinterpret_cast(message) - , opt ? mpt::ufmt::val(*opt) : U_("NULL") - , result - )); + MPT_LOG(LogDebug, "sounddev", MPT_UFORMAT("ASIO: AsioMessage(selector={}, value={}, message={}, opt={}) => result={}")(value_cast(selector), value, reinterpret_cast(message), opt ? mpt::ufmt::val(*opt) : U_("NULL"), result)); return result; } -void CASIODevice::ExceptionHandler(const char * func) +void CASIODevice::ExceptionHandler(const char *func) { MPT_TRACE_SCOPE(); try { - throw; // rethrow + throw; // rethrow } catch(const ASIO::Windows::SEH::DriverCrash &e) { - #if !defined(MPT_BUILD_WINESUPPORT) - ExceptionHandler::TaintProcess(ExceptionHandler::TaintReason::Driver); - #endif // !MPT_BUILD_WINESUPPORT +#if !defined(MPT_BUILD_WINESUPPORT) + ExceptionHandler::TaintProcess(ExceptionHandler::TaintReason::Driver); +#endif // !MPT_BUILD_WINESUPPORT MPT_LOG(LogError, "sounddev", MPT_UFORMAT("ASIO: {}: Driver Crash: {}!")(mpt::ToUnicode(mpt::CharsetSource, func), mpt::ToUnicode(mpt::CharsetSource, std::string(e.func())))); SendDeviceMessage(LogError, MPT_UFORMAT("ASIO Driver Crash: {}")(mpt::ToUnicode(mpt::CharsetSource, std::string(e.func())))); } catch(const std::bad_alloc &) @@ -1228,22 +1207,22 @@ MPT_TRACE_SCOPE(); SoundDevice::Caps caps; - caps.Available = true; - caps.CanUpdateInterval = false; - caps.CanSampleFormat = false; - caps.CanExclusiveMode = false; + caps.Available = true; + caps.CanUpdateInterval = false; + caps.CanSampleFormat = false; + caps.CanExclusiveMode = false; caps.CanBoostThreadPriority = false; - caps.CanKeepDeviceRunning = true; - caps.CanUseHardwareTiming = true; - caps.CanChannelMapping = true; - caps.CanInput = true; - caps.HasNamedInputSources = true; - caps.CanDriverPanel = true; + caps.CanKeepDeviceRunning = true; + caps.CanUseHardwareTiming = true; + caps.CanChannelMapping = true; + caps.CanInput = true; + caps.HasNamedInputSources = true; + caps.CanDriverPanel = true; - caps.LatencyMin = 0.000001; // 1 us - caps.LatencyMax = 0.5; // 500 ms - caps.UpdateIntervalMin = 0.0; // disabled - caps.UpdateIntervalMax = 0.0; // disabled + caps.LatencyMin = 0.000001; // 1 us + caps.LatencyMax = 0.5; // 500 ms + caps.UpdateIntervalMin = 0.0; // disabled + caps.UpdateIntervalMax = 0.0; // disabled caps.DefaultSettings.sampleFormat = SampleFormatFloat32; @@ -1306,7 +1285,7 @@ try { ASIO::ChannelInfo channelInfo = AsioDriver()->getChannelInfo(i, false); - name = mpt::ToUnicode(mpt::Charset::Locale, channelInfo.name); + name = mpt::ToUnicode(mpt::Charset::Locale, channelInfo.name); } catch(...) { ExceptionHandler(__func__); @@ -1320,7 +1299,7 @@ try { ASIO::ChannelInfo channelInfo = AsioDriver()->getChannelInfo(i, true); - name = mpt::ToUnicode(mpt::Charset::Locale, channelInfo.name); + name = mpt::ToUnicode(mpt::Charset::Locale, channelInfo.name); } catch(...) { ExceptionHandler(__func__); @@ -1358,10 +1337,10 @@ } -#endif // MPT_WITH_ASIO +#endif // MPT_WITH_ASIO -} // namespace SoundDevice +} // namespace SoundDevice OPENMPT_NAMESPACE_END Index: sounddev/SoundDeviceASIO.h =================================================================== --- sounddev/SoundDeviceASIO.h (revision 14154) +++ sounddev/SoundDeviceASIO.h (working copy) @@ -22,17 +22,18 @@ #ifdef MPT_WITH_ASIO #if !defined(MPT_BUILD_WINESUPPORT) #include "../mptrack/ExceptionHandler.h" -#endif // !MPT_BUILD_WINESUPPORT -#endif // MPT_WITH_ASIO +#endif // !MPT_BUILD_WINESUPPORT +#endif // MPT_WITH_ASIO #ifdef MPT_WITH_ASIO #include #include -#endif // MPT_WITH_ASIO +#endif // MPT_WITH_ASIO OPENMPT_NAMESPACE_BEGIN -namespace SoundDevice { +namespace SoundDevice +{ #ifdef MPT_WITH_ASIO @@ -40,8 +41,8 @@ { MPT_DECLARE_COMPONENT_MEMBERS public: - ComponentASIO() { } - virtual ~ComponentASIO() { } + ComponentASIO() {} + virtual ~ComponentASIO() {} bool DoInitialize() override { return true; } }; @@ -64,23 +65,22 @@ friend class TemporaryASIODriverOpener; protected: - std::unique_ptr m_DeferredBufferSwitchDispatcher; std::unique_ptr m_Driver; - #if !defined(MPT_BUILD_WINESUPPORT) - using CrashContext = ExceptionHandler::Context; - using CrashContextGuard = ExceptionHandler::ContextSetter; - #else // MPT_BUILD_WINESUPPORT - using CrashContext = void *; - struct CrashContextGuard +#if !defined(MPT_BUILD_WINESUPPORT) + using CrashContext = ExceptionHandler::Context; + using CrashContextGuard = ExceptionHandler::ContextSetter; +#else // MPT_BUILD_WINESUPPORT + using CrashContext = void *; + struct CrashContextGuard + { + CrashContextGuard(CrashContext *) { - CrashContextGuard(CrashContext *) - { - return; - } - }; - #endif // !MPT_BUILD_WINESUPPORT + return; + } + }; +#endif // !MPT_BUILD_WINESUPPORT CrashContext m_Ectx; class ASIODriverWithContext @@ -88,8 +88,9 @@ private: ASIO::Driver *m_Driver; CrashContextGuard m_Guard; + public: - ASIODriverWithContext(ASIO::Driver *driver, CrashContext * ectx) + ASIODriverWithContext(ASIO::Driver *driver, CrashContext *ectx) : m_Driver(driver) , m_Guard(ectx) { @@ -141,7 +142,7 @@ { enum AsioRequestEnum : AsioRequests { - LatenciesChanged = 1<<0, + LatenciesChanged = 1 << 0, }; }; std::atomic m_AsioRequest; @@ -151,12 +152,12 @@ { enum AsioFeatureEnum : AsioFeatures { - ResetRequest = 1<<0, - ResyncRequest = 1<<1, - BufferSizeChange = 1<<2, - Overload = 1<<3, - SampleRateChange = 1<<4, - DeferredProcess = 1<<5, + ResetRequest = 1 << 0, + ResyncRequest = 1 << 1, + BufferSizeChange = 1 << 2, + Overload = 1 << 3, + SampleRateChange = 1 << 4, + DeferredProcess = 1 << 5, }; }; mutable std::atomic m_UsedFeatures; @@ -164,23 +165,20 @@ mutable std::atomic m_DebugRealtimeThreadID; - void SetRenderSilence(bool silence, bool wait=false); + void SetRenderSilence(bool silence, bool wait = false); public: - CASIODevice(SoundDevice::Info info, SoundDevice::SysInfo sysInfo); ~CASIODevice(); private: - void InitMembers(); - bool HandleRequests(); // return true if any work has been done + bool HandleRequests(); // return true if any work has been done void UpdateLatency(); void InternalStopImpl(bool force); public: - bool InternalOpen(); bool InternalClose(); void InternalFillAudioBuffer(); @@ -191,7 +189,7 @@ bool InternalIsPlayingSilence() const; void InternalStopAndAvoidPlayingSilence(); void InternalEndPlayingSilence(); - + bool OnIdle() { return HandleRequests(); } SoundDevice::Caps InternalGetDeviceCaps(); @@ -205,11 +203,9 @@ SoundDevice::Statistics GetStatistics() const; public: - static std::vector EnumerateDevices(SoundDevice::SysInfo sysInfo); protected: - void OpenDriver(); void CloseDriver(); bool IsDriverOpen() const { return (m_Driver != nullptr); } @@ -219,11 +215,9 @@ SoundDevice::BufferAttributes InternalGetEffectiveBufferAttributes() const; protected: - void FillAsioBuffer(bool useSource = true); private: - // CallbackHandler void MessageResetRequest() noexcept override; @@ -230,10 +224,10 @@ bool MessageBufferSizeChange(ASIO::Long newSize) noexcept override; bool MessageResyncRequest() noexcept override; void MessageLatenciesChanged() noexcept override; - ASIO::Long MessageMMCCommand(ASIO::Long value, const void * message, const ASIO::Double * opt) noexcept override; + ASIO::Long MessageMMCCommand(ASIO::Long value, const void *message, const ASIO::Double *opt) noexcept override; void MessageOverload() noexcept override; - ASIO::Long MessageUnknown(ASIO::MessageSelector selector, ASIO::Long value, const void * message, const ASIO::Double * opt) noexcept override; + ASIO::Long MessageUnknown(ASIO::MessageSelector selector, ASIO::Long value, const void *message, const ASIO::Double *opt) noexcept override; void RealtimeSampleRateDidChange(ASIO::SampleRate sRate) noexcept override; void RealtimeRequestDeferredProcessing(bool value) noexcept override; @@ -243,13 +237,11 @@ void RealtimeBufferSwitchImpl(ASIO::BufferIndex bufferIndex) noexcept; private: - - void ExceptionHandler(const char * func); - + void ExceptionHandler(const char *func); }; -#endif // MPT_WITH_ASIO +#endif // MPT_WITH_ASIO -} // namespace SoundDevice +} // namespace SoundDevice OPENMPT_NAMESPACE_END Index: sounddev/SoundDeviceBase.cpp =================================================================== --- sounddev/SoundDeviceBase.cpp (revision 14154) +++ sounddev/SoundDeviceBase.cpp (working copy) @@ -17,9 +17,10 @@ OPENMPT_NAMESPACE_BEGIN -namespace SoundDevice { - - +namespace SoundDevice +{ + + Base::Base(SoundDevice::Info info, SoundDevice::SysInfo sysInfo) : m_Source(nullptr) , m_MessageReceiver(nullptr) @@ -32,7 +33,7 @@ m_DeviceUnavailableOnOpen = false; - m_IsPlaying = false; + m_IsPlaying = false; m_StreamPositionRenderFrames = 0; m_StreamPositionOutputFrames = 0; @@ -64,7 +65,7 @@ return true; } m_AppInfo = appInfo; - m_Caps = InternalGetDeviceCaps(); + m_Caps = InternalGetDeviceCaps(); return m_Caps.Available; } @@ -79,9 +80,9 @@ m_Settings = settings; if(m_Settings.Latency == 0.0) m_Settings.Latency = m_Caps.DefaultSettings.Latency; if(m_Settings.UpdateInterval == 0.0) m_Settings.UpdateInterval = m_Caps.DefaultSettings.UpdateInterval; - m_Settings.Latency = std::clamp(m_Settings.Latency, m_Caps.LatencyMin, m_Caps.LatencyMax); + m_Settings.Latency = std::clamp(m_Settings.Latency, m_Caps.LatencyMin, m_Caps.LatencyMax); m_Settings.UpdateInterval = std::clamp(m_Settings.UpdateInterval, m_Caps.UpdateIntervalMin, m_Caps.UpdateIntervalMax); - m_Flags = SoundDevice::Flags(); + m_Flags = SoundDevice::Flags(); m_DeviceUnavailableOnOpen = false; m_RequestFlags.store(0); return InternalOpen(); @@ -178,18 +179,18 @@ SoundDevice::TimeInfo timeInfo; if(InternalHasGetStreamPosition()) { - timeInfo.SyncPointStreamFrames = InternalHasGetStreamPosition(); + timeInfo.SyncPointStreamFrames = InternalHasGetStreamPosition(); timeInfo.SyncPointSystemTimestamp = SourceLockedGetReferenceClockNowNanoseconds(); - timeInfo.Speed = 1.0; + timeInfo.Speed = 1.0; } else { - timeInfo.SyncPointStreamFrames = m_StreamPositionRenderFrames + numFrames; + timeInfo.SyncPointStreamFrames = m_StreamPositionRenderFrames + numFrames; timeInfo.SyncPointSystemTimestamp = SourceLockedGetReferenceClockNowNanoseconds() + mpt::saturate_round(GetEffectiveBufferAttributes().Latency * 1000000000.0); - timeInfo.Speed = 1.0; + timeInfo.Speed = 1.0; } timeInfo.RenderStreamPositionBefore = StreamPositionFromFrames(m_StreamPositionRenderFrames); - timeInfo.RenderStreamPositionAfter = StreamPositionFromFrames(m_StreamPositionRenderFrames + numFrames); - timeInfo.Latency = GetEffectiveBufferAttributes().Latency; + timeInfo.RenderStreamPositionAfter = StreamPositionFromFrames(m_StreamPositionRenderFrames + numFrames); + timeInfo.Latency = GetEffectiveBufferAttributes().Latency; SetTimeInfo(timeInfo); } m_StreamPositionRenderFrames += numFrames; @@ -248,7 +249,7 @@ MPT_TRACE_SCOPE(); if(!IsOpen()) { - return false; + return false; } if(!IsPlaying()) { @@ -281,7 +282,7 @@ InternalStop(); m_RequestFlags.fetch_and((~RequestFlagRestart).as_bits()); SourceNotifyPostStop(); - m_IsPlaying = false; + m_IsPlaying = false; m_StreamPositionOutputFrames = 0; m_StreamPositionRenderFrames = 0; } @@ -302,7 +303,7 @@ InternalStopAndAvoidPlayingSilence(); m_RequestFlags.fetch_and((~RequestFlagRestart).as_bits()); SourceNotifyPostStop(); - m_IsPlaying = false; + m_IsPlaying = false; m_StreamPositionOutputFrames = 0; m_StreamPositionRenderFrames = 0; } @@ -336,13 +337,10 @@ frames = InternalGetStreamPositionFrames(); } else if(InternalHasTimeInfo()) { - const uint64 now = SourceGetReferenceClockNowNanoseconds(); + const uint64 now = SourceGetReferenceClockNowNanoseconds(); const SoundDevice::TimeInfo timeInfo = GetTimeInfo(); - frames = mpt::saturate_round( - timeInfo.SyncPointStreamFrames + ( - static_cast(static_cast(now - timeInfo.SyncPointSystemTimestamp)) * timeInfo.Speed * m_Settings.Samplerate * (1.0 / (1000.0 * 1000.0)) - ) - ); + frames = mpt::saturate_round( + timeInfo.SyncPointStreamFrames + (static_cast(static_cast(now - timeInfo.SyncPointSystemTimestamp)) * timeInfo.Speed * m_Settings.Samplerate * (1.0 / (1000.0 * 1000.0)))); } else { frames = m_StreamPositionOutputFrames; @@ -356,13 +354,13 @@ MPT_TRACE_SCOPE(); SoundDevice::Statistics result; result.InstantaneousLatency = m_Settings.Latency; - result.LastUpdateInterval = m_Settings.UpdateInterval; - result.text = mpt::ustring(); + result.LastUpdateInterval = m_Settings.UpdateInterval; + result.text = mpt::ustring(); return result; } -} // namespace SoundDevice +} // namespace SoundDevice OPENMPT_NAMESPACE_END Index: sounddev/SoundDeviceBase.h =================================================================== --- sounddev/SoundDeviceBase.h (revision 14154) +++ sounddev/SoundDeviceBase.h (working copy) @@ -25,7 +25,8 @@ OPENMPT_NAMESPACE_BEGIN -namespace SoundDevice { +namespace SoundDevice +{ class Base @@ -33,11 +34,11 @@ { private: - class SourceLockedGuard { private: ISource &m_Source; + public: SourceLockedGuard(ISource &source) : m_Source(source) @@ -51,7 +52,6 @@ }; private: - SoundDevice::ISource *m_Source; SoundDevice::IMessageReceiver *m_MessageReceiver; @@ -58,11 +58,9 @@ const SoundDevice::Info m_Info; private: - SoundDevice::Caps m_Caps; protected: - SoundDevice::SysInfo m_SysInfo; SoundDevice::AppInfo m_AppInfo; SoundDevice::Settings m_Settings; @@ -70,12 +68,11 @@ bool m_DeviceUnavailableOnOpen; private: - bool m_IsPlaying; SoundDevice::TimeInfo m_TimeInfo; - int64 m_StreamPositionRenderFrames; // only updated or read in audio CALLBACK or when device is stopped. requires no further locking + int64 m_StreamPositionRenderFrames; // only updated or read in audio CALLBACK or when device is stopped. requires no further locking std::atomic m_StreamPositionOutputFrames; @@ -82,12 +79,10 @@ std::atomic m_RequestFlags; public: - SoundDevice::SysInfo GetSysInfo() const { return m_SysInfo; } SoundDevice::AppInfo GetAppInfo() const { return m_AppInfo; } protected: - SoundDevice::Type GetDeviceType() const { return m_Info.type; } mpt::ustring GetDeviceInternalID() const { return m_Info.internalID; } SoundDevice::Identifier GetDeviceIdentifier() const { return m_Info.GetIdentifier(); } @@ -111,7 +106,6 @@ void SendDeviceMessage(LogLevel level, const mpt::ustring &str); protected: - void SetTimeInfo(SoundDevice::TimeInfo timeInfo) { m_TimeInfo = timeInfo; } SoundDevice::StreamPosition StreamPositionFromFrames(int64 frames) const { return SoundDevice::StreamPosition(frames, static_cast(frames) / static_cast(m_Settings.Samplerate)); } @@ -123,9 +117,9 @@ virtual bool InternalIsOpen() const = 0; - virtual bool InternalOpen() = 0; + virtual bool InternalOpen() = 0; virtual bool InternalStart() = 0; - virtual void InternalStop() = 0; + virtual void InternalStop() = 0; virtual bool InternalClose() = 0; virtual bool InternalIsPlayingSilence() const { return false; } @@ -137,11 +131,9 @@ virtual SoundDevice::BufferAttributes InternalGetEffectiveBufferAttributes() const = 0; protected: - Base(SoundDevice::Info info, SoundDevice::SysInfo sysInfo); public: - virtual ~Base(); void SetSource(SoundDevice::ISource *source) { m_Source = source; } @@ -168,7 +160,7 @@ virtual bool IsPlayingSilence() const { return IsOpen() && !IsPlaying() && InternalIsPlayingSilence(); } virtual void StopAndAvoidPlayingSilence(); virtual void EndPlayingSilence(); - + virtual bool OnIdle() { return false; } SoundDevice::Settings GetSettings() const { return m_Settings; } @@ -176,12 +168,12 @@ SoundDevice::BufferFormat GetBufferFormat() const { BufferFormat bufferFormat; - bufferFormat.Samplerate = m_Settings.Samplerate; - bufferFormat.Channels = m_Settings.Channels; - bufferFormat.InputChannels = m_Settings.InputChannels; - bufferFormat.sampleFormat = m_Settings.sampleFormat; + bufferFormat.Samplerate = m_Settings.Samplerate; + bufferFormat.Channels = m_Settings.Channels; + bufferFormat.InputChannels = m_Settings.InputChannels; + bufferFormat.sampleFormat = m_Settings.sampleFormat; bufferFormat.NeedsClippedFloat = m_Flags.NeedsClippedFloat; - bufferFormat.DitherType = m_Settings.DitherType; + bufferFormat.DitherType = m_Settings.DitherType; return bufferFormat; } SoundDevice::BufferAttributes GetEffectiveBufferAttributes() const { return (IsOpen() && IsPlaying()) ? InternalGetEffectiveBufferAttributes() : SoundDevice::BufferAttributes(); } @@ -195,11 +187,10 @@ virtual SoundDevice::Statistics GetStatistics() const; virtual bool OpenDriverSettings() { return false; }; - }; -} // namespace SoundDevice +} // namespace SoundDevice OPENMPT_NAMESPACE_END Index: sounddev/SoundDeviceBuffer.cpp =================================================================== --- sounddev/SoundDeviceBuffer.cpp (revision 14154) +++ sounddev/SoundDeviceBuffer.cpp (working copy) @@ -21,137 +21,124 @@ OPENMPT_NAMESPACE_BEGIN -namespace SoundDevice { +namespace SoundDevice +{ template -static void BufferReadTemplateFixed(Tbuffer & dst, const void * src, std::size_t srcTotal, std::size_t srcPos, std::size_t numFrames, std::size_t numChannels, SampleFormat sampleFormat) +static void BufferReadTemplateFixed(Tbuffer &dst, const void *src, std::size_t srcTotal, std::size_t srcPos, std::size_t numFrames, std::size_t numChannels, SampleFormat sampleFormat) { switch(sampleFormat) { - case SampleFormatUnsigned8: - ConvertBufferToBufferMixFixed(dst, advance_audio_buffer(audio_buffer_interleaved(static_cast(src), numChannels, srcTotal), srcPos), numChannels, numFrames); - break; - case SampleFormatInt8: - ConvertBufferToBufferMixFixed(dst, advance_audio_buffer(audio_buffer_interleaved(static_cast(src), numChannels, srcTotal), srcPos), numChannels, numFrames); - break; - case SampleFormatInt16: - ConvertBufferToBufferMixFixed(dst, advance_audio_buffer(audio_buffer_interleaved(static_cast(src), numChannels, srcTotal), srcPos), numChannels, numFrames); - break; - case SampleFormatInt24: - ConvertBufferToBufferMixFixed(dst, advance_audio_buffer(audio_buffer_interleaved(static_cast(src), numChannels, srcTotal), srcPos), numChannels, numFrames); - break; - case SampleFormatInt32: - ConvertBufferToBufferMixFixed(dst, advance_audio_buffer(audio_buffer_interleaved(static_cast(src), numChannels, srcTotal), srcPos), numChannels, numFrames); - break; - case SampleFormatFloat32: - ConvertBufferToBufferMixFixed(dst, advance_audio_buffer(audio_buffer_interleaved(static_cast(src), numChannels, srcTotal), srcPos), numChannels, numFrames); - break; - case SampleFormatFloat64: - ConvertBufferToBufferMixFixed(dst, advance_audio_buffer(audio_buffer_interleaved(static_cast(src), numChannels, srcTotal), srcPos), numChannels, numFrames); - break; - case SampleFormatInvalid: - // nothing - break; + case SampleFormatUnsigned8: + ConvertBufferToBufferMixFixed(dst, advance_audio_buffer(audio_buffer_interleaved(static_cast(src), numChannels, srcTotal), srcPos), numChannels, numFrames); + break; + case SampleFormatInt8: + ConvertBufferToBufferMixFixed(dst, advance_audio_buffer(audio_buffer_interleaved(static_cast(src), numChannels, srcTotal), srcPos), numChannels, numFrames); + break; + case SampleFormatInt16: + ConvertBufferToBufferMixFixed(dst, advance_audio_buffer(audio_buffer_interleaved(static_cast(src), numChannels, srcTotal), srcPos), numChannels, numFrames); + break; + case SampleFormatInt24: + ConvertBufferToBufferMixFixed(dst, advance_audio_buffer(audio_buffer_interleaved(static_cast(src), numChannels, srcTotal), srcPos), numChannels, numFrames); + break; + case SampleFormatInt32: + ConvertBufferToBufferMixFixed(dst, advance_audio_buffer(audio_buffer_interleaved(static_cast(src), numChannels, srcTotal), srcPos), numChannels, numFrames); + break; + case SampleFormatFloat32: + ConvertBufferToBufferMixFixed(dst, advance_audio_buffer(audio_buffer_interleaved(static_cast(src), numChannels, srcTotal), srcPos), numChannels, numFrames); + break; + case SampleFormatFloat64: + ConvertBufferToBufferMixFixed(dst, advance_audio_buffer(audio_buffer_interleaved(static_cast(src), numChannels, srcTotal), srcPos), numChannels, numFrames); + break; + case SampleFormatInvalid: + // nothing + break; } } template -static void BufferReadTemplateFloat(Tbuffer & dst, const void * src, std::size_t srcTotal, std::size_t srcPos, std::size_t numFrames, std::size_t numChannels, SampleFormat sampleFormat) +static void BufferReadTemplateFloat(Tbuffer &dst, const void *src, std::size_t srcTotal, std::size_t srcPos, std::size_t numFrames, std::size_t numChannels, SampleFormat sampleFormat) { switch(sampleFormat) { - case SampleFormatUnsigned8: - ConvertBufferToBufferMixFloat(dst, advance_audio_buffer(audio_buffer_interleaved(static_cast(src), numChannels, srcTotal), srcPos), numChannels, numFrames); - break; - case SampleFormatInt8: - ConvertBufferToBufferMixFloat(dst, advance_audio_buffer(audio_buffer_interleaved(static_cast(src), numChannels, srcTotal), srcPos), numChannels, numFrames); - break; - case SampleFormatInt16: - ConvertBufferToBufferMixFloat(dst, advance_audio_buffer(audio_buffer_interleaved(static_cast(src), numChannels, srcTotal), srcPos), numChannels, numFrames); - break; - case SampleFormatInt24: - ConvertBufferToBufferMixFloat(dst, advance_audio_buffer(audio_buffer_interleaved(static_cast(src), numChannels, srcTotal), srcPos), numChannels, numFrames); - break; - case SampleFormatInt32: - ConvertBufferToBufferMixFloat(dst, advance_audio_buffer(audio_buffer_interleaved(static_cast(src), numChannels, srcTotal), srcPos), numChannels, numFrames); - break; - case SampleFormatFloat32: - ConvertBufferToBufferMixFloat(dst, advance_audio_buffer(audio_buffer_interleaved(static_cast(src), numChannels, srcTotal), srcPos), numChannels, numFrames); - break; - case SampleFormatFloat64: - ConvertBufferToBufferMixFloat(dst, advance_audio_buffer(audio_buffer_interleaved(static_cast(src), numChannels, srcTotal), srcPos), numChannels, numFrames); - break; - case SampleFormatInvalid: - // nothing - break; + case SampleFormatUnsigned8: + ConvertBufferToBufferMixFloat(dst, advance_audio_buffer(audio_buffer_interleaved(static_cast(src), numChannels, srcTotal), srcPos), numChannels, numFrames); + break; + case SampleFormatInt8: + ConvertBufferToBufferMixFloat(dst, advance_audio_buffer(audio_buffer_interleaved(static_cast(src), numChannels, srcTotal), srcPos), numChannels, numFrames); + break; + case SampleFormatInt16: + ConvertBufferToBufferMixFloat(dst, advance_audio_buffer(audio_buffer_interleaved(static_cast(src), numChannels, srcTotal), srcPos), numChannels, numFrames); + break; + case SampleFormatInt24: + ConvertBufferToBufferMixFloat(dst, advance_audio_buffer(audio_buffer_interleaved(static_cast(src), numChannels, srcTotal), srcPos), numChannels, numFrames); + break; + case SampleFormatInt32: + ConvertBufferToBufferMixFloat(dst, advance_audio_buffer(audio_buffer_interleaved(static_cast(src), numChannels, srcTotal), srcPos), numChannels, numFrames); + break; + case SampleFormatFloat32: + ConvertBufferToBufferMixFloat(dst, advance_audio_buffer(audio_buffer_interleaved(static_cast(src), numChannels, srcTotal), srcPos), numChannels, numFrames); + break; + case SampleFormatFloat64: + ConvertBufferToBufferMixFloat(dst, advance_audio_buffer(audio_buffer_interleaved(static_cast(src), numChannels, srcTotal), srcPos), numChannels, numFrames); + break; + case SampleFormatInvalid: + // nothing + break; } } template -static void BufferWriteTemplateFixed(void * dst, std::size_t dstTotal, std::size_t dstPos, Tbuffer & src, std::size_t numFrames, std::size_t numChannels, Dither &dither, SampleFormat sampleFormat, bool clipFloat) +static void BufferWriteTemplateFixed(void *dst, std::size_t dstTotal, std::size_t dstPos, Tbuffer &src, std::size_t numFrames, std::size_t numChannels, Dither &dither, SampleFormat sampleFormat, bool clipFloat) { switch(sampleFormat) { case SampleFormatUnsigned8: dither.WithDither( - [&](auto &ditherInstance) - { - ConvertBufferMixFixedToBuffer(advance_audio_buffer(audio_buffer_interleaved(static_cast(dst), numChannels, dstTotal), dstPos), src, ditherInstance, numChannels, numFrames); - } - ); + [&](auto &ditherInstance) { + ConvertBufferMixFixedToBuffer(advance_audio_buffer(audio_buffer_interleaved(static_cast(dst), numChannels, dstTotal), dstPos), src, ditherInstance, numChannels, numFrames); + }); break; case SampleFormatInt8: dither.WithDither( - [&](auto &ditherInstance) - { - ConvertBufferMixFixedToBuffer(advance_audio_buffer(audio_buffer_interleaved(static_cast(dst), numChannels, dstTotal), dstPos), src, ditherInstance, numChannels, numFrames); - } - ); + [&](auto &ditherInstance) { + ConvertBufferMixFixedToBuffer(advance_audio_buffer(audio_buffer_interleaved(static_cast(dst), numChannels, dstTotal), dstPos), src, ditherInstance, numChannels, numFrames); + }); break; case SampleFormatInt16: dither.WithDither( - [&](auto &ditherInstance) - { - ConvertBufferMixFixedToBuffer(advance_audio_buffer(audio_buffer_interleaved(static_cast(dst), numChannels, dstTotal), dstPos), src, ditherInstance, numChannels, numFrames); - } - ); + [&](auto &ditherInstance) { + ConvertBufferMixFixedToBuffer(advance_audio_buffer(audio_buffer_interleaved(static_cast(dst), numChannels, dstTotal), dstPos), src, ditherInstance, numChannels, numFrames); + }); break; case SampleFormatInt24: dither.WithDither( - [&](auto &ditherInstance) - { - ConvertBufferMixFixedToBuffer(advance_audio_buffer(audio_buffer_interleaved(static_cast(dst), numChannels, dstTotal), dstPos), src, ditherInstance, numChannels, numFrames); - } - ); + [&](auto &ditherInstance) { + ConvertBufferMixFixedToBuffer(advance_audio_buffer(audio_buffer_interleaved(static_cast(dst), numChannels, dstTotal), dstPos), src, ditherInstance, numChannels, numFrames); + }); break; case SampleFormatInt32: dither.WithDither( - [&](auto &ditherInstance) - { - ConvertBufferMixFixedToBuffer(advance_audio_buffer(audio_buffer_interleaved(static_cast(dst), numChannels, dstTotal), dstPos), src, ditherInstance, numChannels, numFrames); - } - ); + [&](auto &ditherInstance) { + ConvertBufferMixFixedToBuffer(advance_audio_buffer(audio_buffer_interleaved(static_cast(dst), numChannels, dstTotal), dstPos), src, ditherInstance, numChannels, numFrames); + }); break; case SampleFormatFloat32: if(clipFloat) { dither.WithDither( - [&](auto &ditherInstance) - { - ConvertBufferMixFixedToBuffer(advance_audio_buffer(audio_buffer_interleaved(static_cast(dst), numChannels, dstTotal), dstPos), src, ditherInstance, numChannels, numFrames); - } - ); + [&](auto &ditherInstance) { + ConvertBufferMixFixedToBuffer(advance_audio_buffer(audio_buffer_interleaved(static_cast(dst), numChannels, dstTotal), dstPos), src, ditherInstance, numChannels, numFrames); + }); } else { dither.WithDither( - [&](auto &ditherInstance) - { - ConvertBufferMixFixedToBuffer(advance_audio_buffer(audio_buffer_interleaved(static_cast(dst), numChannels, dstTotal), dstPos), src, ditherInstance, numChannels, numFrames); - } - ); + [&](auto &ditherInstance) { + ConvertBufferMixFixedToBuffer(advance_audio_buffer(audio_buffer_interleaved(static_cast(dst), numChannels, dstTotal), dstPos), src, ditherInstance, numChannels, numFrames); + }); } break; case SampleFormatFloat64: @@ -158,19 +145,15 @@ if(clipFloat) { dither.WithDither( - [&](auto &ditherInstance) - { - ConvertBufferMixFixedToBuffer(advance_audio_buffer(audio_buffer_interleaved(static_cast(dst), numChannels, dstTotal), dstPos), src, ditherInstance, numChannels, numFrames); - } - ); + [&](auto &ditherInstance) { + ConvertBufferMixFixedToBuffer(advance_audio_buffer(audio_buffer_interleaved(static_cast(dst), numChannels, dstTotal), dstPos), src, ditherInstance, numChannels, numFrames); + }); } else { dither.WithDither( - [&](auto &ditherInstance) - { - ConvertBufferMixFixedToBuffer(advance_audio_buffer(audio_buffer_interleaved(static_cast(dst), numChannels, dstTotal), dstPos), src, ditherInstance, numChannels, numFrames); - } - ); + [&](auto &ditherInstance) { + ConvertBufferMixFixedToBuffer(advance_audio_buffer(audio_buffer_interleaved(static_cast(dst), numChannels, dstTotal), dstPos), src, ditherInstance, numChannels, numFrames); + }); } break; case SampleFormatInvalid: @@ -181,138 +164,120 @@ template -static void BufferWriteTemplateFloat(void * dst, std::size_t dstTotal, std::size_t dstPos, Tbuffer & src, std::size_t numFrames, std::size_t numChannels, Dither &dither, SampleFormat sampleFormat, bool clipFloat) +static void BufferWriteTemplateFloat(void *dst, std::size_t dstTotal, std::size_t dstPos, Tbuffer &src, std::size_t numFrames, std::size_t numChannels, Dither &dither, SampleFormat sampleFormat, bool clipFloat) { switch(sampleFormat) { - case SampleFormatUnsigned8: - dither.WithDither( - [&](auto &ditherInstance) + case SampleFormatUnsigned8: + dither.WithDither( + [&](auto &ditherInstance) { + ConvertBufferMixFloatToBuffer(advance_audio_buffer(audio_buffer_interleaved(static_cast(dst), numChannels, dstTotal), dstPos), src, ditherInstance, numChannels, numFrames); + }); + break; + case SampleFormatInt8: + dither.WithDither( + [&](auto &ditherInstance) { + ConvertBufferMixFloatToBuffer(advance_audio_buffer(audio_buffer_interleaved(static_cast(dst), numChannels, dstTotal), dstPos), src, ditherInstance, numChannels, numFrames); + }); + break; + case SampleFormatInt16: + dither.WithDither( + [&](auto &ditherInstance) { + ConvertBufferMixFloatToBuffer(advance_audio_buffer(audio_buffer_interleaved(static_cast(dst), numChannels, dstTotal), dstPos), src, ditherInstance, numChannels, numFrames); + }); + break; + case SampleFormatInt24: + dither.WithDither( + [&](auto &ditherInstance) { + ConvertBufferMixFloatToBuffer(advance_audio_buffer(audio_buffer_interleaved(static_cast(dst), numChannels, dstTotal), dstPos), src, ditherInstance, numChannels, numFrames); + }); + break; + case SampleFormatInt32: + dither.WithDither( + [&](auto &ditherInstance) { + ConvertBufferMixFloatToBuffer(advance_audio_buffer(audio_buffer_interleaved(static_cast(dst), numChannels, dstTotal), dstPos), src, ditherInstance, numChannels, numFrames); + }); + break; + case SampleFormatFloat32: + if(clipFloat) { - ConvertBufferMixFloatToBuffer(advance_audio_buffer(audio_buffer_interleaved(static_cast(dst), numChannels, dstTotal), dstPos), src, ditherInstance, numChannels, numFrames); - } - ); - break; - case SampleFormatInt8: - dither.WithDither( - [&](auto &ditherInstance) + dither.WithDither( + [&](auto &ditherInstance) { + ConvertBufferMixFloatToBuffer(advance_audio_buffer(audio_buffer_interleaved(static_cast(dst), numChannels, dstTotal), dstPos), src, ditherInstance, numChannels, numFrames); + }); + } else { - ConvertBufferMixFloatToBuffer(advance_audio_buffer(audio_buffer_interleaved(static_cast(dst), numChannels, dstTotal), dstPos), src, ditherInstance, numChannels, numFrames); + dither.WithDither( + [&](auto &ditherInstance) { + ConvertBufferMixFloatToBuffer(advance_audio_buffer(audio_buffer_interleaved(static_cast(dst), numChannels, dstTotal), dstPos), src, ditherInstance, numChannels, numFrames); + }); } - ); - break; - case SampleFormatInt16: - dither.WithDither( - [&](auto &ditherInstance) + break; + case SampleFormatFloat64: + if(clipFloat) { - ConvertBufferMixFloatToBuffer(advance_audio_buffer(audio_buffer_interleaved(static_cast(dst), numChannels, dstTotal), dstPos), src, ditherInstance, numChannels, numFrames); - } - ); - break; - case SampleFormatInt24: - dither.WithDither( - [&](auto &ditherInstance) + dither.WithDither( + [&](auto &ditherInstance) { + ConvertBufferMixFloatToBuffer(advance_audio_buffer(audio_buffer_interleaved(static_cast(dst), numChannels, dstTotal), dstPos), src, ditherInstance, numChannels, numFrames); + }); + } else { - ConvertBufferMixFloatToBuffer(advance_audio_buffer(audio_buffer_interleaved(static_cast(dst), numChannels, dstTotal), dstPos), src, ditherInstance, numChannels, numFrames); + dither.WithDither( + [&](auto &ditherInstance) { + ConvertBufferMixFloatToBuffer(advance_audio_buffer(audio_buffer_interleaved(static_cast(dst), numChannels, dstTotal), dstPos), src, ditherInstance, numChannels, numFrames); + }); } - ); - break; - case SampleFormatInt32: - dither.WithDither( - [&](auto &ditherInstance) - { - ConvertBufferMixFloatToBuffer(advance_audio_buffer(audio_buffer_interleaved(static_cast(dst), numChannels, dstTotal), dstPos), src, ditherInstance, numChannels, numFrames); - } - ); - break; - case SampleFormatFloat32: - if(clipFloat) - { - dither.WithDither( - [&](auto &ditherInstance) - { - ConvertBufferMixFloatToBuffer(advance_audio_buffer(audio_buffer_interleaved(static_cast(dst), numChannels, dstTotal), dstPos), src, ditherInstance, numChannels, numFrames); - } - ); - } else - { - dither.WithDither( - [&](auto &ditherInstance) - { - ConvertBufferMixFloatToBuffer(advance_audio_buffer(audio_buffer_interleaved(static_cast(dst), numChannels, dstTotal), dstPos), src, ditherInstance, numChannels, numFrames); - } - ); - } - break; - case SampleFormatFloat64: - if(clipFloat) - { - dither.WithDither( - [&](auto &ditherInstance) - { - ConvertBufferMixFloatToBuffer(advance_audio_buffer(audio_buffer_interleaved(static_cast(dst), numChannels, dstTotal), dstPos), src, ditherInstance, numChannels, numFrames); - } - ); - } else - { - dither.WithDither( - [&](auto &ditherInstance) - { - ConvertBufferMixFloatToBuffer(advance_audio_buffer(audio_buffer_interleaved(static_cast(dst), numChannels, dstTotal), dstPos), src, ditherInstance, numChannels, numFrames); - } - ); - } - break; - case SampleFormatInvalid: - // nothing - break; + break; + case SampleFormatInvalid: + // nothing + break; } } -void BufferRead(audio_buffer_interleaved & dst, const void * src, std::size_t srcTotal, std::size_t srcPos, std::size_t numFrames, std::size_t numChannels, SampleFormat sampleFormat) +void BufferRead(audio_buffer_interleaved &dst, const void *src, std::size_t srcTotal, std::size_t srcPos, std::size_t numFrames, std::size_t numChannels, SampleFormat sampleFormat) { BufferReadTemplateFixed(dst, src, srcTotal, srcPos, numFrames, numChannels, sampleFormat); } -void BufferRead(audio_buffer_planar & dst, const void * src, std::size_t srcTotal, std::size_t srcPos, std::size_t numFrames, std::size_t numChannels, SampleFormat sampleFormat) +void BufferRead(audio_buffer_planar &dst, const void *src, std::size_t srcTotal, std::size_t srcPos, std::size_t numFrames, std::size_t numChannels, SampleFormat sampleFormat) { BufferReadTemplateFixed(dst, src, srcTotal, srcPos, numFrames, numChannels, sampleFormat); } -void BufferRead(audio_buffer_interleaved & dst, const void * src, std::size_t srcTotal, std::size_t srcPos, std::size_t numFrames, std::size_t numChannels, SampleFormat sampleFormat) +void BufferRead(audio_buffer_interleaved &dst, const void *src, std::size_t srcTotal, std::size_t srcPos, std::size_t numFrames, std::size_t numChannels, SampleFormat sampleFormat) { BufferReadTemplateFloat(dst, src, srcTotal, srcPos, numFrames, numChannels, sampleFormat); } -void BufferRead(audio_buffer_planar & dst, const void * src, std::size_t srcTotal, std::size_t srcPos, std::size_t numFrames, std::size_t numChannels, SampleFormat sampleFormat) +void BufferRead(audio_buffer_planar &dst, const void *src, std::size_t srcTotal, std::size_t srcPos, std::size_t numFrames, std::size_t numChannels, SampleFormat sampleFormat) { BufferReadTemplateFloat(dst, src, srcTotal, srcPos, numFrames, numChannels, sampleFormat); } -void BufferWrite(void * dst, std::size_t dstTotal, std::size_t dstPos, audio_buffer_interleaved & src, std::size_t numFrames, std::size_t numChannels, Dither &dither, SampleFormat sampleFormat, bool clipFloat) +void BufferWrite(void *dst, std::size_t dstTotal, std::size_t dstPos, audio_buffer_interleaved &src, std::size_t numFrames, std::size_t numChannels, Dither &dither, SampleFormat sampleFormat, bool clipFloat) { BufferWriteTemplateFixed(dst, dstTotal, dstPos, src, numFrames, numChannels, dither, sampleFormat, clipFloat); } -void BufferWrite(void * dst, std::size_t dstTotal, std::size_t dstPos, audio_buffer_planar & src, std::size_t numFrames, std::size_t numChannels, Dither &dither, SampleFormat sampleFormat, bool clipFloat) +void BufferWrite(void *dst, std::size_t dstTotal, std::size_t dstPos, audio_buffer_planar &src, std::size_t numFrames, std::size_t numChannels, Dither &dither, SampleFormat sampleFormat, bool clipFloat) { BufferWriteTemplateFixed(dst, dstTotal, dstPos, src, numFrames, numChannels, dither, sampleFormat, clipFloat); } -void BufferWrite(void * dst, std::size_t dstTotal, std::size_t dstPos, audio_buffer_interleaved & src, std::size_t numFrames, std::size_t numChannels, Dither &dither, SampleFormat sampleFormat, bool clipFloat) +void BufferWrite(void *dst, std::size_t dstTotal, std::size_t dstPos, audio_buffer_interleaved &src, std::size_t numFrames, std::size_t numChannels, Dither &dither, SampleFormat sampleFormat, bool clipFloat) { BufferWriteTemplateFloat(dst, dstTotal, dstPos, src, numFrames, numChannels, dither, sampleFormat, clipFloat); } -void BufferWrite(void * dst, std::size_t dstTotal, std::size_t dstPos, audio_buffer_planar & src, std::size_t numFrames, std::size_t numChannels, Dither &dither, SampleFormat sampleFormat, bool clipFloat) +void BufferWrite(void *dst, std::size_t dstTotal, std::size_t dstPos, audio_buffer_planar &src, std::size_t numFrames, std::size_t numChannels, Dither &dither, SampleFormat sampleFormat, bool clipFloat) { BufferWriteTemplateFloat(dst, dstTotal, dstPos, src, numFrames, numChannels, dither, sampleFormat, clipFloat); } -} // namespace SoundDevice +} // namespace SoundDevice OPENMPT_NAMESPACE_END Index: sounddev/SoundDeviceBuffer.h =================================================================== --- sounddev/SoundDeviceBuffer.h (revision 14154) +++ sounddev/SoundDeviceBuffer.h (working copy) @@ -23,34 +23,36 @@ OPENMPT_NAMESPACE_BEGIN -namespace SoundDevice { +namespace SoundDevice +{ -void BufferRead(audio_buffer_interleaved & dst, const void * src, std::size_t srcTotal, std::size_t srcPos, std::size_t numFrames, std::size_t numChannels, SampleFormat sampleFormat); -void BufferRead(audio_buffer_planar & dst, const void * src, std::size_t srcTotal, std::size_t srcPos, std::size_t numFrames, std::size_t numChannels, SampleFormat sampleFormat); +void BufferRead(audio_buffer_interleaved &dst, const void *src, std::size_t srcTotal, std::size_t srcPos, std::size_t numFrames, std::size_t numChannels, SampleFormat sampleFormat); +void BufferRead(audio_buffer_planar &dst, const void *src, std::size_t srcTotal, std::size_t srcPos, std::size_t numFrames, std::size_t numChannels, SampleFormat sampleFormat); -void BufferRead(audio_buffer_interleaved & dst, const void * src, std::size_t srcTotal, std::size_t srcPos, std::size_t numFrames, std::size_t numChannels, SampleFormat sampleFormat); -void BufferRead(audio_buffer_planar & dst, const void * src, std::size_t srcTotal, std::size_t srcPos, std::size_t numFrames, std::size_t numChannels, SampleFormat sampleFormat); +void BufferRead(audio_buffer_interleaved &dst, const void *src, std::size_t srcTotal, std::size_t srcPos, std::size_t numFrames, std::size_t numChannels, SampleFormat sampleFormat); +void BufferRead(audio_buffer_planar &dst, const void *src, std::size_t srcTotal, std::size_t srcPos, std::size_t numFrames, std::size_t numChannels, SampleFormat sampleFormat); -void BufferWrite(void * dst, std::size_t dstTotal, std::size_t dstPos, audio_buffer_interleaved & src, std::size_t numFrames, std::size_t numChannels, Dither &dither, SampleFormat sampleFormat, bool clipFloat); -void BufferWrite(void * dst, std::size_t dstTotal, std::size_t dstPos, audio_buffer_planar & src, std::size_t numFrames, std::size_t numChannels, Dither &dither, SampleFormat sampleFormat, bool clipFloat); +void BufferWrite(void *dst, std::size_t dstTotal, std::size_t dstPos, audio_buffer_interleaved &src, std::size_t numFrames, std::size_t numChannels, Dither &dither, SampleFormat sampleFormat, bool clipFloat); +void BufferWrite(void *dst, std::size_t dstTotal, std::size_t dstPos, audio_buffer_planar &src, std::size_t numFrames, std::size_t numChannels, Dither &dither, SampleFormat sampleFormat, bool clipFloat); -void BufferWrite(void * dst, std::size_t dstTotal, std::size_t dstPos, audio_buffer_interleaved & src, std::size_t numFrames, std::size_t numChannels, Dither &dither, SampleFormat sampleFormat, bool clipFloat); -void BufferWrite(void * dst, std::size_t dstTotal, std::size_t dstPos, audio_buffer_planar & src, std::size_t numFrames, std::size_t numChannels, Dither &dither, SampleFormat sampleFormat, bool clipFloat); +void BufferWrite(void *dst, std::size_t dstTotal, std::size_t dstPos, audio_buffer_interleaved &src, std::size_t numFrames, std::size_t numChannels, Dither &dither, SampleFormat sampleFormat, bool clipFloat); +void BufferWrite(void *dst, std::size_t dstTotal, std::size_t dstPos, audio_buffer_planar &src, std::size_t numFrames, std::size_t numChannels, Dither &dither, SampleFormat sampleFormat, bool clipFloat); class BufferIO { private: - const void * const m_src; - void * const m_dst; + const void *const m_src; + void *const m_dst; std::size_t m_countFramesReadProcessed; std::size_t m_countFramesWriteProcessed; - Dither & m_dither; + Dither &m_dither; const BufferFormat m_bufferFormat; const std::size_t m_countFramesTotal; + public: - inline BufferIO(void * dst, const void * src, std::size_t numFrames, Dither & dither, BufferFormat bufferFormat) + inline BufferIO(void *dst, const void *src, std::size_t numFrames, Dither &dither, BufferFormat bufferFormat) : m_src(src) , m_dst(dst) , m_countFramesReadProcessed(0) @@ -62,7 +64,7 @@ return; } template - inline void Read(Tbuffer & dst, std::size_t countChunk) + inline void Read(Tbuffer &dst, std::size_t countChunk) { MPT_ASSERT(m_countFramesReadProcessed + countChunk <= m_countFramesTotal); SoundDevice::BufferRead(dst, m_src, m_countFramesTotal, m_countFramesReadProcessed, countChunk, m_bufferFormat.InputChannels, m_bufferFormat.sampleFormat); @@ -69,7 +71,7 @@ m_countFramesReadProcessed += countChunk; } template - inline void Write(Tbuffer & src, std::size_t countChunk) + inline void Write(Tbuffer &src, std::size_t countChunk) { MPT_ASSERT(m_countFramesWriteProcessed + countChunk <= m_countFramesTotal); SoundDevice::BufferWrite(m_dst, m_countFramesTotal, m_countFramesWriteProcessed, src, countChunk, m_bufferFormat.Channels, m_dither, m_bufferFormat.sampleFormat, m_bufferFormat.NeedsClippedFloat); @@ -78,7 +80,7 @@ }; -} // namespace SoundDevice +} // namespace SoundDevice OPENMPT_NAMESPACE_END Index: sounddev/SoundDeviceManager.cpp =================================================================== --- sounddev/SoundDeviceManager.cpp (revision 14154) +++ sounddev/SoundDeviceManager.cpp (working copy) @@ -21,7 +21,7 @@ #include "SoundDeviceStub.h" #if defined(MPT_ENABLE_PULSEAUDIO_FULL) #include "SoundDevicePulseaudio.h" -#endif // MPT_ENABLE_PULSEAUDIO_FULL +#endif // MPT_ENABLE_PULSEAUDIO_FULL #include "SoundDevicePulseSimple.h" @@ -28,9 +28,10 @@ OPENMPT_NAMESPACE_BEGIN -namespace SoundDevice { +namespace SoundDevice +{ - + struct CompareInfo { static int64 score(const SoundDevice::Info &x) @@ -54,15 +55,14 @@ score += static_cast(x.flags.implementor); return score; } - bool operator () (const SoundDevice::Info &x, const SoundDevice::Info &y) + bool operator()(const SoundDevice::Info &x, const SoundDevice::Info &y) { const auto scorex = score(x); const auto scorey = score(y); return (scorex > scorey) - || ((scorex == scorey) && (x.type > y.type)) - || ((scorex == scorey) && (x.type == y.type) && (x.default_ > y.default_)) - || ((scorex == scorey) && (x.type == y.type) && (x.default_ == y.default_) && (x.name < y.name)) - ; + || ((scorex == scorey) && (x.type > y.type)) + || ((scorex == scorey) && (x.type == y.type) && (x.default_ > y.default_)) + || ((scorex == scorey) && (x.type == y.type) && (x.default_ == y.default_) && (x.name < y.name)); } }; @@ -84,7 +84,7 @@ template -SoundDevice::IBase* Manager::ConstructSoundDevice(const SoundDevice::Info &info, SoundDevice::SysInfo sysInfo) +SoundDevice::IBase *Manager::ConstructSoundDevice(const SoundDevice::Info &info, SoundDevice::SysInfo sysInfo) { return new Tdevice(info, sysInfo); } @@ -101,7 +101,7 @@ #ifdef MPT_WITH_PORTAUDIO m_PortAudio.Reload(); -#endif // MPT_WITH_PORTAUDIO +#endif // MPT_WITH_PORTAUDIO #if defined(MPT_ENABLE_PULSEAUDIO_FULL) #if defined(MPT_WITH_PULSEAUDIO) @@ -109,8 +109,8 @@ { EnumerateDevices(GetSysInfo()); } -#endif // MPT_WITH_PULSEAUDIO -#endif // MPT_ENABLE_PULSEAUDIO_FULL +#endif // MPT_WITH_PULSEAUDIO +#endif // MPT_ENABLE_PULSEAUDIO_FULL #if defined(MPT_WITH_PULSEAUDIO) && defined(MPT_WITH_PULSEAUDIOSIMPLE) if(IsComponentAvailable(m_PulseaudioSimple)) @@ -117,7 +117,7 @@ { EnumerateDevices(GetSysInfo()); } -#endif // MPT_WITH_PULSEAUDIO && MPT_WITH_PULSEAUDIOSIMPLE +#endif // MPT_WITH_PULSEAUDIO && MPT_WITH_PULSEAUDIOSIMPLE #if MPT_OS_WINDOWS if(IsComponentAvailable(m_WaveOut)) @@ -124,7 +124,7 @@ { EnumerateDevices(GetSysInfo()); } -#endif // MPT_OS_WINDOWS +#endif // MPT_OS_WINDOWS #ifdef MPT_WITH_ASIO if(IsComponentAvailable(m_ASIO)) @@ -131,7 +131,7 @@ { EnumerateDevices(GetSysInfo()); } -#endif // MPT_WITH_ASIO +#endif // MPT_WITH_ASIO #ifdef MPT_WITH_PORTAUDIO if(IsComponentAvailable(m_PortAudio)) @@ -138,7 +138,7 @@ { EnumerateDevices(GetSysInfo()); } -#endif // MPT_WITH_PORTAUDIO +#endif // MPT_WITH_PORTAUDIO #ifdef MPT_WITH_RTAUDIO if(IsComponentAvailable(m_RtAudio)) @@ -145,13 +145,13 @@ { EnumerateDevices(GetSysInfo()); } -#endif // MPT_WITH_RTAUDIO +#endif // MPT_WITH_RTAUDIO #ifndef MPT_BUILD_WINESUPPORT { EnumerateDevices(GetSysInfo()); } -#endif // !MPT_BUILD_WINESUPPORT +#endif // !MPT_BUILD_WINESUPPORT struct Default { @@ -212,33 +212,33 @@ #endif } else #endif - if(GetSysInfo().SystemClass == mpt::OS::Class::Windows && GetSysInfo().IsWindowsWine() && GetSysInfo().WineHostClass == mpt::OS::Class::Linux) - { // Wine on Linux + if(GetSysInfo().SystemClass == mpt::OS::Class::Windows && GetSysInfo().IsWindowsWine() && GetSysInfo().WineHostClass == mpt::OS::Class::Linux) + { // Wine on Linux typeDefault[SoundDevice::TypePORTAUDIO_WASAPI].value = Info::DefaultFor::System; } else if(GetSysInfo().SystemClass == mpt::OS::Class::Windows && GetSysInfo().IsWindowsWine()) - { // Wine + { // Wine typeDefault[SoundDevice::TypePORTAUDIO_WASAPI].value = Info::DefaultFor::System; - typeDefault[SoundDevice::TypeDSOUND].value = Info::DefaultFor::LowLevel; + typeDefault[SoundDevice::TypeDSOUND].value = Info::DefaultFor::LowLevel; } else if(GetSysInfo().SystemClass == mpt::OS::Class::Windows && GetSysInfo().WindowsVersion.IsBefore(mpt::OS::Windows::Version::WinVista)) - { // WinXP - typeDefault[SoundDevice::TypeWAVEOUT].value = Info::DefaultFor::System; - typeDefault[SoundDevice::TypeASIO].value = Info::DefaultFor::ProAudio; + { // WinXP + typeDefault[SoundDevice::TypeWAVEOUT].value = Info::DefaultFor::System; + typeDefault[SoundDevice::TypeASIO].value = Info::DefaultFor::ProAudio; typeDefault[SoundDevice::TypePORTAUDIO_WDMKS].value = Info::DefaultFor::LowLevel; } else if(GetSysInfo().SystemClass == mpt::OS::Class::Windows && GetSysInfo().WindowsVersion.IsBefore(mpt::OS::Windows::Version::Win7)) - { // Vista - typeDefault[SoundDevice::TypeWAVEOUT].value = Info::DefaultFor::System; - typeDefault[SoundDevice::TypeASIO].value = Info::DefaultFor::ProAudio; + { // Vista + typeDefault[SoundDevice::TypeWAVEOUT].value = Info::DefaultFor::System; + typeDefault[SoundDevice::TypeASIO].value = Info::DefaultFor::ProAudio; typeDefault[SoundDevice::TypePORTAUDIO_WDMKS].value = Info::DefaultFor::LowLevel; } else if(GetSysInfo().SystemClass == mpt::OS::Class::Windows) - { // >=Win7 + { // >=Win7 typeDefault[SoundDevice::TypePORTAUDIO_WASAPI].value = Info::DefaultFor::System; - typeDefault[SoundDevice::TypeASIO].value = Info::DefaultFor::ProAudio; - typeDefault[SoundDevice::TypePORTAUDIO_WDMKS].value = Info::DefaultFor::LowLevel; + typeDefault[SoundDevice::TypeASIO].value = Info::DefaultFor::ProAudio; + typeDefault[SoundDevice::TypePORTAUDIO_WDMKS].value = Info::DefaultFor::LowLevel; } else - { // unknown + { // unknown typeDefault[SoundDevice::TypePORTAUDIO_WASAPI].value = Info::DefaultFor::System; } - for(auto & deviceInfo : m_SoundDevices) + for(auto &deviceInfo : m_SoundDevices) { if(typeDefault[deviceInfo.type].value != Info::DefaultFor::None) { @@ -260,7 +260,6 @@ MPT_LOG(LogDebug, "sounddev", MPT_UFORMAT(" Extra Data: {} = {}")(extra.first, extra.second)); } } - } @@ -318,17 +317,17 @@ return SoundDevice::Info(); } if(!identifier.empty()) - { // valid identifier + { // valid identifier for(const auto &info : *this) { if((info.GetIdentifier() == identifier) && !IsDeviceUnavailable(info.GetIdentifier())) - { // exact match + { // exact match return info; } } } for(const auto &info : *this) - { // find first available device + { // find first available device if(!IsDeviceUnavailable(info.GetIdentifier())) { return info; @@ -419,7 +418,7 @@ } -SoundDevice::IBase * Manager::CreateSoundDevice(SoundDevice::Identifier identifier) +SoundDevice::IBase *Manager::CreateSoundDevice(SoundDevice::Identifier identifier) { MPT_TRACE_SCOPE(); const SoundDevice::Info info = FindDeviceInfo(identifier); @@ -446,7 +445,7 @@ result = nullptr; return nullptr; } - m_DeviceCaps[identifier] = result->GetDeviceCaps(); // update cached caps + m_DeviceCaps[identifier] = result->GetDeviceCaps(); // update cached caps return result; } @@ -499,10 +498,10 @@ break; } if(type.empty()) - { // fallback to first device + { // fallback to first device return *manager.begin(); } - std::size_t index = static_cast((id & SoundDevice::Legacy::MaskIndex) >> SoundDevice::Legacy::ShiftIndex); + std::size_t index = static_cast((id & SoundDevice::Legacy::MaskIndex) >> SoundDevice::Legacy::ShiftIndex); std::size_t seenDevicesOfDesiredType = 0; for(const auto &info : manager) { @@ -511,7 +510,7 @@ if(seenDevicesOfDesiredType == index) { if(!info.IsValid()) - { // fallback to first device + { // fallback to first device return *manager.begin(); } return info; @@ -522,10 +521,10 @@ // default to first device return *manager.begin(); } -} +} // namespace Legacy -} // namespace SoundDevice +} // namespace SoundDevice OPENMPT_NAMESPACE_END Index: sounddev/SoundDeviceManager.h =================================================================== --- sounddev/SoundDeviceManager.h (revision 14154) +++ sounddev/SoundDeviceManager.h (working copy) @@ -24,12 +24,13 @@ OPENMPT_NAMESPACE_BEGIN -namespace SoundDevice { +namespace SoundDevice +{ #if defined(MPT_ENABLE_PULSEAUDIO_FULL) class ComponentPulseaudio; -#endif // MPT_ENABLE_PULSEAUDIO_FULL +#endif // MPT_ENABLE_PULSEAUDIO_FULL class ComponentPulseaudioSimple; class ComponentWaveOut; class ComponentASIO; @@ -41,15 +42,12 @@ { public: - typedef std::size_t GlobalID; private: + typedef SoundDevice::IBase *(*CreateSoundDeviceFunc)(const SoundDevice::Info &info, SoundDevice::SysInfo sysInfo); - typedef SoundDevice::IBase* (*CreateSoundDeviceFunc)(const SoundDevice::Info &info, SoundDevice::SysInfo sysInfo); - private: - const SoundDevice::SysInfo m_SysInfo; const SoundDevice::AppInfo m_AppInfo; @@ -56,23 +54,23 @@ #if defined(MPT_ENABLE_PULSEAUDIO_FULL) #if defined(MPT_WITH_PULSEAUDIO) ComponentHandle m_Pulseaudio; -#endif // MPT_WITH_PULSEAUDIO -#endif // MPT_ENABLE_PULSEAUDIO_FULL +#endif // MPT_WITH_PULSEAUDIO +#endif // MPT_ENABLE_PULSEAUDIO_FULL #if defined(MPT_WITH_PULSEAUDIO) && defined(MPT_WITH_PULSEAUDIOSIMPLE) ComponentHandle m_PulseaudioSimple; -#endif // MPT_WITH_PULSEAUDIO && MPT_WITH_PULSEAUDIOSIMPLE +#endif // MPT_WITH_PULSEAUDIO && MPT_WITH_PULSEAUDIOSIMPLE #if MPT_OS_WINDOWS ComponentHandle m_WaveOut; -#endif // MPT_OS_WINDOWS +#endif // MPT_OS_WINDOWS #ifdef MPT_WITH_ASIO ComponentHandle m_ASIO; -#endif // MPT_WITH_ASIO +#endif // MPT_WITH_ASIO #ifdef MPT_WITH_PORTAUDIO ComponentHandle m_PortAudio; -#endif // MPT_WITH_PORTAUDIO +#endif // MPT_WITH_PORTAUDIO #ifdef MPT_WITH_RTAUDIO ComponentHandle m_RtAudio; -#endif // MPT_WITH_RTAUDIO +#endif // MPT_WITH_RTAUDIO std::vector m_SoundDevices; std::map m_DeviceUnavailable; @@ -81,17 +79,16 @@ std::map m_DeviceDynamicCaps; public: - Manager(SoundDevice::SysInfo sysInfo, SoundDevice::AppInfo appInfo); ~Manager(); private: + template + void EnumerateDevices(SoundDevice::SysInfo sysInfo); + template + static SoundDevice::IBase *ConstructSoundDevice(const SoundDevice::Info &info, SoundDevice::SysInfo sysInfo); - template void EnumerateDevices(SoundDevice::SysInfo sysInfo); - template static SoundDevice::IBase* ConstructSoundDevice(const SoundDevice::Info &info, SoundDevice::SysInfo sysInfo); - public: - SoundDevice::SysInfo GetSysInfo() const { return m_SysInfo; } SoundDevice::AppInfo GetAppInfo() const { return m_AppInfo; } @@ -99,7 +96,7 @@ std::vector::const_iterator begin() const { return m_SoundDevices.begin(); } std::vector::const_iterator end() const { return m_SoundDevices.end(); } - const std::vector & GetDeviceInfos() const { return m_SoundDevices; } + const std::vector &GetDeviceInfos() const { return m_SoundDevices; } SoundDevice::Manager::GlobalID GetGlobalID(SoundDevice::Identifier identifier) const; @@ -115,8 +112,7 @@ SoundDevice::Caps GetDeviceCaps(SoundDevice::Identifier identifier, SoundDevice::IBase *currentSoundDevice = nullptr); SoundDevice::DynamicCaps GetDeviceDynamicCaps(SoundDevice::Identifier identifier, const std::vector &baseSampleRates, SoundDevice::IMessageReceiver *messageReceiver = nullptr, SoundDevice::IBase *currentSoundDevice = nullptr, bool update = false); - SoundDevice::IBase * CreateSoundDevice(SoundDevice::Identifier identifier); - + SoundDevice::IBase *CreateSoundDevice(SoundDevice::Identifier identifier); }; @@ -126,7 +122,7 @@ } -} // namespace SoundDevice +} // namespace SoundDevice OPENMPT_NAMESPACE_END Index: sounddev/SoundDevicePortAudio.cpp =================================================================== --- sounddev/SoundDevicePortAudio.cpp (revision 14154) +++ sounddev/SoundDevicePortAudio.cpp (working copy) @@ -31,7 +31,8 @@ OPENMPT_NAMESPACE_BEGIN -namespace SoundDevice { +namespace SoundDevice +{ #ifdef MPT_WITH_PORTAUDIO @@ -39,7 +40,10 @@ #ifdef MPT_ALL_LOGGING #define PALOG(x) MPT_LOG(LogDebug, "PortAudio", x) #else -#define PALOG(x) do { } while(0) +#define PALOG(x) \ + do \ + { \ + } while(0) #endif @@ -52,11 +56,11 @@ if(internalID == U_("WASAPI-Default")) { m_DeviceIsDefault = true; - m_DeviceIndex = Pa_GetHostApiInfo(Pa_HostApiTypeIdToHostApiIndex(paWASAPI))->defaultOutputDevice; + m_DeviceIndex = Pa_GetHostApiInfo(Pa_HostApiTypeIdToHostApiIndex(paWASAPI))->defaultOutputDevice; } else { m_DeviceIsDefault = false; - m_DeviceIndex = ConvertStrTo(internalID); + m_DeviceIndex = ConvertStrTo(internalID); } m_HostApiType = Pa_GetHostApiInfo(Pa_GetDeviceInfo(m_DeviceIndex)->hostApi)->type; MemsetZero(m_StreamParameters); @@ -63,13 +67,13 @@ MemsetZero(m_InputStreamParameters); #if MPT_OS_WINDOWS MemsetZero(m_WasapiStreamInfo); -#endif // MPT_OS_WINDOWS - m_Stream = 0; - m_StreamInfo = 0; - m_CurrentFrameBuffer = nullptr; +#endif // MPT_OS_WINDOWS + m_Stream = 0; + m_StreamInfo = 0; + m_CurrentFrameBuffer = nullptr; m_CurrentFrameBufferInput = nullptr; - m_CurrentFrameCount = 0; - m_CurrentRealLatency = 0.0; + m_CurrentFrameCount = 0; + m_CurrentRealLatency = 0.0; } @@ -83,11 +87,11 @@ { MemsetZero(m_StreamParameters); MemsetZero(m_InputStreamParameters); - m_Stream = 0; - m_StreamInfo = 0; - m_CurrentFrameBuffer = 0; + m_Stream = 0; + m_StreamInfo = 0; + m_CurrentFrameBuffer = 0; m_CurrentFrameBufferInput = 0; - m_CurrentFrameCount = 0; + m_CurrentFrameCount = 0; m_StreamParameters.device = m_DeviceIndex; if(m_StreamParameters.device == -1) { @@ -105,23 +109,23 @@ { switch(m_Settings.sampleFormat.GetBitsPerSample()) { - case 8: m_StreamParameters.sampleFormat = paInt8; break; - case 16: m_StreamParameters.sampleFormat = paInt16; break; - case 24: m_StreamParameters.sampleFormat = paInt24; break; - case 32: m_StreamParameters.sampleFormat = paInt32; break; - default: return false; break; + case 8: m_StreamParameters.sampleFormat = paInt8; break; + case 16: m_StreamParameters.sampleFormat = paInt16; break; + case 24: m_StreamParameters.sampleFormat = paInt24; break; + case 32: m_StreamParameters.sampleFormat = paInt32; break; + default: return false; break; } } - m_StreamParameters.suggestedLatency = m_Settings.Latency; + m_StreamParameters.suggestedLatency = m_Settings.Latency; m_StreamParameters.hostApiSpecificStreamInfo = NULL; - unsigned long framesPerBuffer = static_cast(m_Settings.UpdateInterval * m_Settings.Samplerate); + unsigned long framesPerBuffer = static_cast(m_Settings.UpdateInterval * m_Settings.Samplerate); if(m_HostApiType == paWASAPI) { #if MPT_OS_WINDOWS MemsetZero(m_WasapiStreamInfo); - m_WasapiStreamInfo.size = sizeof(PaWasapiStreamInfo); + m_WasapiStreamInfo.size = sizeof(PaWasapiStreamInfo); m_WasapiStreamInfo.hostApiType = paWASAPI; - m_WasapiStreamInfo.version = 1; + m_WasapiStreamInfo.version = 1; if(m_Settings.BoostThreadPriority) { m_WasapiStreamInfo.flags |= paWinWasapiThreadPriority; @@ -155,7 +159,7 @@ } m_StreamParameters.hostApiSpecificStreamInfo = &m_WasapiStreamInfo; } -#endif // MPT_OS_WINDOWS +#endif // MPT_OS_WINDOWS if(m_Settings.ExclusiveMode) { m_Flags.NeedsClippedFloat = false; @@ -162,7 +166,7 @@ #if MPT_OS_WINDOWS m_WasapiStreamInfo.flags |= paWinWasapiExclusive | paWinWasapiExplicitSampleFormat; m_StreamParameters.hostApiSpecificStreamInfo = &m_WasapiStreamInfo; -#endif // MPT_OS_WINDOWS +#endif // MPT_OS_WINDOWS } else { m_Flags.NeedsClippedFloat = GetSysInfo().IsOriginal(); @@ -170,7 +174,7 @@ } else if(m_HostApiType == paWDMKS) { m_Flags.NeedsClippedFloat = false; - framesPerBuffer = paFramesPerBufferUnspecified; // let portaudio choose + framesPerBuffer = paFramesPerBufferUnspecified; // let portaudio choose } else if(m_HostApiType == paMME) { m_Flags.NeedsClippedFloat = GetSysInfo().IsOriginal(); @@ -196,7 +200,7 @@ #if MPT_OS_WINDOWS m_WasapiStreamInfo.flags &= ~paWinWasapiExplicitSampleFormat; m_StreamParameters.hostApiSpecificStreamInfo = &m_WasapiStreamInfo; -#endif // MPT_OS_WINDOWS +#endif // MPT_OS_WINDOWS if(Pa_IsFormatSupported((m_Settings.InputChannels > 0) ? &m_InputStreamParameters : NULL, &m_StreamParameters, m_Settings.Samplerate) != paFormatIsSupported) { return false; @@ -204,11 +208,11 @@ } else { if(!GetSysInfo().IsWine && GetSysInfo().WindowsVersion.IsAtLeast(mpt::OS::Windows::Version::Win7)) - { // retry with automatic stream format conversion (i.e. resampling) - #if MPT_OS_WINDOWS + { // retry with automatic stream format conversion (i.e. resampling) +#if MPT_OS_WINDOWS m_WasapiStreamInfo.flags |= paWinWasapiAutoConvert; m_StreamParameters.hostApiSpecificStreamInfo = &m_WasapiStreamInfo; - #endif // MPT_OS_WINDOWS +#endif // MPT_OS_WINDOWS if(Pa_IsFormatSupported((m_Settings.InputChannels > 0) ? &m_InputStreamParameters : NULL, &m_StreamParameters, m_Settings.Samplerate) != paFormatIsSupported) { return false; @@ -228,7 +232,7 @@ { flags |= paDitherOff; } - if(Pa_OpenStream(&m_Stream, (m_Settings.InputChannels > 0) ? &m_InputStreamParameters : NULL, &m_StreamParameters, m_Settings.Samplerate, framesPerBuffer, flags, StreamCallbackWrapper, reinterpret_cast(this)) != paNoError) + if(Pa_OpenStream(&m_Stream, (m_Settings.InputChannels > 0) ? &m_InputStreamParameters : NULL, &m_StreamParameters, m_Settings.Samplerate, framesPerBuffer, flags, StreamCallbackWrapper, reinterpret_cast(this)) != paNoError) { return false; } @@ -252,14 +256,14 @@ Pa_CloseStream(m_Stream); if(Pa_GetDeviceInfo(m_StreamParameters.device)->hostApi == Pa_HostApiTypeIdToHostApiIndex(paWDMKS)) { - Pa_Sleep(mpt::saturate_round(bufferAttributes.Latency * 2.0 * 1000.0 + 0.5)); // wait for broken wdm drivers not closing the stream immediatly + Pa_Sleep(mpt::saturate_round(bufferAttributes.Latency * 2.0 * 1000.0 + 0.5)); // wait for broken wdm drivers not closing the stream immediatly } MemsetZero(m_StreamParameters); MemsetZero(m_InputStreamParameters); - m_StreamInfo = 0; - m_Stream = 0; - m_CurrentFrameCount = 0; - m_CurrentFrameBuffer = 0; + m_StreamInfo = 0; + m_Stream = 0; + m_CurrentFrameCount = 0; + m_CurrentFrameBuffer = 0; m_CurrentFrameBufferInput = 0; } return true; @@ -304,9 +308,9 @@ SoundDevice::BufferAttributes CPortaudioDevice::InternalGetEffectiveBufferAttributes() const { SoundDevice::BufferAttributes bufferAttributes; - bufferAttributes.Latency = m_StreamInfo->outputLatency; + bufferAttributes.Latency = m_StreamInfo->outputLatency; bufferAttributes.UpdateInterval = m_Settings.UpdateInterval; - bufferAttributes.NumBuffers = 1; + bufferAttributes.NumBuffers = 1; if(m_HostApiType == paWASAPI && m_Settings.ExclusiveMode) { // WASAPI exclusive mode streams only account for a single period of latency in PortAudio @@ -351,8 +355,8 @@ MPT_TRACE_SCOPE(); SoundDevice::Statistics result; result.InstantaneousLatency = m_CurrentRealLatency; - result.LastUpdateInterval = 1.0 * m_StatisticPeriodFrames / m_Settings.Samplerate; - result.text = mpt::ustring(); + result.LastUpdateInterval = 1.0 * m_StatisticPeriodFrames / m_Settings.Samplerate; + result.text = mpt::ustring(); #if MPT_OS_WINDOWS if(m_HostApiType == paWASAPI) { @@ -376,7 +380,7 @@ } } } -#endif // MPT_OS_WINDOWS +#endif // MPT_OS_WINDOWS return result; } @@ -384,19 +388,19 @@ SoundDevice::Caps CPortaudioDevice::InternalGetDeviceCaps() { SoundDevice::Caps caps; - caps.Available = true; - caps.CanUpdateInterval = true; - caps.CanSampleFormat = true; - caps.CanExclusiveMode = false; - caps.CanBoostThreadPriority = false; - caps.CanUseHardwareTiming = false; - caps.CanChannelMapping = false; - caps.CanInput = false; - caps.HasNamedInputSources = false; - caps.CanDriverPanel = false; - caps.HasInternalDither = true; + caps.Available = true; + caps.CanUpdateInterval = true; + caps.CanSampleFormat = true; + caps.CanExclusiveMode = false; + caps.CanBoostThreadPriority = false; + caps.CanUseHardwareTiming = false; + caps.CanChannelMapping = false; + caps.CanInput = false; + caps.HasNamedInputSources = false; + caps.CanDriverPanel = false; + caps.HasInternalDither = true; caps.DefaultSettings.sampleFormat = SampleFormatFloat32; - const PaDeviceInfo *deviceInfo = Pa_GetDeviceInfo(m_DeviceIndex); + const PaDeviceInfo *deviceInfo = Pa_GetDeviceInfo(m_DeviceIndex); if(deviceInfo) { caps.DefaultSettings.Latency = deviceInfo->defaultLowOutputLatency; @@ -403,22 +407,22 @@ } if(HasInputChannelsOnSameDevice()) { - caps.CanInput = true; + caps.CanInput = true; caps.HasNamedInputSources = false; } else { - caps.CanInput = (EnumerateInputOnlyDevices(m_HostApiType).size() > 0); + caps.CanInput = (EnumerateInputOnlyDevices(m_HostApiType).size() > 0); caps.HasNamedInputSources = caps.CanInput; } if(m_HostApiType == paWASAPI) { - caps.CanBoostThreadPriority = true; - caps.CanDriverPanel = true; + caps.CanBoostThreadPriority = true; + caps.CanDriverPanel = true; caps.DefaultSettings.sampleFormat = SampleFormatFloat32; if(m_DeviceIsDefault) { - caps.CanExclusiveMode = false; - caps.DefaultSettings.Latency = 0.030; + caps.CanExclusiveMode = false; + caps.DefaultSettings.Latency = 0.030; caps.DefaultSettings.UpdateInterval = 0.010; } else { @@ -426,13 +430,13 @@ if(deviceInfo) { // PortAudio WASAPI returns the device period as latency - caps.DefaultSettings.Latency = deviceInfo->defaultHighOutputLatency * 2.0; + caps.DefaultSettings.Latency = deviceInfo->defaultHighOutputLatency * 2.0; caps.DefaultSettings.UpdateInterval = deviceInfo->defaultHighOutputLatency; } } } else if(m_HostApiType == paWDMKS) { - caps.CanUpdateInterval = false; + caps.CanUpdateInterval = false; caps.DefaultSettings.sampleFormat = SampleFormatInt32; } else if(m_HostApiType == paDirectSound) { @@ -487,11 +491,11 @@ { return caps; } - for(std::size_t n = 0; n sampleFormats { SampleFormatInt8, SampleFormatInt16, SampleFormatInt24, SampleFormatInt32, SampleFormatFloat32 }; + const std::array sampleFormats{SampleFormatInt8, SampleFormatInt16, SampleFormatInt24, SampleFormatInt32, SampleFormatFloat32}; for(const SampleFormat sampleFormat : sampleFormats) { for(const auto sampleRate : caps.supportedExclusiveSampleRates) @@ -539,7 +543,7 @@ { PaStreamParameters StreamParameters; MemsetZero(StreamParameters); - StreamParameters.device = device; + StreamParameters.device = device; StreamParameters.channelCount = 2; if(sampleFormat.IsFloat()) { @@ -548,20 +552,20 @@ { switch(sampleFormat.GetBitsPerSample()) { - case 8: StreamParameters.sampleFormat = paInt8; break; - case 16: StreamParameters.sampleFormat = paInt16; break; - case 24: StreamParameters.sampleFormat = paInt24; break; - case 32: StreamParameters.sampleFormat = paInt32; break; + case 8: StreamParameters.sampleFormat = paInt8; break; + case 16: StreamParameters.sampleFormat = paInt16; break; + case 24: StreamParameters.sampleFormat = paInt24; break; + case 32: StreamParameters.sampleFormat = paInt32; break; } } - StreamParameters.suggestedLatency = 0.0; + StreamParameters.suggestedLatency = 0.0; StreamParameters.hostApiSpecificStreamInfo = NULL; PaWasapiStreamInfo wasapiStreamInfo; MemsetZero(wasapiStreamInfo); - wasapiStreamInfo.size = sizeof(PaWasapiStreamInfo); - wasapiStreamInfo.hostApiType = paWASAPI; - wasapiStreamInfo.version = 1; - wasapiStreamInfo.flags = paWinWasapiExclusive | paWinWasapiExplicitSampleFormat; + wasapiStreamInfo.size = sizeof(PaWasapiStreamInfo); + wasapiStreamInfo.hostApiType = paWASAPI; + wasapiStreamInfo.version = 1; + wasapiStreamInfo.flags = paWinWasapiExclusive | paWinWasapiExplicitSampleFormat; StreamParameters.hostApiSpecificStreamInfo = &wasapiStreamInfo; if(Pa_IsFormatSupported(NULL, &StreamParameters, sampleRate) == paFormatIsSupported) { @@ -575,7 +579,7 @@ { caps.supportedSampleFormats.clear(); caps.supportedExclusiveModeSampleFormats.clear(); - const std::array sampleFormats { SampleFormatInt8, SampleFormatInt16, SampleFormatInt24, SampleFormatInt32, SampleFormatFloat32 }; + const std::array sampleFormats{SampleFormatInt8, SampleFormatInt16, SampleFormatInt24, SampleFormatInt32, SampleFormatFloat32}; for(const SampleFormat sampleFormat : sampleFormats) { for(const auto sampleRate : caps.supportedSampleRates) @@ -582,7 +586,7 @@ { PaStreamParameters StreamParameters; MemsetZero(StreamParameters); - StreamParameters.device = device; + StreamParameters.device = device; StreamParameters.channelCount = 2; if(sampleFormat.IsFloat()) { @@ -591,13 +595,13 @@ { switch(sampleFormat.GetBitsPerSample()) { - case 8: StreamParameters.sampleFormat = paInt8; break; - case 16: StreamParameters.sampleFormat = paInt16; break; - case 24: StreamParameters.sampleFormat = paInt24; break; - case 32: StreamParameters.sampleFormat = paInt32; break; + case 8: StreamParameters.sampleFormat = paInt8; break; + case 16: StreamParameters.sampleFormat = paInt16; break; + case 24: StreamParameters.sampleFormat = paInt24; break; + case 32: StreamParameters.sampleFormat = paInt32; break; } } - StreamParameters.suggestedLatency = 0.0; + StreamParameters.suggestedLatency = 0.0; StreamParameters.hostApiSpecificStreamInfo = NULL; if(Pa_IsFormatSupported(NULL, &StreamParameters, sampleRate) == paFormatIsSupported) { @@ -616,13 +620,13 @@ caps.supportedExclusiveModeSampleFormats = DefaultSampleFormats>(); } } -#endif // MPT_OS_WINDOWS +#endif // MPT_OS_WINDOWS #if MPT_OS_WINDOWS if((m_HostApiType == paWASAPI) && GetSysInfo().WindowsVersion.IsAtLeast(mpt::OS::Windows::Version::Win7)) { caps.supportedSampleRates = baseSampleRates; } -#endif // MPT_OS_WINDOWS +#endif // MPT_OS_WINDOWS if(!HasInputChannelsOnSameDevice()) { @@ -655,18 +659,14 @@ } controlEXE += P_("control.exe"); return (reinterpret_cast(ShellExecute(NULL, TEXT("open"), controlEXE.AsNative().c_str(), TEXT("/name Microsoft.Sound"), NULL, SW_SHOW)) >= 32); -#else // !MPT_OS_WINDOWS +#else // !MPT_OS_WINDOWS return false; -#endif // MPT_OS_WINDOWS +#endif // MPT_OS_WINDOWS } int CPortaudioDevice::StreamCallback( - const void *input, void *output, - unsigned long frameCount, - const PaStreamCallbackTimeInfo* timeInfo, - PaStreamCallbackFlags statusFlags - ) + const void *input, void *output, unsigned long frameCount, const PaStreamCallbackTimeInfo *timeInfo, PaStreamCallbackFlags statusFlags) { if(!input && !output) { @@ -697,12 +697,12 @@ { m_CurrentRealLatency = timeInfo->outputBufferDacTime - timeInfo->currentTime; } - m_CurrentFrameBuffer = output; + m_CurrentFrameBuffer = output; m_CurrentFrameBufferInput = input; - m_CurrentFrameCount = frameCount; + m_CurrentFrameCount = frameCount; SourceFillAudioBufferLocked(); - m_CurrentFrameCount = 0; - m_CurrentFrameBuffer = 0; + m_CurrentFrameCount = 0; + m_CurrentFrameBuffer = 0; m_CurrentFrameBufferInput = 0; if((m_HostApiType == paALSA) && (statusFlags & paOutputUnderflow)) { @@ -714,14 +714,9 @@ int CPortaudioDevice::StreamCallbackWrapper( - const void *input, void *output, - unsigned long frameCount, - const PaStreamCallbackTimeInfo* timeInfo, - PaStreamCallbackFlags statusFlags, - void *userData - ) + const void *input, void *output, unsigned long frameCount, const PaStreamCallbackTimeInfo *timeInfo, PaStreamCallbackFlags statusFlags, void *userData) { - return reinterpret_cast(userData)->StreamCallback(input, output, frameCount, timeInfo, statusFlags); + return reinterpret_cast(userData)->StreamCallback(input, output, frameCount, timeInfo, statusFlags); } @@ -773,156 +768,145 @@ result.type = U_("PortAudio") + U_("-") + mpt::ufmt::dec(static_cast(Pa_GetHostApiInfo(Pa_GetDeviceInfo(dev)->hostApi)->type)); break; } - result.internalID = mpt::ufmt::dec(dev); - result.name = mpt::ToUnicode(mpt::Charset::UTF8, Pa_GetDeviceInfo(dev)->name); - result.apiName = mpt::ToUnicode(mpt::Charset::UTF8, Pa_GetHostApiInfo(Pa_GetDeviceInfo(dev)->hostApi)->name); + result.internalID = mpt::ufmt::dec(dev); + result.name = mpt::ToUnicode(mpt::Charset::UTF8, Pa_GetDeviceInfo(dev)->name); + result.apiName = mpt::ToUnicode(mpt::Charset::UTF8, Pa_GetHostApiInfo(Pa_GetDeviceInfo(dev)->hostApi)->name); result.extraData[U_("PortAudio-HostAPI-name")] = mpt::ToUnicode(mpt::Charset::UTF8, Pa_GetHostApiInfo(Pa_GetDeviceInfo(dev)->hostApi)->name); result.apiPath.push_back(U_("PortAudio")); result.useNameAsIdentifier = true; - result.flags = { - Info::Usability::Unknown, - Info::Level::Unknown, - Info::Compatible::Unknown, - Info::Api::Unknown, - Info::Io::Unknown, - Info::Mixing::Unknown, - Info::Implementor::External - }; + result.flags = { + Info::Usability::Unknown, + Info::Level::Unknown, + Info::Compatible::Unknown, + Info::Api::Unknown, + Info::Io::Unknown, + Info::Mixing::Unknown, + Info::Implementor::External}; switch(Pa_GetHostApiInfo(Pa_GetDeviceInfo(dev)->hostApi)->type) { - case paDirectSound: - result.apiName = U_("DirectSound"); - result.default_ = ((Pa_GetHostApiInfo(Pa_GetDeviceInfo(dev)->hostApi)->defaultOutputDevice == static_cast(dev)) ? Info::Default::Managed : Info::Default::None); - result.flags = { - sysInfo.SystemClass == mpt::OS::Class::Windows ? Info::Usability::Deprecated : Info::Usability::NotAvailable, - Info::Level::Secondary, - Info::Compatible::No, - Info::Api::Emulated, - Info::Io::FullDuplex, - Info::Mixing::Software, - Info::Implementor::External - }; - break; - case paMME: - result.apiName = U_("MME"); - result.default_ = ((Pa_GetHostApiInfo(Pa_GetDeviceInfo(dev)->hostApi)->defaultOutputDevice == static_cast(dev)) ? Info::Default::Named : Info::Default::None); - result.flags = { - sysInfo.SystemClass == mpt::OS::Class::Windows ? Info::Usability::Deprecated : Info::Usability::NotAvailable, - Info::Level::Secondary, - Info::Compatible::No, - Info::Api::Emulated, - Info::Io::FullDuplex, - Info::Mixing::Software, - Info::Implementor::External - }; - break; - case paASIO: - result.apiName = U_("ASIO"); - result.default_ = ((Pa_GetHostApiInfo(Pa_GetDeviceInfo(dev)->hostApi)->defaultOutputDevice == static_cast(dev)) ? Info::Default::Named : Info::Default::None); - result.flags = { - sysInfo.SystemClass == mpt::OS::Class::Windows ? sysInfo.IsWindowsOriginal() ? Info::Usability::Usable : Info::Usability::Experimental : Info::Usability::NotAvailable, - Info::Level::Secondary, - Info::Compatible::No, - sysInfo.SystemClass == mpt::OS::Class::Windows && sysInfo.IsWindowsOriginal() ? Info::Api::Native : Info::Api::Emulated, - Info::Io::FullDuplex, - Info::Mixing::Hardware, - Info::Implementor::External - }; - break; - case paCoreAudio: - result.apiName = U_("CoreAudio"); - result.default_ = ((Pa_GetHostApiInfo(Pa_GetDeviceInfo(dev)->hostApi)->defaultOutputDevice == static_cast(dev)) ? Info::Default::Named : Info::Default::None); - result.flags = { - sysInfo.SystemClass == mpt::OS::Class::Darwin ? Info::Usability::Usable : Info::Usability::NotAvailable, - Info::Level::Secondary, - Info::Compatible::Yes, - sysInfo.SystemClass == mpt::OS::Class::Darwin ? Info::Api::Native : Info::Api::Emulated, - Info::Io::FullDuplex, - Info::Mixing::Server, - Info::Implementor::External - }; - break; - case paOSS: - result.apiName = U_("OSS"); - result.default_ = ((Pa_GetHostApiInfo(Pa_GetDeviceInfo(dev)->hostApi)->defaultOutputDevice == static_cast(dev)) ? Info::Default::Named : Info::Default::None); - result.flags = { - sysInfo.SystemClass == mpt::OS::Class::BSD ? Info::Usability::Usable : sysInfo.SystemClass == mpt::OS::Class::Linux ? Info::Usability::Deprecated : Info::Usability::NotAvailable, - Info::Level::Primary, - Info::Compatible::No, - sysInfo.SystemClass == mpt::OS::Class::BSD ? Info::Api::Native : sysInfo.SystemClass == mpt::OS::Class::Linux ? Info::Api::Emulated : Info::Api::Emulated, - Info::Io::FullDuplex, - sysInfo.SystemClass == mpt::OS::Class::BSD ? Info::Mixing::Hardware : sysInfo.SystemClass == mpt::OS::Class::Linux ? Info::Mixing::Software : Info::Mixing::Software, - Info::Implementor::External - }; - break; - case paALSA: - result.apiName = U_("ALSA"); - result.default_ = ((Pa_GetHostApiInfo(Pa_GetDeviceInfo(dev)->hostApi)->defaultOutputDevice == static_cast(dev)) ? Info::Default::Named : Info::Default::None); - result.flags = { - sysInfo.SystemClass == mpt::OS::Class::Linux ? Info::Usability::Usable : Info::Usability::Experimental, - Info::Level::Primary, - Info::Compatible::No, - sysInfo.SystemClass == mpt::OS::Class::Linux ? Info::Api::Native : Info::Api::Emulated, - Info::Io::FullDuplex, - sysInfo.SystemClass == mpt::OS::Class::Linux ? Info::Mixing::Hardware : Info::Mixing::Software, - Info::Implementor::External - }; - break; - case paAL: - result.apiName = U_("OpenAL"); - result.default_ = ((Pa_GetHostApiInfo(Pa_GetDeviceInfo(dev)->hostApi)->defaultOutputDevice == static_cast(dev)) ? Info::Default::Named : Info::Default::None); - result.flags = { - Info::Usability::Usable, - Info::Level::Primary, - Info::Compatible::No, - Info::Api::Emulated, - Info::Io::FullDuplex, - Info::Mixing::Software, - Info::Implementor::External - }; - break; - case paWDMKS: - result.apiName = U_("WaveRT"); - result.default_ = ((Pa_GetHostApiInfo(Pa_GetDeviceInfo(dev)->hostApi)->defaultOutputDevice == static_cast(dev)) ? Info::Default::Named : Info::Default::None); - result.flags = { - sysInfo.SystemClass == mpt::OS::Class::Windows ? sysInfo.IsWindowsOriginal() ? Info::Usability::Usable : Info::Usability::Broken : Info::Usability::NotAvailable, - Info::Level::Primary, - Info::Compatible::No, - sysInfo.SystemClass == mpt::OS::Class::Windows ? sysInfo.IsWindowsOriginal() ? Info::Api::Native : Info::Api::Emulated : Info::Api::Emulated, - Info::Io::FullDuplex, - Info::Mixing::Hardware, - Info::Implementor::External - }; - break; - case paJACK: - result.apiName = U_("JACK"); - result.default_ = ((Pa_GetHostApiInfo(Pa_GetDeviceInfo(dev)->hostApi)->defaultOutputDevice == static_cast(dev)) ? Info::Default::Managed : Info::Default::None); - result.flags = { - sysInfo.SystemClass == mpt::OS::Class::Linux ? Info::Usability::Usable : sysInfo.SystemClass == mpt::OS::Class::Darwin ? Info::Usability::Usable : Info::Usability::Experimental, - Info::Level::Secondary, - Info::Compatible::Yes, - sysInfo.SystemClass == mpt::OS::Class::Linux ? Info::Api::Native : Info::Api::Emulated, - Info::Io::FullDuplex, - Info::Mixing::Server, - Info::Implementor::External - }; - break; - case paWASAPI: - result.apiName = U_("WASAPI"); - result.default_ = ((Pa_GetHostApiInfo(Pa_GetDeviceInfo(dev)->hostApi)->defaultOutputDevice == static_cast(dev)) ? Info::Default::Named : Info::Default::None); - result.flags = { - sysInfo.SystemClass == mpt::OS::Class::Windows ? Info::Usability::Usable : Info::Usability::NotAvailable, - Info::Level::Primary, - Info::Compatible::No, - sysInfo.SystemClass == mpt::OS::Class::Windows ? Info::Api::Native : Info::Api::Emulated, - Info::Io::FullDuplex, - Info::Mixing::Server, - Info::Implementor::External - }; - break; - default: - // nothing - break; + case paDirectSound: + result.apiName = U_("DirectSound"); + result.default_ = ((Pa_GetHostApiInfo(Pa_GetDeviceInfo(dev)->hostApi)->defaultOutputDevice == static_cast(dev)) ? Info::Default::Managed : Info::Default::None); + result.flags = { + sysInfo.SystemClass == mpt::OS::Class::Windows ? Info::Usability::Deprecated : Info::Usability::NotAvailable, + Info::Level::Secondary, + Info::Compatible::No, + Info::Api::Emulated, + Info::Io::FullDuplex, + Info::Mixing::Software, + Info::Implementor::External}; + break; + case paMME: + result.apiName = U_("MME"); + result.default_ = ((Pa_GetHostApiInfo(Pa_GetDeviceInfo(dev)->hostApi)->defaultOutputDevice == static_cast(dev)) ? Info::Default::Named : Info::Default::None); + result.flags = { + sysInfo.SystemClass == mpt::OS::Class::Windows ? Info::Usability::Deprecated : Info::Usability::NotAvailable, + Info::Level::Secondary, + Info::Compatible::No, + Info::Api::Emulated, + Info::Io::FullDuplex, + Info::Mixing::Software, + Info::Implementor::External}; + break; + case paASIO: + result.apiName = U_("ASIO"); + result.default_ = ((Pa_GetHostApiInfo(Pa_GetDeviceInfo(dev)->hostApi)->defaultOutputDevice == static_cast(dev)) ? Info::Default::Named : Info::Default::None); + result.flags = { + sysInfo.SystemClass == mpt::OS::Class::Windows ? sysInfo.IsWindowsOriginal() ? Info::Usability::Usable : Info::Usability::Experimental : Info::Usability::NotAvailable, + Info::Level::Secondary, + Info::Compatible::No, + sysInfo.SystemClass == mpt::OS::Class::Windows && sysInfo.IsWindowsOriginal() ? Info::Api::Native : Info::Api::Emulated, + Info::Io::FullDuplex, + Info::Mixing::Hardware, + Info::Implementor::External}; + break; + case paCoreAudio: + result.apiName = U_("CoreAudio"); + result.default_ = ((Pa_GetHostApiInfo(Pa_GetDeviceInfo(dev)->hostApi)->defaultOutputDevice == static_cast(dev)) ? Info::Default::Named : Info::Default::None); + result.flags = { + sysInfo.SystemClass == mpt::OS::Class::Darwin ? Info::Usability::Usable : Info::Usability::NotAvailable, + Info::Level::Secondary, + Info::Compatible::Yes, + sysInfo.SystemClass == mpt::OS::Class::Darwin ? Info::Api::Native : Info::Api::Emulated, + Info::Io::FullDuplex, + Info::Mixing::Server, + Info::Implementor::External}; + break; + case paOSS: + result.apiName = U_("OSS"); + result.default_ = ((Pa_GetHostApiInfo(Pa_GetDeviceInfo(dev)->hostApi)->defaultOutputDevice == static_cast(dev)) ? Info::Default::Named : Info::Default::None); + result.flags = { + sysInfo.SystemClass == mpt::OS::Class::BSD ? Info::Usability::Usable : sysInfo.SystemClass == mpt::OS::Class::Linux ? Info::Usability::Deprecated : Info::Usability::NotAvailable, + Info::Level::Primary, + Info::Compatible::No, + sysInfo.SystemClass == mpt::OS::Class::BSD ? Info::Api::Native : sysInfo.SystemClass == mpt::OS::Class::Linux ? Info::Api::Emulated : Info::Api::Emulated, + Info::Io::FullDuplex, + sysInfo.SystemClass == mpt::OS::Class::BSD ? Info::Mixing::Hardware : sysInfo.SystemClass == mpt::OS::Class::Linux ? Info::Mixing::Software : Info::Mixing::Software, + Info::Implementor::External}; + break; + case paALSA: + result.apiName = U_("ALSA"); + result.default_ = ((Pa_GetHostApiInfo(Pa_GetDeviceInfo(dev)->hostApi)->defaultOutputDevice == static_cast(dev)) ? Info::Default::Named : Info::Default::None); + result.flags = { + sysInfo.SystemClass == mpt::OS::Class::Linux ? Info::Usability::Usable : Info::Usability::Experimental, + Info::Level::Primary, + Info::Compatible::No, + sysInfo.SystemClass == mpt::OS::Class::Linux ? Info::Api::Native : Info::Api::Emulated, + Info::Io::FullDuplex, + sysInfo.SystemClass == mpt::OS::Class::Linux ? Info::Mixing::Hardware : Info::Mixing::Software, + Info::Implementor::External}; + break; + case paAL: + result.apiName = U_("OpenAL"); + result.default_ = ((Pa_GetHostApiInfo(Pa_GetDeviceInfo(dev)->hostApi)->defaultOutputDevice == static_cast(dev)) ? Info::Default::Named : Info::Default::None); + result.flags = { + Info::Usability::Usable, + Info::Level::Primary, + Info::Compatible::No, + Info::Api::Emulated, + Info::Io::FullDuplex, + Info::Mixing::Software, + Info::Implementor::External}; + break; + case paWDMKS: + result.apiName = U_("WaveRT"); + result.default_ = ((Pa_GetHostApiInfo(Pa_GetDeviceInfo(dev)->hostApi)->defaultOutputDevice == static_cast(dev)) ? Info::Default::Named : Info::Default::None); + result.flags = { + sysInfo.SystemClass == mpt::OS::Class::Windows ? sysInfo.IsWindowsOriginal() ? Info::Usability::Usable : Info::Usability::Broken : Info::Usability::NotAvailable, + Info::Level::Primary, + Info::Compatible::No, + sysInfo.SystemClass == mpt::OS::Class::Windows ? sysInfo.IsWindowsOriginal() ? Info::Api::Native : Info::Api::Emulated : Info::Api::Emulated, + Info::Io::FullDuplex, + Info::Mixing::Hardware, + Info::Implementor::External}; + break; + case paJACK: + result.apiName = U_("JACK"); + result.default_ = ((Pa_GetHostApiInfo(Pa_GetDeviceInfo(dev)->hostApi)->defaultOutputDevice == static_cast(dev)) ? Info::Default::Managed : Info::Default::None); + result.flags = { + sysInfo.SystemClass == mpt::OS::Class::Linux ? Info::Usability::Usable : sysInfo.SystemClass == mpt::OS::Class::Darwin ? Info::Usability::Usable : Info::Usability::Experimental, + Info::Level::Secondary, + Info::Compatible::Yes, + sysInfo.SystemClass == mpt::OS::Class::Linux ? Info::Api::Native : Info::Api::Emulated, + Info::Io::FullDuplex, + Info::Mixing::Server, + Info::Implementor::External}; + break; + case paWASAPI: + result.apiName = U_("WASAPI"); + result.default_ = ((Pa_GetHostApiInfo(Pa_GetDeviceInfo(dev)->hostApi)->defaultOutputDevice == static_cast(dev)) ? Info::Default::Named : Info::Default::None); + result.flags = { + sysInfo.SystemClass == mpt::OS::Class::Windows ? Info::Usability::Usable : Info::Usability::NotAvailable, + Info::Level::Primary, + Info::Compatible::No, + sysInfo.SystemClass == mpt::OS::Class::Windows ? Info::Api::Native : Info::Api::Emulated, + Info::Io::FullDuplex, + Info::Mixing::Server, + Info::Implementor::External}; + break; + default: + // nothing + break; } PALOG(MPT_UFORMAT("PortAudio: {}, {}, {}, {}")(result.internalID, result.name, result.apiName, static_cast(result.default_))); PALOG(MPT_UFORMAT(" low : {}")(Pa_GetDeviceInfo(dev)->defaultLowOutputLatency)); @@ -929,10 +913,10 @@ PALOG(MPT_UFORMAT(" high : {}")(Pa_GetDeviceInfo(dev)->defaultHighOutputLatency)); if((result.default_ != Info::Default::None) && (Pa_GetHostApiInfo(Pa_GetDeviceInfo(dev)->hostApi)->type == paWASAPI)) { - auto defaultResult = result; - defaultResult.default_ = Info::Default::Managed; - defaultResult.name = U_("Default Device"); - defaultResult.internalID = U_("WASAPI-Default"); + auto defaultResult = result; + defaultResult.default_ = Info::Default::Managed; + defaultResult.name = U_("Default Device"); + defaultResult.internalID = U_("WASAPI-Default"); defaultResult.useNameAsIdentifier = false; devices.push_back(defaultResult); result.default_ = Info::Default::Named; @@ -943,9 +927,9 @@ } -std::vector > CPortaudioDevice::EnumerateInputOnlyDevices(PaHostApiTypeId hostApiType) +std::vector> CPortaudioDevice::EnumerateInputOnlyDevices(PaHostApiTypeId hostApiType) { - std::vector > result; + std::vector> result; for(PaDeviceIndex dev = 0; dev < Pa_GetDeviceCount(); ++dev) { if(!Pa_GetDeviceInfo(dev)) @@ -973,7 +957,7 @@ continue; } if(Pa_GetDeviceInfo(dev)->maxOutputChannels > 0) - { // only find devices with only input channels + { // only find devices with only input channels continue; } if(Pa_GetHostApiInfo(Pa_GetDeviceInfo(dev)->hostApi)->type != hostApiType) @@ -1010,7 +994,7 @@ } PALOG(MPT_UFORMAT("PortAudio: {}")(mpt::ToUnicode(mpt::Charset::UTF8, text))); } -#endif // MPT_COMPILER_MSVC +#endif // MPT_COMPILER_MSVC MPT_REGISTERED_COMPONENT(ComponentPortAudio, "PortAudio") @@ -1024,9 +1008,9 @@ bool ComponentPortAudio::DoInitialize() { - #if defined(MODPLUG_TRACKER) && MPT_COMPILER_MSVC - PaUtil_SetDebugPrintFunction(PortaudioLog); - #endif +#if defined(MODPLUG_TRACKER) && MPT_COMPILER_MSVC + PaUtil_SetDebugPrintFunction(PortaudioLog); +#endif return (Pa_Initialize() == paNoError); } @@ -1040,10 +1024,10 @@ } -#endif // MPT_WITH_PORTAUDIO +#endif // MPT_WITH_PORTAUDIO -} // namespace SoundDevice +} // namespace SoundDevice OPENMPT_NAMESPACE_END Index: sounddev/SoundDevicePortAudio.h =================================================================== --- sounddev/SoundDevicePortAudio.h (revision 14154) +++ sounddev/SoundDevicePortAudio.h (working copy) @@ -20,20 +20,20 @@ #include #if MPT_OS_WINDOWS #include -#endif // MPT_OS_WINDOWS +#endif // MPT_OS_WINDOWS #endif OPENMPT_NAMESPACE_BEGIN -namespace SoundDevice { +namespace SoundDevice +{ #ifdef MPT_WITH_PORTAUDIO -class CPortaudioDevice: public SoundDevice::Base +class CPortaudioDevice : public SoundDevice::Base { protected: - PaDeviceIndex m_DeviceIsDefault; PaDeviceIndex m_DeviceIndex; PaHostApiTypeId m_HostApiType; @@ -41,23 +41,21 @@ PaStreamParameters m_InputStreamParameters; #if MPT_OS_WINDOWS PaWasapiStreamInfo m_WasapiStreamInfo; -#endif // MPT_OS_WINDOWS - PaStream * m_Stream; - const PaStreamInfo * m_StreamInfo; - void * m_CurrentFrameBuffer; - const void * m_CurrentFrameBufferInput; +#endif // MPT_OS_WINDOWS + PaStream *m_Stream; + const PaStreamInfo *m_StreamInfo; + void *m_CurrentFrameBuffer; + const void *m_CurrentFrameBufferInput; unsigned long m_CurrentFrameCount; - double m_CurrentRealLatency; // seconds + double m_CurrentRealLatency; // seconds std::atomic m_StatisticPeriodFrames; public: - CPortaudioDevice(SoundDevice::Info info, SoundDevice::SysInfo sysInfo); ~CPortaudioDevice(); public: - bool InternalOpen(); bool InternalClose(); void InternalFillAudioBuffer(); @@ -74,30 +72,18 @@ bool OnIdle(); int StreamCallback( - const void *input, void *output, - unsigned long frameCount, - const PaStreamCallbackTimeInfo* timeInfo, - PaStreamCallbackFlags statusFlags - ); + const void *input, void *output, unsigned long frameCount, const PaStreamCallbackTimeInfo *timeInfo, PaStreamCallbackFlags statusFlags); public: - static int StreamCallbackWrapper( - const void *input, void *output, - unsigned long frameCount, - const PaStreamCallbackTimeInfo* timeInfo, - PaStreamCallbackFlags statusFlags, - void *userData - ); + const void *input, void *output, unsigned long frameCount, const PaStreamCallbackTimeInfo *timeInfo, PaStreamCallbackFlags statusFlags, void *userData); static std::vector EnumerateDevices(SoundDevice::SysInfo sysInfo); private: - bool HasInputChannelsOnSameDevice() const; - static std::vector > EnumerateInputOnlyDevices(PaHostApiTypeId hostApiType); - + static std::vector> EnumerateInputOnlyDevices(PaHostApiTypeId hostApiType); }; @@ -111,10 +97,10 @@ }; -#endif // MPT_WITH_PORTAUDIO +#endif // MPT_WITH_PORTAUDIO -} // namespace SoundDevice +} // namespace SoundDevice OPENMPT_NAMESPACE_END Index: sounddev/SoundDevicePulseSimple.cpp =================================================================== --- sounddev/SoundDevicePulseSimple.cpp (revision 14154) +++ sounddev/SoundDevicePulseSimple.cpp (working copy) @@ -25,7 +25,8 @@ //#define MPT_PULSEAUDIO_SIMPLE_ENUMERATE_DEVICES -namespace SoundDevice { +namespace SoundDevice +{ #if defined(MPT_WITH_PULSEAUDIO) && defined(MPT_WITH_PULSEAUDIOSIMPLE) @@ -55,10 +56,10 @@ #ifdef MPT_PULSEAUDIO_SIMPLE_ENUMERATE_DEVICES -static void PulseAudioSinkInfoListCallback(pa_context * /* c */ , const pa_sink_info *i, int /* eol */ , void *userdata) +static void PulseAudioSinkInfoListCallback(pa_context * /* c */, const pa_sink_info *i, int /* eol */, void *userdata) { MPT_LOG(LogDebug, "sounddev", U_("PulseAudioSinkInfoListCallback")); - std::vector *devices_ = reinterpret_cast*>(userdata); + std::vector *devices_ = reinterpret_cast *>(userdata); if(!devices_) { return; @@ -96,35 +97,34 @@ continue; } SoundDevice::Info info; - #if defined(MPT_ENABLE_PULSEAUDIO_FULL) - info.type = U_("PulseAudio-Simple"); - #else // !MPT_ENABLE_PULSEAUDIO_FULL - info.type = U_("PulseAudio"); - #endif // MPT_ENABLE_PULSEAUDIO_FULL +#if defined(MPT_ENABLE_PULSEAUDIO_FULL) + info.type = U_("PulseAudio-Simple"); +#else // !MPT_ENABLE_PULSEAUDIO_FULL + info.type = U_("PulseAudio"); +#endif // MPT_ENABLE_PULSEAUDIO_FULL info.internalID = mpt::ToUnicode(mpt::Charset::UTF8, i->name); - info.name = mpt::ToUnicode(mpt::Charset::UTF8, i->description); - #if defined(MPT_ENABLE_PULSEAUDIO_FULL) - info.apiName = U_("PulseAudio Simple API"); - #else - info.apiName = U_("PulseAudio"); - #endif - info.default_ = Info::Default::None; + info.name = mpt::ToUnicode(mpt::Charset::UTF8, i->description); +#if defined(MPT_ENABLE_PULSEAUDIO_FULL) + info.apiName = U_("PulseAudio Simple API"); +#else + info.apiName = U_("PulseAudio"); +#endif + info.default_ = Info::Default::None; info.useNameAsIdentifier = false; - info.flags = { - sysInfo.SystemClass == mpt::OS::Class::Linux ? Info::Usability::Usable : Info::Usability::Experimental, - Info::Level::Primary, - Info::Compatible::No, - sysInfo.SystemClass == mpt::OS::Class::Linux ? Info::Api::Native : Info::Api::Emulated, - Info::Io::FullDuplex, - Info::Mixing::Server, - Info::Implementor::External - }; + info.flags = { + sysInfo.SystemClass == mpt::OS::Class::Linux ? Info::Usability::Usable : Info::Usability::Experimental, + Info::Level::Primary, + Info::Compatible::No, + sysInfo.SystemClass == mpt::OS::Class::Linux ? Info::Api::Native : Info::Api::Emulated, + Info::Io::FullDuplex, + Info::Mixing::Server, + Info::Implementor::External}; devices.push_back(info); break; } } -#endif // MPT_PULSEAUDIO_SIMPLE_ENUMERATE_DEVICES +#endif // MPT_PULSEAUDIO_SIMPLE_ENUMERATE_DEVICES std::vector PulseaudioSimple::EnumerateDevices(SoundDevice::SysInfo sysInfo) @@ -131,69 +131,68 @@ { std::vector devices; SoundDevice::Info info; - #if defined(MPT_ENABLE_PULSEAUDIO_FULL) - info.type = U_("PulseAudio-Simple"); - #else // !MPT_ENABLE_PULSEAUDIO_FULL - info.type = U_("PulseAudio"); - #endif // MPT_ENABLE_PULSEAUDIO_FULL +#if defined(MPT_ENABLE_PULSEAUDIO_FULL) + info.type = U_("PulseAudio-Simple"); +#else // !MPT_ENABLE_PULSEAUDIO_FULL + info.type = U_("PulseAudio"); +#endif // MPT_ENABLE_PULSEAUDIO_FULL info.internalID = U_("0"); - info.name = U_("Default Device"); - #if defined(MPT_ENABLE_PULSEAUDIO_FULL) - info.apiName = U_("PulseAudio Simple API"); - #else - info.apiName = U_("PulseAudio"); - #endif - info.default_ = Info::Default::Managed; + info.name = U_("Default Device"); +#if defined(MPT_ENABLE_PULSEAUDIO_FULL) + info.apiName = U_("PulseAudio Simple API"); +#else + info.apiName = U_("PulseAudio"); +#endif + info.default_ = Info::Default::Managed; info.useNameAsIdentifier = false; - info.flags = { - sysInfo.SystemClass == mpt::OS::Class::Linux ? Info::Usability::Usable : Info::Usability::Experimental, - Info::Level::Primary, - Info::Compatible::No, - sysInfo.SystemClass == mpt::OS::Class::Linux ? Info::Api::Native : Info::Api::Emulated, - Info::Io::FullDuplex, - Info::Mixing::Server, - Info::Implementor::External - }; + info.flags = { + sysInfo.SystemClass == mpt::OS::Class::Linux ? Info::Usability::Usable : Info::Usability::Experimental, + Info::Level::Primary, + Info::Compatible::No, + sysInfo.SystemClass == mpt::OS::Class::Linux ? Info::Api::Native : Info::Api::Emulated, + Info::Io::FullDuplex, + Info::Mixing::Server, + Info::Implementor::External}; devices.push_back(info); - #ifdef MPT_PULSEAUDIO_SIMPLE_ENUMERATE_DEVICES +#ifdef MPT_PULSEAUDIO_SIMPLE_ENUMERATE_DEVICES - int result = 0; - pa_mainloop *m = nullptr; - pa_context *c = nullptr; - bool doneConnect = false; - pa_context_state_t cs = PA_CONTEXT_UNCONNECTED; - pa_operation *o = nullptr; - pa_operation_state_t s = PA_OPERATION_RUNNING; + int result = 0; + pa_mainloop *m = nullptr; + pa_context *c = nullptr; + bool doneConnect = false; + pa_context_state_t cs = PA_CONTEXT_UNCONNECTED; + pa_operation *o = nullptr; + pa_operation_state_t s = PA_OPERATION_RUNNING; - m = pa_mainloop_new(); - if(!m) + m = pa_mainloop_new(); + if(!m) + { + MPT_LOG(LogError, "sounddev", U_("pa_mainloop_new")); + goto cleanup; + } + c = pa_context_new(pa_mainloop_get_api(m), mpt::ToCharset(mpt::Charset::UTF8, mpt::ustring()).c_str()); // TODO: get AppInfo + if(!c) + { + MPT_LOG(LogError, "sounddev", U_("pa_context_new")); + goto cleanup; + } + if(pa_context_connect(c, NULL, PA_CONTEXT_NOFLAGS, NULL) < 0) + { + MPT_LOG(LogError, "sounddev", U_("pa_context_connect")); + goto cleanup; + } + doneConnect = false; + while(!doneConnect) + { + if(pa_mainloop_iterate(m, 1, &result) < 0) { - MPT_LOG(LogError, "sounddev", U_("pa_mainloop_new")); + MPT_LOG(LogError, "sounddev", U_("pa_mainloop_iterate")); goto cleanup; } - c = pa_context_new(pa_mainloop_get_api(m), mpt::ToCharset(mpt::Charset::UTF8, mpt::ustring()).c_str()); // TODO: get AppInfo - if(!c) + cs = pa_context_get_state(c); + switch(cs) { - MPT_LOG(LogError, "sounddev", U_("pa_context_new")); - goto cleanup; - } - if(pa_context_connect(c, NULL, PA_CONTEXT_NOFLAGS, NULL) < 0) - { - MPT_LOG(LogError, "sounddev", U_("pa_context_connect")); - goto cleanup; - } - doneConnect = false; - while(!doneConnect) - { - if(pa_mainloop_iterate(m, 1, &result) < 0) - { - MPT_LOG(LogError, "sounddev", U_("pa_mainloop_iterate")); - goto cleanup; - } - cs = pa_context_get_state(c); - switch(cs) - { case PA_CONTEXT_UNCONNECTED: case PA_CONTEXT_CONNECTING: case PA_CONTEXT_AUTHORIZING: @@ -205,57 +204,57 @@ case PA_CONTEXT_FAILED: case PA_CONTEXT_TERMINATED: default: - { - MPT_LOG(LogError, "sounddev", U_("pa_context_connect")); - goto cleanup; - } - break; - } - } - o = pa_context_get_sink_info_list(c, &PulseAudioSinkInfoListCallback, &devices); - if(!o) - { - MPT_LOG(LogError, "sounddev", U_("pa_context_get_sink_info_list: ") + PulseErrorString(pa_context_errno(c))); - goto cleanup; - } - s = PA_OPERATION_RUNNING; - while((s = pa_operation_get_state(o)) == PA_OPERATION_RUNNING) - { - if(pa_mainloop_iterate(m, 1, &result) < 0) { - MPT_LOG(LogError, "sounddev", U_("pa_mainloop_iterate")); + MPT_LOG(LogError, "sounddev", U_("pa_context_connect")); goto cleanup; } + break; } - if(s == PA_OPERATION_CANCELLED) + } + o = pa_context_get_sink_info_list(c, &PulseAudioSinkInfoListCallback, &devices); + if(!o) + { + MPT_LOG(LogError, "sounddev", U_("pa_context_get_sink_info_list: ") + PulseErrorString(pa_context_errno(c))); + goto cleanup; + } + s = PA_OPERATION_RUNNING; + while((s = pa_operation_get_state(o)) == PA_OPERATION_RUNNING) + { + if(pa_mainloop_iterate(m, 1, &result) < 0) { - MPT_LOG(LogError, "sounddev", U_("pa_operation_get_state")); + MPT_LOG(LogError, "sounddev", U_("pa_mainloop_iterate")); goto cleanup; } + } + if(s == PA_OPERATION_CANCELLED) + { + MPT_LOG(LogError, "sounddev", U_("pa_operation_get_state")); goto cleanup; + } + goto cleanup; - cleanup: +cleanup: - if(o) - { - pa_operation_unref(o); - o = nullptr; - } - if(c) - { - pa_context_disconnect(c); - pa_context_unref(c); - c = nullptr; - } - if(m) - { - pa_mainloop_quit(m, 0); - pa_mainloop_run(m, &result); - pa_mainloop_free(m); - m = nullptr; - } + if(o) + { + pa_operation_unref(o); + o = nullptr; + } + if(c) + { + pa_context_disconnect(c); + pa_context_unref(c); + c = nullptr; + } + if(m) + { + pa_mainloop_quit(m, 0); + pa_mainloop_run(m, &result); + pa_mainloop_free(m); + m = nullptr; + } - #endif // MPT_PULSEAUDIO_SIMPLE_ENUMERATE_DEVICES +#endif // MPT_PULSEAUDIO_SIMPLE_ENUMERATE_DEVICES return devices; } @@ -273,23 +272,23 @@ SoundDevice::Caps PulseaudioSimple::InternalGetDeviceCaps() { SoundDevice::Caps caps; - caps.Available = true; // TODO: poll PulseAudio - caps.CanUpdateInterval = true; - caps.CanSampleFormat = false; - caps.CanExclusiveMode = true; - caps.CanBoostThreadPriority = true; - caps.CanKeepDeviceRunning = false; - caps.CanUseHardwareTiming = false; - caps.CanChannelMapping = false; - caps.CanInput = false; - caps.HasNamedInputSources = false; - caps.CanDriverPanel = false; - caps.HasInternalDither = false; - caps.ExclusiveModeDescription = U_("Adjust latency"); - caps.DefaultSettings.Latency = 0.030; + caps.Available = true; // TODO: poll PulseAudio + caps.CanUpdateInterval = true; + caps.CanSampleFormat = false; + caps.CanExclusiveMode = true; + caps.CanBoostThreadPriority = true; + caps.CanKeepDeviceRunning = false; + caps.CanUseHardwareTiming = false; + caps.CanChannelMapping = false; + caps.CanInput = false; + caps.HasNamedInputSources = false; + caps.CanDriverPanel = false; + caps.HasInternalDither = false; + caps.ExclusiveModeDescription = U_("Adjust latency"); + caps.DefaultSettings.Latency = 0.030; caps.DefaultSettings.UpdateInterval = 0.005; - caps.DefaultSettings.sampleFormat = SampleFormatFloat32; - caps.DefaultSettings.ExclusiveMode = true; + caps.DefaultSettings.sampleFormat = SampleFormatFloat32; + caps.DefaultSettings.ExclusiveMode = true; return caps; } @@ -297,10 +296,10 @@ SoundDevice::DynamicCaps PulseaudioSimple::GetDeviceDynamicCaps(const std::vector &baseSampleRates) { SoundDevice::DynamicCaps caps; - caps.supportedSampleRates = baseSampleRates; - caps.supportedExclusiveSampleRates = baseSampleRates; - caps.supportedSampleFormats = { SampleFormatFloat32 }; - caps.supportedExclusiveModeSampleFormats = { SampleFormatFloat32 }; + caps.supportedSampleRates = baseSampleRates; + caps.supportedExclusiveSampleRates = baseSampleRates; + caps.supportedSampleFormats = {SampleFormatFloat32}; + caps.supportedExclusiveModeSampleFormats = {SampleFormatFloat32}; return caps; } @@ -321,21 +320,21 @@ int error = 0; pa_sample_spec ss; MemsetZero(ss); - ss.format = PA_SAMPLE_FLOAT32; - ss.rate = m_Settings.Samplerate; + ss.format = PA_SAMPLE_FLOAT32; + ss.rate = m_Settings.Samplerate; ss.channels = m_Settings.Channels; pa_buffer_attr ba; MemsetZero(ba); - ba.minreq = Util::AlignUp(mpt::saturate_round(m_Settings.GetBytesPerSecond() * m_Settings.UpdateInterval), m_Settings.GetBytesPerFrame()); - ba.maxlength = Util::AlignUp(mpt::saturate_round(m_Settings.GetBytesPerSecond() * m_Settings.Latency), m_Settings.GetBytesPerFrame()); - ba.tlength = ba.maxlength - ba.minreq; - ba.prebuf = ba.tlength; - ba.fragsize = 0; - m_EffectiveBufferAttributes = SoundDevice::BufferAttributes(); - m_EffectiveBufferAttributes.Latency = static_cast(ba.maxlength) / static_cast(m_Settings.GetBytesPerSecond()); + ba.minreq = Util::AlignUp(mpt::saturate_round(m_Settings.GetBytesPerSecond() * m_Settings.UpdateInterval), m_Settings.GetBytesPerFrame()); + ba.maxlength = Util::AlignUp(mpt::saturate_round(m_Settings.GetBytesPerSecond() * m_Settings.Latency), m_Settings.GetBytesPerFrame()); + ba.tlength = ba.maxlength - ba.minreq; + ba.prebuf = ba.tlength; + ba.fragsize = 0; + m_EffectiveBufferAttributes = SoundDevice::BufferAttributes(); + m_EffectiveBufferAttributes.Latency = static_cast(ba.maxlength) / static_cast(m_Settings.GetBytesPerSecond()); m_EffectiveBufferAttributes.UpdateInterval = static_cast(ba.minreq) / static_cast(m_Settings.GetBytesPerSecond()); - m_EffectiveBufferAttributes.NumBuffers = 1; - m_OutputBuffer.resize(ba.minreq / (m_Settings.sampleFormat.GetBitsPerSample()/8)); + m_EffectiveBufferAttributes.NumBuffers = 1; + m_OutputBuffer.resize(ba.minreq / (m_Settings.sampleFormat.GetBitsPerSample() / 8)); m_PA_SimpleOutput = pa_simple_new( NULL, mpt::ToCharset(mpt::Charset::UTF8, m_AppInfo.GetName()).c_str(), @@ -364,9 +363,9 @@ void PulseaudioSimple::InternalFillAudioBuffer() { - bool needsClose = false; - int error = 0; - error = 0; + bool needsClose = false; + int error = 0; + error = 0; pa_usec_t latency_usec = pa_simple_get_latency(m_PA_SimpleOutput, &error); if(error != 0) { @@ -420,8 +419,8 @@ { SoundDevice::Statistics stats; stats.InstantaneousLatency = static_cast(m_StatisticLastLatencyFrames.load()) / static_cast(m_Settings.Samplerate); - stats.LastUpdateInterval = m_EffectiveBufferAttributes.UpdateInterval; - stats.text = mpt::ustring(); + stats.LastUpdateInterval = m_EffectiveBufferAttributes.UpdateInterval; + stats.text = mpt::ustring(); return stats; } @@ -428,12 +427,12 @@ void PulseaudioSimple::InternalStopFromSoundThread() { - int error = 0; - bool oldVersion = false; + int error = 0; + bool oldVersion = false; std::vector version = mpt::String::Split(mpt::ToUnicode(mpt::Charset::UTF8, pa_get_library_version() ? pa_get_library_version() : "")); if(!version.empty()) { - if(version[0] <4) + if(version[0] < 4) { oldVersion = true; } @@ -478,10 +477,10 @@ } -#endif // MPT_WITH_PULSEAUDIO && MPT_WITH_PULSEAUDIOSIMPLE +#endif // MPT_WITH_PULSEAUDIO && MPT_WITH_PULSEAUDIOSIMPLE -} // namespace SoundDevice +} // namespace SoundDevice OPENMPT_NAMESPACE_END Index: sounddev/SoundDevicePulseSimple.h =================================================================== --- sounddev/SoundDevicePulseSimple.h (revision 14154) +++ sounddev/SoundDevicePulseSimple.h (working copy) @@ -21,13 +21,14 @@ #if defined(MPT_WITH_PULSEAUDIO) && defined(MPT_WITH_PULSEAUDIOSIMPLE) #include #include -#endif // MPT_WITH_PULSEAUDIO && MPT_WITH_PULSEAUDIOSIMPLE +#endif // MPT_WITH_PULSEAUDIO && MPT_WITH_PULSEAUDIOSIMPLE OPENMPT_NAMESPACE_BEGIN -namespace SoundDevice { +namespace SoundDevice +{ #if defined(MPT_WITH_PULSEAUDIO) && defined(MPT_WITH_PULSEAUDIOSIMPLE) @@ -38,8 +39,8 @@ { MPT_DECLARE_COMPONENT_MEMBERS public: - ComponentPulseaudioSimple() { } - virtual ~ComponentPulseaudioSimple() { } + ComponentPulseaudioSimple() {} + virtual ~ComponentPulseaudioSimple() {} bool DoInitialize() override { return true; } }; @@ -49,8 +50,10 @@ { private: static mpt::ustring PulseErrorString(int error); + public: static std::vector EnumerateDevices(SoundDevice::SysInfo sysInfo); + public: PulseaudioSimple(SoundDevice::Info info, SoundDevice::SysInfo sysInfo); SoundDevice::Caps InternalGetDeviceCaps(); @@ -65,8 +68,9 @@ void InternalStopFromSoundThread(); bool InternalClose(); ~PulseaudioSimple(); + private: - pa_simple * m_PA_SimpleOutput; + pa_simple *m_PA_SimpleOutput; SoundDevice::BufferAttributes m_EffectiveBufferAttributes; std::vector m_OutputBuffer; std::atomic m_StatisticLastLatencyFrames; @@ -73,10 +77,10 @@ }; -#endif // MPT_WITH_PULSEAUDIO && MPT_WITH_PULSEAUDIOSIMPLE +#endif // MPT_WITH_PULSEAUDIO && MPT_WITH_PULSEAUDIOSIMPLE -} // namespace SoundDevice +} // namespace SoundDevice OPENMPT_NAMESPACE_END Index: sounddev/SoundDevicePulseaudio.cpp =================================================================== --- sounddev/SoundDevicePulseaudio.cpp (revision 14154) +++ sounddev/SoundDevicePulseaudio.cpp (working copy) @@ -22,7 +22,8 @@ OPENMPT_NAMESPACE_BEGIN -namespace SoundDevice { +namespace SoundDevice +{ #if defined(MPT_ENABLE_PULSEAUDIO_FULL) @@ -52,10 +53,10 @@ } -static void PulseAudioSinkInfoListCallback(pa_context * /* c */ , const pa_sink_info *i, int /* eol */ , void *userdata) +static void PulseAudioSinkInfoListCallback(pa_context * /* c */, const pa_sink_info *i, int /* eol */, void *userdata) { MPT_LOG(LogDebug, "sounddev", U_("PulseAudioSinkInfoListCallback")); - std::vector *devices_ = reinterpret_cast*>(userdata); + std::vector *devices_ = reinterpret_cast *>(userdata); if(!devices_) { return; @@ -93,21 +94,20 @@ continue; } SoundDevice::Info info; - info.type = U_("PulseAudio"); - info.internalID = mpt::ToUnicode(mpt::Charset::UTF8, i->name); - info.name = mpt::ToUnicode(mpt::Charset::UTF8, i->description); - info.apiName = U_("PulseAudio"); - info.default_ = Info::Default::None; + info.type = U_("PulseAudio"); + info.internalID = mpt::ToUnicode(mpt::Charset::UTF8, i->name); + info.name = mpt::ToUnicode(mpt::Charset::UTF8, i->description); + info.apiName = U_("PulseAudio"); + info.default_ = Info::Default::None; info.useNameAsIdentifier = false; - info.flags = { - sysInfo.SystemClass == mpt::OS::Class::Linux ? Info::Usability::Usable : Info::Usability::Experimental, - Info::Level::Primary, - Info::Compatible::No, - sysInfo.SystemClass == mpt::OS::Class::Linux ? Info::Api::Native : Info::Api::Emulated, - Info::Io::FullDuplex, - Info::Mixing::Server, - Info::Implementor::External - }; + info.flags = { + sysInfo.SystemClass == mpt::OS::Class::Linux ? Info::Usability::Usable : Info::Usability::Experimental, + Info::Level::Primary, + Info::Compatible::No, + sysInfo.SystemClass == mpt::OS::Class::Linux ? Info::Api::Native : Info::Api::Emulated, + Info::Io::FullDuplex, + Info::Mixing::Server, + Info::Implementor::External}; devices.push_back(info); break; } @@ -118,29 +118,28 @@ { std::vector devices; SoundDevice::Info info; - info.type = U_("PulseAudio"); - info.internalID = U_("0"); - info.name = U_("Default Device"); - info.apiName = U_("PulseAudio"); - info.default_ = Info::Default::Managed; + info.type = U_("PulseAudio"); + info.internalID = U_("0"); + info.name = U_("Default Device"); + info.apiName = U_("PulseAudio"); + info.default_ = Info::Default::Managed; info.useNameAsIdentifier = false; - info.flags = { - sysInfo.SystemClass == mpt::OS::Class::Linux ? Info::Usability::Usable : Info::Usability::Experimental, - Info::Level::Primary, - Info::Compatible::No, - sysInfo.SystemClass == mpt::OS::Class::Linux ? Info::Api::Native : Info::Api::Emulated, - Info::Io::FullDuplex, - Info::Mixing::Server, - Info::Implementor::External - }; + info.flags = { + sysInfo.SystemClass == mpt::OS::Class::Linux ? Info::Usability::Usable : Info::Usability::Experimental, + Info::Level::Primary, + Info::Compatible::No, + sysInfo.SystemClass == mpt::OS::Class::Linux ? Info::Api::Native : Info::Api::Emulated, + Info::Io::FullDuplex, + Info::Mixing::Server, + Info::Implementor::External}; devices.push_back(info); - int result = 0; - pa_mainloop *m = nullptr; - pa_context *c = nullptr; - bool doneConnect = false; - pa_context_state_t cs = PA_CONTEXT_UNCONNECTED; - pa_operation *o = nullptr; + int result = 0; + pa_mainloop *m = nullptr; + pa_context *c = nullptr; + bool doneConnect = false; + pa_context_state_t cs = PA_CONTEXT_UNCONNECTED; + pa_operation *o = nullptr; pa_operation_state_t s = PA_OPERATION_RUNNING; m = pa_mainloop_new(); @@ -149,7 +148,7 @@ MPT_LOG(LogError, "sounddev", U_("pa_mainloop_new")); goto cleanup; } - c = pa_context_new(pa_mainloop_get_api(m), mpt::ToCharset(mpt::Charset::UTF8, mpt::ustring()).c_str()); // TODO: get AppInfo + c = pa_context_new(pa_mainloop_get_api(m), mpt::ToCharset(mpt::Charset::UTF8, mpt::ustring()).c_str()); // TODO: get AppInfo if(!c) { MPT_LOG(LogError, "sounddev", U_("pa_context_new")); @@ -171,17 +170,17 @@ cs = pa_context_get_state(c); switch(cs) { - case PA_CONTEXT_UNCONNECTED: - case PA_CONTEXT_CONNECTING: - case PA_CONTEXT_AUTHORIZING: - case PA_CONTEXT_SETTING_NAME: - break; - case PA_CONTEXT_READY: - doneConnect = true; - break; - case PA_CONTEXT_FAILED: - case PA_CONTEXT_TERMINATED: - default: + case PA_CONTEXT_UNCONNECTED: + case PA_CONTEXT_CONNECTING: + case PA_CONTEXT_AUTHORIZING: + case PA_CONTEXT_SETTING_NAME: + break; + case PA_CONTEXT_READY: + doneConnect = true; + break; + case PA_CONTEXT_FAILED: + case PA_CONTEXT_TERMINATED: + default: { MPT_LOG(LogError, "sounddev", U_("pa_context_connect")); goto cleanup; @@ -211,26 +210,26 @@ } goto cleanup; - cleanup: +cleanup: - if(o) - { - pa_operation_unref(o); - o = nullptr; - } - if(c) - { - pa_context_disconnect(c); - pa_context_unref(c); - c = nullptr; - } - if(m) - { - pa_mainloop_quit(m, 0); - pa_mainloop_run(m, &result); - pa_mainloop_free(m); - m = nullptr; - } + if(o) + { + pa_operation_unref(o); + o = nullptr; + } + if(c) + { + pa_context_disconnect(c); + pa_context_unref(c); + c = nullptr; + } + if(m) + { + pa_mainloop_quit(m, 0); + pa_mainloop_run(m, &result); + pa_mainloop_free(m); + m = nullptr; + } return devices; } @@ -248,23 +247,23 @@ SoundDevice::Caps Pulseaudio::InternalGetDeviceCaps() { SoundDevice::Caps caps; - caps.Available = true; // TODO: poll PulseAudio - caps.CanUpdateInterval = true; - caps.CanSampleFormat = false; - caps.CanExclusiveMode = true; - caps.CanBoostThreadPriority = true; - caps.CanKeepDeviceRunning = false; - caps.CanUseHardwareTiming = true; - caps.CanChannelMapping = false; - caps.CanInput = false; - caps.HasNamedInputSources = false; - caps.CanDriverPanel = false; - caps.HasInternalDither = false; - caps.ExclusiveModeDescription = U_("Use early requests"); - caps.DefaultSettings.Latency = 0.030; + caps.Available = true; // TODO: poll PulseAudio + caps.CanUpdateInterval = true; + caps.CanSampleFormat = false; + caps.CanExclusiveMode = true; + caps.CanBoostThreadPriority = true; + caps.CanKeepDeviceRunning = false; + caps.CanUseHardwareTiming = true; + caps.CanChannelMapping = false; + caps.CanInput = false; + caps.HasNamedInputSources = false; + caps.CanDriverPanel = false; + caps.HasInternalDither = false; + caps.ExclusiveModeDescription = U_("Use early requests"); + caps.DefaultSettings.Latency = 0.030; caps.DefaultSettings.UpdateInterval = 0.005; - caps.DefaultSettings.sampleFormat = SampleFormatFloat32; - caps.DefaultSettings.ExclusiveMode = true; + caps.DefaultSettings.sampleFormat = SampleFormatFloat32; + caps.DefaultSettings.ExclusiveMode = true; return caps; } @@ -272,10 +271,10 @@ SoundDevice::DynamicCaps Pulseaudio::GetDeviceDynamicCaps(const std::vector &baseSampleRates) { SoundDevice::DynamicCaps caps; - caps.supportedSampleRates = baseSampleRates; - caps.supportedExclusiveSampleRates = baseSampleRates; - caps.supportedSampleFormats = { SampleFormatFloat32 }; - caps.supportedExclusiveModeSampleFormats = { SampleFormatFloat32 }; + caps.supportedSampleRates = baseSampleRates; + caps.supportedExclusiveSampleRates = baseSampleRates; + caps.supportedSampleFormats = {SampleFormatFloat32}; + caps.supportedExclusiveModeSampleFormats = {SampleFormatFloat32}; return caps; } @@ -296,21 +295,21 @@ int error = 0; pa_sample_spec ss; MemsetZero(ss); - ss.format = PA_SAMPLE_FLOAT32; - ss.rate = m_Settings.Samplerate; + ss.format = PA_SAMPLE_FLOAT32; + ss.rate = m_Settings.Samplerate; ss.channels = m_Settings.Channels; pa_buffer_attr ba; MemsetZero(ba); - ba.minreq = Util::AlignUp(mpt::saturate_round(m_Settings.GetBytesPerSecond() * m_Settings.UpdateInterval), m_Settings.GetBytesPerFrame()); - ba.maxlength = Util::AlignUp(mpt::saturate_round(m_Settings.GetBytesPerSecond() * m_Settings.Latency), m_Settings.GetBytesPerFrame()); - ba.tlength = ba.maxlength - ba.minreq; - ba.prebuf = ba.tlength; - ba.fragsize = 0; - m_EffectiveBufferAttributes = SoundDevice::BufferAttributes(); - m_EffectiveBufferAttributes.Latency = static_cast(ba.maxlength) / static_cast(m_Settings.GetBytesPerSecond()); + ba.minreq = Util::AlignUp(mpt::saturate_round(m_Settings.GetBytesPerSecond() * m_Settings.UpdateInterval), m_Settings.GetBytesPerFrame()); + ba.maxlength = Util::AlignUp(mpt::saturate_round(m_Settings.GetBytesPerSecond() * m_Settings.Latency), m_Settings.GetBytesPerFrame()); + ba.tlength = ba.maxlength - ba.minreq; + ba.prebuf = ba.tlength; + ba.fragsize = 0; + m_EffectiveBufferAttributes = SoundDevice::BufferAttributes(); + m_EffectiveBufferAttributes.Latency = static_cast(ba.maxlength) / static_cast(m_Settings.GetBytesPerSecond()); m_EffectiveBufferAttributes.UpdateInterval = static_cast(ba.minreq) / static_cast(m_Settings.GetBytesPerSecond()); - m_EffectiveBufferAttributes.NumBuffers = 1; - m_OutputBuffer.resize(ba.minreq / (m_Settings.sampleFormat.GetBitsPerSample()/8)); + m_EffectiveBufferAttributes.NumBuffers = 1; + m_OutputBuffer.resize(ba.minreq / (m_Settings.sampleFormat.GetBitsPerSample() / 8)); m_PA_SimpleOutput = pa_simple_new( NULL, mpt::ToCharset(mpt::Charset::UTF8, m_AppInfo.GetName()).c_str(), @@ -339,9 +338,9 @@ void Pulseaudio::InternalFillAudioBuffer() { - bool needsClose = false; - int error = 0; - error = 0; + bool needsClose = false; + int error = 0; + error = 0; pa_usec_t latency_usec = pa_simple_get_latency(m_PA_SimpleOutput, &error); if(error != 0) { @@ -395,8 +394,8 @@ { SoundDevice::Statistics stats; stats.InstantaneousLatency = static_cast(m_StatisticLastLatencyFrames.load()) / static_cast(m_Settings.Samplerate); - stats.LastUpdateInterval = m_EffectiveBufferAttributes.UpdateInterval; - stats.text = mpt::ustring(); + stats.LastUpdateInterval = m_EffectiveBufferAttributes.UpdateInterval; + stats.text = mpt::ustring(); return stats; } @@ -403,12 +402,12 @@ void Pulseaudio::InternalStopFromSoundThread() { - int error = 0; - bool oldVersion = false; + int error = 0; + bool oldVersion = false; std::vector version = mpt::String::Split(mpt::ToUnicode(mpt::Charset::UTF8, pa_get_library_version() ? pa_get_library_version() : "")); if(!version.empty()) { - if(version[0] <4) + if(version[0] < 4) { oldVersion = true; } @@ -453,12 +452,12 @@ } -#endif // MPT_WITH_PULSEAUDIO +#endif // MPT_WITH_PULSEAUDIO -#endif // MPT_ENABLE_PULSEAUDIO_FULL +#endif // MPT_ENABLE_PULSEAUDIO_FULL -} // namespace SoundDevice +} // namespace SoundDevice OPENMPT_NAMESPACE_END Index: sounddev/SoundDevicePulseaudio.h =================================================================== --- sounddev/SoundDevicePulseaudio.h (revision 14154) +++ sounddev/SoundDevicePulseaudio.h (working copy) @@ -22,14 +22,15 @@ #if defined(MPT_WITH_PULSEAUDIO) #include #include -#endif // MPT_WITH_PULSEAUDIO -#endif // MPT_ENABLE_PULSEAUDIO_FULL +#endif // MPT_WITH_PULSEAUDIO +#endif // MPT_ENABLE_PULSEAUDIO_FULL OPENMPT_NAMESPACE_BEGIN -namespace SoundDevice { +namespace SoundDevice +{ #if defined(MPT_ENABLE_PULSEAUDIO_FULL) @@ -42,8 +43,8 @@ { MPT_DECLARE_COMPONENT_MEMBERS public: - ComponentPulseaudio() { } - virtual ~ComponentPulseaudio() { } + ComponentPulseaudio() {} + virtual ~ComponentPulseaudio() {} bool DoInitialize() override { return true; } }; @@ -53,8 +54,10 @@ { private: static mpt::ustring PulseErrorString(int error); + public: static std::vector EnumerateDevices(SoundDevice::SysInfo sysInfo); + public: Pulseaudio(SoundDevice::Info info, SoundDevice::SysInfo sysInfo); SoundDevice::Caps InternalGetDeviceCaps(); @@ -69,8 +72,9 @@ void InternalStopFromSoundThread(); bool InternalClose(); ~Pulseaudio(); + private: - pa_simple * m_PA_SimpleOutput; + pa_simple *m_PA_SimpleOutput; SoundDevice::BufferAttributes m_EffectiveBufferAttributes; std::vector m_OutputBuffer; std::atomic m_StatisticLastLatencyFrames; @@ -77,12 +81,12 @@ }; -#endif // MPT_WITH_PULSEAUDIO +#endif // MPT_WITH_PULSEAUDIO -#endif // MPT_ENABLE_PULSEAUDIO_FULL +#endif // MPT_ENABLE_PULSEAUDIO_FULL -} // namespace SoundDevice +} // namespace SoundDevice OPENMPT_NAMESPACE_END Index: sounddev/SoundDeviceRtAudio.cpp =================================================================== --- sounddev/SoundDeviceRtAudio.cpp (revision 14154) +++ sounddev/SoundDeviceRtAudio.cpp (working copy) @@ -20,7 +20,8 @@ OPENMPT_NAMESPACE_BEGIN -namespace SoundDevice { +namespace SoundDevice +{ #ifdef MPT_WITH_RTAUDIO @@ -33,17 +34,17 @@ { switch(sampleFormat.GetBitsPerSample()) { - case 32: result = RTAUDIO_FLOAT32; break; - case 64: result = RTAUDIO_FLOAT64; break; + case 32: result = RTAUDIO_FLOAT32; break; + case 64: result = RTAUDIO_FLOAT64; break; } } else if(sampleFormat.IsInt()) { switch(sampleFormat.GetBitsPerSample()) { - case 8: result = RTAUDIO_SINT8; break; - case 16: result = RTAUDIO_SINT16; break; - case 24: result = RTAUDIO_SINT24; break; - case 32: result = RTAUDIO_SINT32; break; + case 8: result = RTAUDIO_SINT8; break; + case 16: result = RTAUDIO_SINT16; break; + case 24: result = RTAUDIO_SINT24; break; + case 32: result = RTAUDIO_SINT32; break; } } return result; @@ -56,15 +57,15 @@ , m_FramesPerChunk(0) { m_CurrentFrameBufferOutput = nullptr; - m_CurrentFrameBufferInput = nullptr; - m_CurrentFrameBufferCount = 0; - m_CurrentStreamTime = 0.0; + m_CurrentFrameBufferInput = nullptr; + m_CurrentFrameBufferCount = 0; + m_CurrentStreamTime = 0.0; m_StatisticLatencyFrames.store(0); m_StatisticPeriodFrames.store(0); try { m_RtAudio = std::make_unique(GetApi(info)); - } catch (const RtAudioError &) + } catch(const RtAudioError &) { // nothing } @@ -86,20 +87,20 @@ return false; } if(ChannelMapping::BaseChannel(m_Settings.Channels, m_Settings.Channels.ToDevice(0)) != m_Settings.Channels) - { // only simple base channel mappings are supported + { // only simple base channel mappings are supported return false; } - m_OutputStreamParameters.deviceId = GetDevice(GetDeviceInfo()); - m_OutputStreamParameters.nChannels = m_Settings.Channels; + m_OutputStreamParameters.deviceId = GetDevice(GetDeviceInfo()); + m_OutputStreamParameters.nChannels = m_Settings.Channels; m_OutputStreamParameters.firstChannel = m_Settings.Channels.ToDevice(0); - m_InputStreamParameters.deviceId = GetDevice(GetDeviceInfo()); - m_InputStreamParameters.nChannels = m_Settings.InputChannels; - m_InputStreamParameters.firstChannel = m_Settings.InputSourceID; - m_FramesPerChunk = mpt::saturate_round(m_Settings.UpdateInterval * m_Settings.Samplerate); - m_StreamOptions.flags = RtAudioStreamFlags(); - m_StreamOptions.numberOfBuffers = mpt::saturate_round(m_Settings.Latency * m_Settings.Samplerate / m_FramesPerChunk); - m_StreamOptions.priority = 0; - m_StreamOptions.streamName = mpt::ToCharset(mpt::Charset::UTF8, m_AppInfo.GetName()); + m_InputStreamParameters.deviceId = GetDevice(GetDeviceInfo()); + m_InputStreamParameters.nChannels = m_Settings.InputChannels; + m_InputStreamParameters.firstChannel = m_Settings.InputSourceID; + m_FramesPerChunk = mpt::saturate_round(m_Settings.UpdateInterval * m_Settings.Samplerate); + m_StreamOptions.flags = RtAudioStreamFlags(); + m_StreamOptions.numberOfBuffers = mpt::saturate_round(m_Settings.Latency * m_Settings.Samplerate / m_FramesPerChunk); + m_StreamOptions.priority = 0; + m_StreamOptions.streamName = mpt::ToCharset(mpt::Charset::UTF8, m_AppInfo.GetName()); if(m_Settings.BoostThreadPriority) { m_StreamOptions.flags |= RTAUDIO_SCHEDULE_REALTIME; @@ -119,7 +120,7 @@ m_Flags.NeedsClippedFloat = GetSysInfo().IsOriginal(); } m_RtAudio->openStream((m_OutputStreamParameters.nChannels > 0) ? &m_OutputStreamParameters : nullptr, (m_InputStreamParameters.nChannels > 0) ? &m_InputStreamParameters : nullptr, SampleFormatToRtAudioFormat(m_Settings.sampleFormat), m_Settings.Samplerate, &m_FramesPerChunk, &RtAudioCallback, this, &m_StreamOptions, nullptr); - } catch (const RtAudioError &e) + } catch(const RtAudioError &e) { SendError(e); return false; @@ -133,7 +134,7 @@ try { m_RtAudio->closeStream(); - } catch (const RtAudioError &e) + } catch(const RtAudioError &e) { SendError(e); return false; @@ -147,7 +148,7 @@ try { m_RtAudio->startStream(); - } catch (const RtAudioError &e) + } catch(const RtAudioError &e) { SendError(e); return false; @@ -161,7 +162,7 @@ try { m_RtAudio->stopStream(); - } catch (const RtAudioError &e) + } catch(const RtAudioError &e) { SendError(e); return; @@ -193,9 +194,9 @@ SoundDevice::BufferAttributes CRtAudioDevice::InternalGetEffectiveBufferAttributes() const { SoundDevice::BufferAttributes bufferAttributes; - bufferAttributes.Latency = m_FramesPerChunk * m_StreamOptions.numberOfBuffers / static_cast(m_Settings.Samplerate); + bufferAttributes.Latency = m_FramesPerChunk * m_StreamOptions.numberOfBuffers / static_cast(m_Settings.Samplerate); bufferAttributes.UpdateInterval = m_FramesPerChunk / static_cast(m_Settings.Samplerate); - bufferAttributes.NumBuffers = m_StreamOptions.numberOfBuffers; + bufferAttributes.NumBuffers = m_StreamOptions.numberOfBuffers; return bufferAttributes; } @@ -202,8 +203,8 @@ int CRtAudioDevice::RtAudioCallback(void *outputBuffer, void *inputBuffer, unsigned int nFrames, double streamTime, RtAudioStreamStatus status, void *userData) { - reinterpret_cast(userData)->AudioCallback(outputBuffer, inputBuffer, nFrames, streamTime, status); - return 0; // continue + reinterpret_cast(userData)->AudioCallback(outputBuffer, inputBuffer, nFrames, streamTime, status); + return 0; // continue } @@ -210,13 +211,13 @@ void CRtAudioDevice::AudioCallback(void *outputBuffer, void *inputBuffer, unsigned int nFrames, double streamTime, RtAudioStreamStatus status) { m_CurrentFrameBufferOutput = outputBuffer; - m_CurrentFrameBufferInput = inputBuffer; - m_CurrentFrameBufferCount = nFrames; - m_CurrentStreamTime = streamTime; + m_CurrentFrameBufferInput = inputBuffer; + m_CurrentFrameBufferCount = nFrames; + m_CurrentStreamTime = streamTime; SourceFillAudioBufferLocked(); - m_CurrentFrameBufferCount = 0; + m_CurrentFrameBufferCount = 0; m_CurrentFrameBufferOutput = 0; - m_CurrentFrameBufferInput = 0; + m_CurrentFrameBufferInput = 0; if(status != RtAudioStreamStatus()) { // maybe @@ -247,11 +248,11 @@ if(latency > 0) { result.InstantaneousLatency = latency / static_cast(m_Settings.Samplerate); - result.LastUpdateInterval = m_StatisticPeriodFrames.load() / static_cast(m_Settings.Samplerate); + result.LastUpdateInterval = m_StatisticPeriodFrames.load() / static_cast(m_Settings.Samplerate); } else { result.InstantaneousLatency = m_StatisticLatencyFrames.load() / static_cast(m_Settings.Samplerate); - result.LastUpdateInterval = m_StatisticPeriodFrames.load() / static_cast(m_Settings.Samplerate); + result.LastUpdateInterval = m_StatisticPeriodFrames.load() / static_cast(m_Settings.Samplerate); } return result; } @@ -273,24 +274,24 @@ { return caps; } - caps.Available = rtinfo.probed; - caps.CanUpdateInterval = true; - caps.CanSampleFormat = true; - caps.CanExclusiveMode = true; - caps.CanBoostThreadPriority = true; - caps.CanKeepDeviceRunning = false; - caps.CanUseHardwareTiming = false; - caps.CanChannelMapping = false; // only base channel is supported, and that does not make too much sense for non-ASIO backends - caps.CanInput = (rtinfo.inputChannels > 0); - caps.HasNamedInputSources = true; - caps.CanDriverPanel = false; - caps.HasInternalDither = false; + caps.Available = rtinfo.probed; + caps.CanUpdateInterval = true; + caps.CanSampleFormat = true; + caps.CanExclusiveMode = true; + caps.CanBoostThreadPriority = true; + caps.CanKeepDeviceRunning = false; + caps.CanUseHardwareTiming = false; + caps.CanChannelMapping = false; // only base channel is supported, and that does not make too much sense for non-ASIO backends + caps.CanInput = (rtinfo.inputChannels > 0); + caps.HasNamedInputSources = true; + caps.CanDriverPanel = false; + caps.HasInternalDither = false; caps.ExclusiveModeDescription = U_("Exclusive Mode"); return caps; } -SoundDevice::DynamicCaps CRtAudioDevice::GetDeviceDynamicCaps(const std::vector & /* baseSampleRates */ ) +SoundDevice::DynamicCaps CRtAudioDevice::GetDeviceDynamicCaps(const std::vector & /* baseSampleRates */) { MPT_TRACE(); SoundDevice::DynamicCaps caps; @@ -315,7 +316,7 @@ std::reverse(caps.supportedSampleRates.begin(), caps.supportedSampleRates.end()); mpt::append(caps.supportedExclusiveSampleRates, rtinfo.sampleRates); std::reverse(caps.supportedExclusiveSampleRates.begin(), caps.supportedExclusiveSampleRates.end()); - caps.supportedSampleFormats = { SampleFormatFloat32 }; + caps.supportedSampleFormats = {SampleFormatFloat32}; caps.supportedExclusiveModeSampleFormats.clear(); if(rtinfo.nativeFormats & RTAUDIO_SINT8) { @@ -450,125 +451,117 @@ continue; } SoundDevice::Info info = SoundDevice::Info(); - info.type = U_("RtAudio") + U_("-") + mpt::ToUnicode(mpt::Charset::UTF8, RtAudio::getApiName(rtaudio.getCurrentApi())); + info.type = U_("RtAudio") + U_("-") + mpt::ToUnicode(mpt::Charset::UTF8, RtAudio::getApiName(rtaudio.getCurrentApi())); std::vector apidev; apidev.push_back(mpt::ToUnicode(mpt::Charset::UTF8, RtAudio::getApiName(rtaudio.getCurrentApi()))); apidev.push_back(mpt::ufmt::val(device)); - info.internalID = mpt::String::Combine(apidev, U_(",")); - info.name = mpt::ToUnicode(mpt::Charset::UTF8, rtinfo.name); - info.apiName = mpt::ToUnicode(mpt::Charset::UTF8, RtAudio::getApiDisplayName(rtaudio.getCurrentApi())); - info.extraData[U_("RtAudio-ApiDisplayName")] = mpt::ToUnicode(mpt::Charset::UTF8, RtAudio::getApiDisplayName(rtaudio.getCurrentApi())); + info.internalID = mpt::String::Combine(apidev, U_(",")); + info.name = mpt::ToUnicode(mpt::Charset::UTF8, rtinfo.name); + info.apiName = mpt::ToUnicode(mpt::Charset::UTF8, RtAudio::getApiDisplayName(rtaudio.getCurrentApi())); + info.extraData[U_("RtAudio-ApiDisplayName")] = mpt::ToUnicode(mpt::Charset::UTF8, RtAudio::getApiDisplayName(rtaudio.getCurrentApi())); info.apiPath.push_back(U_("RtAudio")); info.useNameAsIdentifier = true; switch(rtaudio.getCurrentApi()) { - case RtAudio::LINUX_ALSA: - info.apiName = U_("ALSA"); - info.default_ = (rtinfo.isDefaultOutput ? Info::Default::Named : Info::Default::None); - info.flags = { - sysInfo.SystemClass == mpt::OS::Class::Linux ? Info::Usability::Usable : Info::Usability::Experimental, - Info::Level::Secondary, - Info::Compatible::No, - sysInfo.SystemClass == mpt::OS::Class::Linux ? Info::Api::Native : Info::Api::Emulated, - Info::Io::FullDuplex, - sysInfo.SystemClass == mpt::OS::Class::Linux ? Info::Mixing::Hardware : Info::Mixing::Software, - Info::Implementor::External - }; - break; - case RtAudio::LINUX_PULSE: - info.apiName = U_("PulseAudio"); - info.default_ = (rtinfo.isDefaultOutput ? Info::Default::Managed : Info::Default::None); - info.flags = { - sysInfo.SystemClass == mpt::OS::Class::Linux ? Info::Usability::Usable : Info::Usability::Experimental, - Info::Level::Secondary, - Info::Compatible::No, - sysInfo.SystemClass == mpt::OS::Class::Linux ? Info::Api::Native : Info::Api::Emulated, - Info::Io::FullDuplex, - Info::Mixing::Server, - Info::Implementor::External - }; - break; - case RtAudio::LINUX_OSS: - info.apiName = U_("OSS"); - info.default_ = (rtinfo.isDefaultOutput ? Info::Default::Named : Info::Default::None); - info.flags = { - sysInfo.SystemClass == mpt::OS::Class::BSD ? Info::Usability::Usable : sysInfo.SystemClass == mpt::OS::Class::Linux ? Info::Usability::Deprecated : Info::Usability::NotAvailable, - Info::Level::Secondary, - Info::Compatible::No, - sysInfo.SystemClass == mpt::OS::Class::BSD ? Info::Api::Native : sysInfo.SystemClass == mpt::OS::Class::Linux ? Info::Api::Emulated : Info::Api::Emulated, - Info::Io::FullDuplex, - sysInfo.SystemClass == mpt::OS::Class::BSD ? Info::Mixing::Hardware : sysInfo.SystemClass == mpt::OS::Class::Linux ? Info::Mixing::Software : Info::Mixing::Software, - Info::Implementor::External - }; - break; - case RtAudio::UNIX_JACK: - info.apiName = U_("JACK"); - info.default_ = (rtinfo.isDefaultOutput ? Info::Default::Managed : Info::Default::None); - info.flags = { - sysInfo.SystemClass == mpt::OS::Class::Linux ? Info::Usability::Usable : sysInfo.SystemClass == mpt::OS::Class::Darwin ? Info::Usability::Usable : Info::Usability::Experimental, - Info::Level::Primary, - Info::Compatible::Yes, - sysInfo.SystemClass == mpt::OS::Class::Linux ? Info::Api::Native : Info::Api::Emulated, - Info::Io::FullDuplex, - Info::Mixing::Server, - Info::Implementor::External - }; - break; - case RtAudio::MACOSX_CORE: - info.apiName = U_("CoreAudio"); - info.default_ = (rtinfo.isDefaultOutput ? Info::Default::Named : Info::Default::None); - info.flags = { - sysInfo.SystemClass == mpt::OS::Class::Darwin ? Info::Usability::Usable : Info::Usability::NotAvailable, - Info::Level::Primary, - Info::Compatible::Yes, - sysInfo.SystemClass == mpt::OS::Class::Darwin ? Info::Api::Native : Info::Api::Emulated, - Info::Io::FullDuplex, - Info::Mixing::Server, - Info::Implementor::External - }; - break; - case RtAudio::WINDOWS_WASAPI: - info.apiName = U_("WASAPI"); - info.default_ = (rtinfo.isDefaultOutput ? Info::Default::Named : Info::Default::None); - info.flags = { - sysInfo.SystemClass == mpt::OS::Class::Windows ? Info::Usability::Usable : Info::Usability::NotAvailable, - Info::Level::Secondary, - Info::Compatible::No, - sysInfo.SystemClass == mpt::OS::Class::Windows ? Info::Api::Native : Info::Api::Emulated, - Info::Io::FullDuplex, - Info::Mixing::Server, - Info::Implementor::External - }; - break; - case RtAudio::WINDOWS_ASIO: - info.apiName = U_("ASIO"); - info.default_ = (rtinfo.isDefaultOutput ? Info::Default::Named : Info::Default::None); - info.flags = { - sysInfo.SystemClass == mpt::OS::Class::Windows ? sysInfo.IsWindowsOriginal() ? Info::Usability::Usable : Info::Usability::Experimental : Info::Usability::NotAvailable, - Info::Level::Secondary, - Info::Compatible::No, - sysInfo.SystemClass == mpt::OS::Class::Windows && sysInfo.IsWindowsOriginal() ? Info::Api::Native : Info::Api::Emulated, - Info::Io::FullDuplex, - Info::Mixing::Hardware, - Info::Implementor::External - }; - break; - case RtAudio::WINDOWS_DS: - info.apiName = U_("DirectSound"); - info.default_ = (rtinfo.isDefaultOutput ? Info::Default::Managed : Info::Default::None); - info.flags = { - Info::Usability::Broken, // sysInfo.SystemClass == mpt::OS::Class::Windows ? Info::Usability::Deprecated : Info::Usability::NotAvailable, - Info::Level::Secondary, - Info::Compatible::No, - Info::Api::Emulated, - Info::Io::FullDuplex, - Info::Mixing::Software, - Info::Implementor::External - }; - break; - default: - // nothing - break; + case RtAudio::LINUX_ALSA: + info.apiName = U_("ALSA"); + info.default_ = (rtinfo.isDefaultOutput ? Info::Default::Named : Info::Default::None); + info.flags = { + sysInfo.SystemClass == mpt::OS::Class::Linux ? Info::Usability::Usable : Info::Usability::Experimental, + Info::Level::Secondary, + Info::Compatible::No, + sysInfo.SystemClass == mpt::OS::Class::Linux ? Info::Api::Native : Info::Api::Emulated, + Info::Io::FullDuplex, + sysInfo.SystemClass == mpt::OS::Class::Linux ? Info::Mixing::Hardware : Info::Mixing::Software, + Info::Implementor::External}; + break; + case RtAudio::LINUX_PULSE: + info.apiName = U_("PulseAudio"); + info.default_ = (rtinfo.isDefaultOutput ? Info::Default::Managed : Info::Default::None); + info.flags = { + sysInfo.SystemClass == mpt::OS::Class::Linux ? Info::Usability::Usable : Info::Usability::Experimental, + Info::Level::Secondary, + Info::Compatible::No, + sysInfo.SystemClass == mpt::OS::Class::Linux ? Info::Api::Native : Info::Api::Emulated, + Info::Io::FullDuplex, + Info::Mixing::Server, + Info::Implementor::External}; + break; + case RtAudio::LINUX_OSS: + info.apiName = U_("OSS"); + info.default_ = (rtinfo.isDefaultOutput ? Info::Default::Named : Info::Default::None); + info.flags = { + sysInfo.SystemClass == mpt::OS::Class::BSD ? Info::Usability::Usable : sysInfo.SystemClass == mpt::OS::Class::Linux ? Info::Usability::Deprecated : Info::Usability::NotAvailable, + Info::Level::Secondary, + Info::Compatible::No, + sysInfo.SystemClass == mpt::OS::Class::BSD ? Info::Api::Native : sysInfo.SystemClass == mpt::OS::Class::Linux ? Info::Api::Emulated : Info::Api::Emulated, + Info::Io::FullDuplex, + sysInfo.SystemClass == mpt::OS::Class::BSD ? Info::Mixing::Hardware : sysInfo.SystemClass == mpt::OS::Class::Linux ? Info::Mixing::Software : Info::Mixing::Software, + Info::Implementor::External}; + break; + case RtAudio::UNIX_JACK: + info.apiName = U_("JACK"); + info.default_ = (rtinfo.isDefaultOutput ? Info::Default::Managed : Info::Default::None); + info.flags = { + sysInfo.SystemClass == mpt::OS::Class::Linux ? Info::Usability::Usable : sysInfo.SystemClass == mpt::OS::Class::Darwin ? Info::Usability::Usable : Info::Usability::Experimental, + Info::Level::Primary, + Info::Compatible::Yes, + sysInfo.SystemClass == mpt::OS::Class::Linux ? Info::Api::Native : Info::Api::Emulated, + Info::Io::FullDuplex, + Info::Mixing::Server, + Info::Implementor::External}; + break; + case RtAudio::MACOSX_CORE: + info.apiName = U_("CoreAudio"); + info.default_ = (rtinfo.isDefaultOutput ? Info::Default::Named : Info::Default::None); + info.flags = { + sysInfo.SystemClass == mpt::OS::Class::Darwin ? Info::Usability::Usable : Info::Usability::NotAvailable, + Info::Level::Primary, + Info::Compatible::Yes, + sysInfo.SystemClass == mpt::OS::Class::Darwin ? Info::Api::Native : Info::Api::Emulated, + Info::Io::FullDuplex, + Info::Mixing::Server, + Info::Implementor::External}; + break; + case RtAudio::WINDOWS_WASAPI: + info.apiName = U_("WASAPI"); + info.default_ = (rtinfo.isDefaultOutput ? Info::Default::Named : Info::Default::None); + info.flags = { + sysInfo.SystemClass == mpt::OS::Class::Windows ? Info::Usability::Usable : Info::Usability::NotAvailable, + Info::Level::Secondary, + Info::Compatible::No, + sysInfo.SystemClass == mpt::OS::Class::Windows ? Info::Api::Native : Info::Api::Emulated, + Info::Io::FullDuplex, + Info::Mixing::Server, + Info::Implementor::External}; + break; + case RtAudio::WINDOWS_ASIO: + info.apiName = U_("ASIO"); + info.default_ = (rtinfo.isDefaultOutput ? Info::Default::Named : Info::Default::None); + info.flags = { + sysInfo.SystemClass == mpt::OS::Class::Windows ? sysInfo.IsWindowsOriginal() ? Info::Usability::Usable : Info::Usability::Experimental : Info::Usability::NotAvailable, + Info::Level::Secondary, + Info::Compatible::No, + sysInfo.SystemClass == mpt::OS::Class::Windows && sysInfo.IsWindowsOriginal() ? Info::Api::Native : Info::Api::Emulated, + Info::Io::FullDuplex, + Info::Mixing::Hardware, + Info::Implementor::External}; + break; + case RtAudio::WINDOWS_DS: + info.apiName = U_("DirectSound"); + info.default_ = (rtinfo.isDefaultOutput ? Info::Default::Managed : Info::Default::None); + info.flags = { + Info::Usability::Broken, // sysInfo.SystemClass == mpt::OS::Class::Windows ? Info::Usability::Deprecated : Info::Usability::NotAvailable, + Info::Level::Secondary, + Info::Compatible::No, + Info::Api::Emulated, + Info::Io::FullDuplex, + Info::Mixing::Software, + Info::Implementor::External}; + break; + default: + // nothing + break; } devices.push_back(info); @@ -603,10 +596,10 @@ } -#endif // MPT_WITH_RTAUDIO +#endif // MPT_WITH_RTAUDIO -} // namespace SoundDevice +} // namespace SoundDevice OPENMPT_NAMESPACE_END Index: sounddev/SoundDeviceRtAudio.h =================================================================== --- sounddev/SoundDeviceRtAudio.h (revision 14154) +++ sounddev/SoundDeviceRtAudio.h (working copy) @@ -19,27 +19,27 @@ #ifdef MPT_WITH_RTAUDIO #if MPT_COMPILER_MSVC #pragma warning(push) -#pragma warning(disable:4244) // conversion from 'int' to 'unsigned char', possible loss of data +#pragma warning(disable : 4244) // conversion from 'int' to 'unsigned char', possible loss of data #endif #include #if MPT_COMPILER_MSVC #pragma warning(pop) #endif -#endif // MPT_WITH_RTAUDIO +#endif // MPT_WITH_RTAUDIO OPENMPT_NAMESPACE_BEGIN -namespace SoundDevice { +namespace SoundDevice +{ #ifdef MPT_WITH_RTAUDIO -class CRtAudioDevice: public SoundDevice::Base +class CRtAudioDevice : public SoundDevice::Base { protected: - std::unique_ptr m_RtAudio; RtAudio::StreamParameters m_InputStreamParameters; @@ -47,8 +47,8 @@ unsigned int m_FramesPerChunk; RtAudio::StreamOptions m_StreamOptions; - void * m_CurrentFrameBufferOutput; - void * m_CurrentFrameBufferInput; + void *m_CurrentFrameBufferOutput; + void *m_CurrentFrameBufferInput; unsigned int m_CurrentFrameBufferCount; double m_CurrentStreamTime; @@ -56,12 +56,10 @@ std::atomic m_StatisticPeriodFrames; public: - CRtAudioDevice(SoundDevice::Info info, SoundDevice::SysInfo sysInfo); ~CRtAudioDevice(); public: - bool InternalOpen(); bool InternalClose(); void InternalFillAudioBuffer(); @@ -76,7 +74,6 @@ SoundDevice::DynamicCaps GetDeviceDynamicCaps(const std::vector &baseSampleRates); private: - void SendError(const RtAudioError &e); void AudioCallback(void *outputBuffer, void *inputBuffer, unsigned int nFrames, double streamTime, RtAudioStreamStatus status); @@ -87,9 +84,7 @@ static unsigned int GetDevice(SoundDevice::Info info); public: - static std::vector EnumerateDevices(SoundDevice::SysInfo sysInfo); - }; @@ -103,10 +98,10 @@ }; -#endif // MPT_WITH_RTAUDIO +#endif // MPT_WITH_RTAUDIO -} // namespace SoundDevice +} // namespace SoundDevice OPENMPT_NAMESPACE_END Index: sounddev/SoundDeviceStub.cpp =================================================================== --- sounddev/SoundDeviceStub.cpp (revision 14154) +++ sounddev/SoundDeviceStub.cpp (working copy) @@ -11,8 +11,8 @@ #include "stdafx.h" #if MPT_COMPILER_MSVC -#pragma warning(disable:4800) // 'T' : forcing value to bool 'true' or 'false' (performance warning) -#endif // MPT_COMPILER_MSVC +#pragma warning(disable : 4800) // 'T' : forcing value to bool 'true' or 'false' (performance warning) +#endif // MPT_COMPILER_MSVC #include "SoundDevice.h" @@ -25,7 +25,7 @@ #include "../mptrack/MPTrackWine.h" #include "../mptrack/wine/NativeSoundDeviceMarshalling.h" -#endif // !MPT_BUILD_WINESUPPORT +#endif // !MPT_BUILD_WINESUPPORT @@ -32,7 +32,8 @@ OPENMPT_NAMESPACE_BEGIN -namespace SoundDevice { +namespace SoundDevice +{ #if !defined(MPT_BUILD_WINESUPPORT) @@ -65,8 +66,8 @@ { return std::vector(); } - MPT_UNREFERENCED_PARAMETER(sysInfo); // we do not want to pass this to the native layer because it would actually be totally wrong - std::vector result = json_cast >(WineWrapper->SoundDevice_EnumerateDevices()); + MPT_UNREFERENCED_PARAMETER(sysInfo); // we do not want to pass this to the native layer because it would actually be totally wrong + std::vector result = json_cast>(WineWrapper->SoundDevice_EnumerateDevices()); for(auto &info : result) { info = AddTypePrefix(info); @@ -77,12 +78,13 @@ SoundDeviceStub::SoundDeviceStub(SoundDevice::Info info, SoundDevice::SysInfo sysInfo) : impl(nullptr) { - MPT_UNREFERENCED_PARAMETER(sysInfo); // we do not want to pass this to the native layer because it would actually be totally wrong + MPT_UNREFERENCED_PARAMETER(sysInfo); // we do not want to pass this to the native layer because it would actually be totally wrong info = RemoveTypePrefix(info); impl = w->OpenMPT_Wine_Wrapper_SoundDevice_Construct(json_cast(info).c_str()); } -SoundDeviceStub::~SoundDeviceStub() { +SoundDeviceStub::~SoundDeviceStub() +{ if(impl) { w->OpenMPT_Wine_Wrapper_SoundDevice_Destruct(impl); @@ -90,9 +92,9 @@ } } -static void __cdecl SoundDevice_MessageReceiver_SoundDeviceMessage(void * inst, uintptr_t level, const char * message) +static void __cdecl SoundDevice_MessageReceiver_SoundDeviceMessage(void *inst, uintptr_t level, const char *message) { - SoundDevice::IMessageReceiver * mr = (SoundDevice::IMessageReceiver*)inst; + SoundDevice::IMessageReceiver *mr = (SoundDevice::IMessageReceiver *)inst; if(!mr) { return; @@ -100,16 +102,18 @@ mr->SoundDeviceMessage((LogLevel)level, mpt::ToUnicode(mpt::Charset::UTF8, message ? message : "")); } -void SoundDeviceStub::SetMessageReceiver(SoundDevice::IMessageReceiver *receiver) { +void SoundDeviceStub::SetMessageReceiver(SoundDevice::IMessageReceiver *receiver) +{ OpenMPT_Wine_Wrapper_SoundDevice_IMessageReceiver messageReceiver; MemsetZero(messageReceiver); - messageReceiver.inst = receiver; + messageReceiver.inst = receiver; messageReceiver.SoundDeviceMessageFunc = &SoundDevice_MessageReceiver_SoundDeviceMessage; return w->OpenMPT_Wine_Wrapper_SoundDevice_SetMessageReceiver(impl, &messageReceiver); } -static void __cdecl SoundSourceGetReferenceClockNowNanosecondsFunc( void * inst, uint64_t * result ) { - SoundDevice::ISource * source = ((SoundDevice::ISource*)inst); +static void __cdecl SoundSourceGetReferenceClockNowNanosecondsFunc(void *inst, uint64_t *result) +{ + SoundDevice::ISource *source = ((SoundDevice::ISource *)inst); if(!source) { *result = 0; @@ -117,8 +121,9 @@ } *result = source->SoundSourceGetReferenceClockNowNanoseconds(); } -static void __cdecl SoundSourcePreStartCallbackFunc( void * inst ) { - SoundDevice::ISource * source = ((SoundDevice::ISource*)inst); +static void __cdecl SoundSourcePreStartCallbackFunc(void *inst) +{ + SoundDevice::ISource *source = ((SoundDevice::ISource *)inst); if(!source) { return; @@ -125,8 +130,9 @@ } source->SoundSourcePreStartCallback(); } -static void __cdecl SoundSourcePostStopCallbackFunc( void * inst ) { - SoundDevice::ISource * source = ((SoundDevice::ISource*)inst); +static void __cdecl SoundSourcePostStopCallbackFunc(void *inst) +{ + SoundDevice::ISource *source = ((SoundDevice::ISource *)inst); if(!source) { return; @@ -133,8 +139,9 @@ } source->SoundSourcePostStopCallback(); } -static void __cdecl SoundSourceIsLockedByCurrentThreadFunc( void * inst, uintptr_t * result ) { - SoundDevice::ISource * source = ((SoundDevice::ISource*)inst); +static void __cdecl SoundSourceIsLockedByCurrentThreadFunc(void *inst, uintptr_t *result) +{ + SoundDevice::ISource *source = ((SoundDevice::ISource *)inst); if(!source) { *result = 0; @@ -142,8 +149,9 @@ } *result = source->SoundSourceIsLockedByCurrentThread(); } -static void __cdecl SoundSourceLockFunc( void * inst ) { - SoundDevice::ISource * source = ((SoundDevice::ISource*)inst); +static void __cdecl SoundSourceLockFunc(void *inst) +{ + SoundDevice::ISource *source = ((SoundDevice::ISource *)inst); if(!source) { return; @@ -150,8 +158,9 @@ } source->SoundSourceLock(); } -static void __cdecl SoundSourceLockedGetReferenceClockNowNanosecondsFunc( void * inst, uint64_t * result ) { - SoundDevice::ISource * source = ((SoundDevice::ISource*)inst); +static void __cdecl SoundSourceLockedGetReferenceClockNowNanosecondsFunc(void *inst, uint64_t *result) +{ + SoundDevice::ISource *source = ((SoundDevice::ISource *)inst); if(!source) { *result = 0; @@ -159,9 +168,10 @@ } *result = source->SoundSourceLockedGetReferenceClockNowNanoseconds(); } -static void __cdecl SoundSourceLockedReadPrepareFunc( void * inst, const OpenMPT_SoundDevice_TimeInfo * timeInfo ) { - SoundDevice::ISource * source = ((SoundDevice::ISource*)inst); - SoundDevice::TimeInfo ti = C::decode(*timeInfo); +static void __cdecl SoundSourceLockedReadPrepareFunc(void *inst, const OpenMPT_SoundDevice_TimeInfo *timeInfo) +{ + SoundDevice::ISource *source = ((SoundDevice::ISource *)inst); + SoundDevice::TimeInfo ti = C::decode(*timeInfo); if(!source) { return; @@ -168,8 +178,9 @@ } source->SoundSourceLockedReadPrepare(ti); } -static void __cdecl SoundSourceLockedReadFunc( void * inst, const OpenMPT_SoundDevice_BufferFormat * bufferFormat, uintptr_t numFrames, void * buffer, const void * inputBuffer ) { - SoundDevice::ISource * source = ((SoundDevice::ISource*)inst); +static void __cdecl SoundSourceLockedReadFunc(void *inst, const OpenMPT_SoundDevice_BufferFormat *bufferFormat, uintptr_t numFrames, void *buffer, const void *inputBuffer) +{ + SoundDevice::ISource *source = ((SoundDevice::ISource *)inst); SoundDevice::BufferFormat bf = C::decode(*bufferFormat); if(!source) { @@ -177,9 +188,10 @@ } source->SoundSourceLockedRead(bf, numFrames, buffer, inputBuffer); } -static void __cdecl SoundSourceLockedReadDoneFunc( void * inst, const OpenMPT_SoundDevice_TimeInfo * timeInfo ) { - SoundDevice::ISource * source = ((SoundDevice::ISource*)inst); - SoundDevice::TimeInfo ti = C::decode(*timeInfo); +static void __cdecl SoundSourceLockedReadDoneFunc(void *inst, const OpenMPT_SoundDevice_TimeInfo *timeInfo) +{ + SoundDevice::ISource *source = ((SoundDevice::ISource *)inst); + SoundDevice::TimeInfo ti = C::decode(*timeInfo); if(!source) { return; @@ -186,8 +198,9 @@ } source->SoundSourceLockedReadDone(ti); } -static void __cdecl SoundSourceUnlockFunc( void * inst ) { - SoundDevice::ISource * source = ((SoundDevice::ISource*)inst); +static void __cdecl SoundSourceUnlockFunc(void *inst) +{ + SoundDevice::ISource *source = ((SoundDevice::ISource *)inst); if(!source) { return; @@ -195,144 +208,171 @@ source->SoundSourceUnlock(); } -void SoundDeviceStub::SetSource(SoundDevice::ISource *isource) { +void SoundDeviceStub::SetSource(SoundDevice::ISource *isource) +{ OpenMPT_Wine_Wrapper_SoundDevice_ISource source; MemsetZero(source); - source.inst = isource; - source.SoundSourceGetReferenceClockNowNanosecondsFunc = &SoundSourceGetReferenceClockNowNanosecondsFunc; - source.SoundSourcePreStartCallbackFunc = &SoundSourcePreStartCallbackFunc; - source.SoundSourcePostStopCallbackFunc = &SoundSourcePostStopCallbackFunc; - source.SoundSourceIsLockedByCurrentThreadFunc = &SoundSourceIsLockedByCurrentThreadFunc; - source.SoundSourceLockFunc = &SoundSourceLockFunc; + source.inst = isource; + source.SoundSourceGetReferenceClockNowNanosecondsFunc = &SoundSourceGetReferenceClockNowNanosecondsFunc; + source.SoundSourcePreStartCallbackFunc = &SoundSourcePreStartCallbackFunc; + source.SoundSourcePostStopCallbackFunc = &SoundSourcePostStopCallbackFunc; + source.SoundSourceIsLockedByCurrentThreadFunc = &SoundSourceIsLockedByCurrentThreadFunc; + source.SoundSourceLockFunc = &SoundSourceLockFunc; source.SoundSourceLockedGetReferenceClockNowNanosecondsFunc = &SoundSourceLockedGetReferenceClockNowNanosecondsFunc; - source.SoundSourceLockedReadPrepareFunc = &SoundSourceLockedReadPrepareFunc; - source.SoundSourceLockedReadFunc = &SoundSourceLockedReadFunc; - source.SoundSourceLockedReadDoneFunc = &SoundSourceLockedReadDoneFunc; - source.SoundSourceUnlockFunc = &SoundSourceUnlockFunc; + source.SoundSourceLockedReadPrepareFunc = &SoundSourceLockedReadPrepareFunc; + source.SoundSourceLockedReadFunc = &SoundSourceLockedReadFunc; + source.SoundSourceLockedReadDoneFunc = &SoundSourceLockedReadDoneFunc; + source.SoundSourceUnlockFunc = &SoundSourceUnlockFunc; return w->OpenMPT_Wine_Wrapper_SoundDevice_SetSource(impl, &source); } -SoundDevice::Info SoundDeviceStub::GetDeviceInfo() const { +SoundDevice::Info SoundDeviceStub::GetDeviceInfo() const +{ SoundDevice::Info info = json_cast(w->result_as_string(w->OpenMPT_Wine_Wrapper_SoundDevice_GetDeviceInfo(impl))); - info = AddTypePrefix(info); + info = AddTypePrefix(info); return info; } -SoundDevice::Caps SoundDeviceStub::GetDeviceCaps() const { +SoundDevice::Caps SoundDeviceStub::GetDeviceCaps() const +{ return json_cast(w->result_as_string(w->OpenMPT_Wine_Wrapper_SoundDevice_GetDeviceCaps(impl))); } -SoundDevice::DynamicCaps SoundDeviceStub::GetDeviceDynamicCaps(const std::vector &baseSampleRates) { +SoundDevice::DynamicCaps SoundDeviceStub::GetDeviceDynamicCaps(const std::vector &baseSampleRates) +{ return json_cast(w->result_as_string(w->OpenMPT_Wine_Wrapper_SoundDevice_GetDeviceDynamicCaps(impl, json_cast(baseSampleRates).c_str()))); } -bool SoundDeviceStub::Init(const SoundDevice::AppInfo &appInfo) { +bool SoundDeviceStub::Init(const SoundDevice::AppInfo &appInfo) +{ return w->OpenMPT_Wine_Wrapper_SoundDevice_Init(impl, json_cast(appInfo).c_str()); } -bool SoundDeviceStub::Open(const SoundDevice::Settings &settings) { +bool SoundDeviceStub::Open(const SoundDevice::Settings &settings) +{ return w->OpenMPT_Wine_Wrapper_SoundDevice_Open(impl, json_cast(settings).c_str()); } -bool SoundDeviceStub::Close() { +bool SoundDeviceStub::Close() +{ return w->OpenMPT_Wine_Wrapper_SoundDevice_Close(impl); } -bool SoundDeviceStub::Start() { +bool SoundDeviceStub::Start() +{ return w->OpenMPT_Wine_Wrapper_SoundDevice_Start(impl); } -void SoundDeviceStub::Stop() { +void SoundDeviceStub::Stop() +{ return w->OpenMPT_Wine_Wrapper_SoundDevice_Stop(impl); } -FlagSet SoundDeviceStub::GetRequestFlags() const { +FlagSet SoundDeviceStub::GetRequestFlags() const +{ uint32_t result = 0; w->OpenMPT_Wine_Wrapper_SoundDevice_GetRequestFlags(impl, &result); return FlagSet(result); } -bool SoundDeviceStub::IsInited() const { +bool SoundDeviceStub::IsInited() const +{ return w->OpenMPT_Wine_Wrapper_SoundDevice_IsInited(impl); } -bool SoundDeviceStub::IsOpen() const { +bool SoundDeviceStub::IsOpen() const +{ return w->OpenMPT_Wine_Wrapper_SoundDevice_IsOpen(impl); } -bool SoundDeviceStub::IsAvailable() const { +bool SoundDeviceStub::IsAvailable() const +{ return w->OpenMPT_Wine_Wrapper_SoundDevice_IsAvailable(impl); } -bool SoundDeviceStub::IsPlaying() const { +bool SoundDeviceStub::IsPlaying() const +{ return w->OpenMPT_Wine_Wrapper_SoundDevice_IsPlaying(impl); } -bool SoundDeviceStub::IsPlayingSilence() const { +bool SoundDeviceStub::IsPlayingSilence() const +{ return w->OpenMPT_Wine_Wrapper_SoundDevice_IsPlayingSilence(impl); } -void SoundDeviceStub::StopAndAvoidPlayingSilence() { +void SoundDeviceStub::StopAndAvoidPlayingSilence() +{ return w->OpenMPT_Wine_Wrapper_SoundDevice_StopAndAvoidPlayingSilence(impl); } -void SoundDeviceStub::EndPlayingSilence() { +void SoundDeviceStub::EndPlayingSilence() +{ return w->OpenMPT_Wine_Wrapper_SoundDevice_EndPlayingSilence(impl); } -bool SoundDeviceStub::OnIdle() { +bool SoundDeviceStub::OnIdle() +{ return w->OpenMPT_Wine_Wrapper_SoundDevice_OnIdle(impl); } -SoundDevice::Settings SoundDeviceStub::GetSettings() const { +SoundDevice::Settings SoundDeviceStub::GetSettings() const +{ return json_cast(w->result_as_string(w->OpenMPT_Wine_Wrapper_SoundDevice_GetSettings(impl))); } -SampleFormat SoundDeviceStub::GetActualSampleFormat() const { +SampleFormat SoundDeviceStub::GetActualSampleFormat() const +{ int32_t result = 0; w->OpenMPT_Wine_Wrapper_SoundDevice_GetActualSampleFormat(impl, &result); return SampleFormat::FromInt(result); } -SoundDevice::BufferAttributes SoundDeviceStub::GetEffectiveBufferAttributes() const { +SoundDevice::BufferAttributes SoundDeviceStub::GetEffectiveBufferAttributes() const +{ OpenMPT_SoundDevice_BufferAttributes result; w->OpenMPT_Wine_Wrapper_SoundDevice_GetEffectiveBufferAttributes(impl, &result); return C::decode(result); } -SoundDevice::TimeInfo SoundDeviceStub::GetTimeInfo() const { +SoundDevice::TimeInfo SoundDeviceStub::GetTimeInfo() const +{ OpenMPT_SoundDevice_TimeInfo result; w->OpenMPT_Wine_Wrapper_SoundDevice_GetTimeInfo(impl, &result); return C::decode(result); } -SoundDevice::StreamPosition SoundDeviceStub::GetStreamPosition() const { +SoundDevice::StreamPosition SoundDeviceStub::GetStreamPosition() const +{ OpenMPT_SoundDevice_StreamPosition result; w->OpenMPT_Wine_Wrapper_SoundDevice_GetStreamPosition(impl, &result); return C::decode(result); } -bool SoundDeviceStub::DebugIsFragileDevice() const { +bool SoundDeviceStub::DebugIsFragileDevice() const +{ return w->OpenMPT_Wine_Wrapper_SoundDevice_DebugIsFragileDevice(impl); } -bool SoundDeviceStub::DebugInRealtimeCallback() const { +bool SoundDeviceStub::DebugInRealtimeCallback() const +{ return w->OpenMPT_Wine_Wrapper_SoundDevice_DebugInRealtimeCallback(impl); } -SoundDevice::Statistics SoundDeviceStub::GetStatistics() const { +SoundDevice::Statistics SoundDeviceStub::GetStatistics() const +{ return json_cast(w->result_as_string(w->OpenMPT_Wine_Wrapper_SoundDevice_GetStatistics(impl))); } -bool SoundDeviceStub::OpenDriverSettings() { +bool SoundDeviceStub::OpenDriverSettings() +{ return w->OpenMPT_Wine_Wrapper_SoundDevice_OpenDriverSettings(impl); } -#endif // !MPT_BUILD_WINESUPPORT +#endif // !MPT_BUILD_WINESUPPORT -} // namespace SoundDevice +} // namespace SoundDevice OPENMPT_NAMESPACE_END Index: sounddev/SoundDeviceStub.h =================================================================== --- sounddev/SoundDeviceStub.h (revision 14154) +++ sounddev/SoundDeviceStub.h (working copy) @@ -17,7 +17,8 @@ #include "../common/ComponentManager.h" -extern "C" { +extern "C" +{ typedef struct OpenMPT_Wine_Wrapper_SoundDevice OpenMPT_Wine_Wrapper_SoundDevice; }; @@ -28,7 +29,8 @@ class ComponentWineWrapper; -namespace SoundDevice { +namespace SoundDevice +{ #if !defined(MPT_BUILD_WINESUPPORT) @@ -37,17 +39,14 @@ { public: - static std::vector EnumerateDevices(SoundDevice::SysInfo sysInfo); public: + SoundDeviceStub(SoundDevice::Info info, SoundDevice::SysInfo sysInfo); - SoundDeviceStub(SoundDevice::Info info, SoundDevice::SysInfo sysInfo); - virtual ~SoundDeviceStub(); public: - virtual void SetSource(SoundDevice::ISource *source); virtual void SetMessageReceiver(SoundDevice::IMessageReceiver *receiver); @@ -74,7 +73,7 @@ virtual void EndPlayingSilence(); virtual bool OnIdle(); - + virtual SoundDevice::Settings GetSettings() const; virtual SampleFormat GetActualSampleFormat() const; virtual SoundDevice::BufferAttributes GetEffectiveBufferAttributes() const; @@ -90,14 +89,12 @@ virtual bool OpenDriverSettings(); private: - ComponentHandle w; - OpenMPT_Wine_Wrapper_SoundDevice * impl; - + OpenMPT_Wine_Wrapper_SoundDevice *impl; }; -#endif // !MPT_BUILD_WINESUPPORT +#endif // !MPT_BUILD_WINESUPPORT -} // namespace SoundDevice +} // namespace SoundDevice OPENMPT_NAMESPACE_END Index: sounddev/SoundDeviceUtilities.cpp =================================================================== --- sounddev/SoundDeviceUtilities.cpp (revision 14154) +++ sounddev/SoundDeviceUtilities.cpp (working copy) @@ -21,13 +21,13 @@ #if MPT_OS_WINDOWS #include #include -#endif // MPT_OS_WINDOWS +#endif // MPT_OS_WINDOWS #if !MPT_OS_WINDOWS #include #include #include -#ifdef _POSIX_PRIORITY_SCHEDULING // from unistd.h +#ifdef _POSIX_PRIORITY_SCHEDULING // from unistd.h #include #endif #endif @@ -43,7 +43,8 @@ OPENMPT_NAMESPACE_BEGIN -namespace SoundDevice { +namespace SoundDevice +{ #if MPT_OS_WINDOWS @@ -55,34 +56,37 @@ { return false; } - WaveFormat.Format.wFormatTag = m_Settings.sampleFormat.IsFloat() ? WAVE_FORMAT_IEEE_FLOAT : WAVE_FORMAT_PCM; - WaveFormat.Format.nChannels = (WORD)m_Settings.Channels; - WaveFormat.Format.nSamplesPerSec = m_Settings.Samplerate; + WaveFormat.Format.wFormatTag = m_Settings.sampleFormat.IsFloat() ? WAVE_FORMAT_IEEE_FLOAT : WAVE_FORMAT_PCM; + WaveFormat.Format.nChannels = (WORD)m_Settings.Channels; + WaveFormat.Format.nSamplesPerSec = m_Settings.Samplerate; WaveFormat.Format.nAvgBytesPerSec = (DWORD)m_Settings.GetBytesPerSecond(); - WaveFormat.Format.nBlockAlign = (WORD)m_Settings.GetBytesPerFrame(); - WaveFormat.Format.wBitsPerSample = (WORD)m_Settings.sampleFormat.GetBitsPerSample(); - WaveFormat.Format.cbSize = 0; + WaveFormat.Format.nBlockAlign = (WORD)m_Settings.GetBytesPerFrame(); + WaveFormat.Format.wBitsPerSample = (WORD)m_Settings.sampleFormat.GetBitsPerSample(); + WaveFormat.Format.cbSize = 0; if((WaveFormat.Format.wBitsPerSample > 16 && m_Settings.sampleFormat.IsInt()) || (WaveFormat.Format.nChannels > 2)) { - WaveFormat.Format.wFormatTag = WAVE_FORMAT_EXTENSIBLE; - WaveFormat.Format.cbSize = sizeof(WAVEFORMATEXTENSIBLE) - sizeof(WAVEFORMATEX); + WaveFormat.Format.wFormatTag = WAVE_FORMAT_EXTENSIBLE; + WaveFormat.Format.cbSize = sizeof(WAVEFORMATEXTENSIBLE) - sizeof(WAVEFORMATEX); WaveFormat.Samples.wValidBitsPerSample = WaveFormat.Format.wBitsPerSample; switch(WaveFormat.Format.nChannels) { - case 1: WaveFormat.dwChannelMask = SPEAKER_FRONT_CENTER; break; - case 2: WaveFormat.dwChannelMask = SPEAKER_FRONT_LEFT | SPEAKER_FRONT_RIGHT; break; - case 3: WaveFormat.dwChannelMask = SPEAKER_FRONT_LEFT | SPEAKER_FRONT_RIGHT | SPEAKER_BACK_CENTER; break; - case 4: WaveFormat.dwChannelMask = SPEAKER_FRONT_LEFT | SPEAKER_FRONT_RIGHT | SPEAKER_BACK_LEFT | SPEAKER_BACK_RIGHT; break; - default: WaveFormat.dwChannelMask = 0; return false; break; + case 1: WaveFormat.dwChannelMask = SPEAKER_FRONT_CENTER; break; + case 2: WaveFormat.dwChannelMask = SPEAKER_FRONT_LEFT | SPEAKER_FRONT_RIGHT; break; + case 3: WaveFormat.dwChannelMask = SPEAKER_FRONT_LEFT | SPEAKER_FRONT_RIGHT | SPEAKER_BACK_CENTER; break; + case 4: WaveFormat.dwChannelMask = SPEAKER_FRONT_LEFT | SPEAKER_FRONT_RIGHT | SPEAKER_BACK_LEFT | SPEAKER_BACK_RIGHT; break; + default: + WaveFormat.dwChannelMask = 0; + return false; + break; } - const GUID guid_MEDIASUBTYPE_PCM = {0x00000001, 0x0000, 0x0010, {0x80, 0x00, 0x0, 0xAA, 0x0, 0x38, 0x9B, 0x71}}; + const GUID guid_MEDIASUBTYPE_PCM = {0x00000001, 0x0000, 0x0010, {0x80, 0x00, 0x0, 0xAA, 0x0, 0x38, 0x9B, 0x71}}; const GUID guid_MEDIASUBTYPE_IEEE_FLOAT = {0x00000003, 0x0000, 0x0010, {0x80, 0x00, 0x00, 0xAA, 0x00, 0x38, 0x9B, 0x71}}; - WaveFormat.SubFormat = m_Settings.sampleFormat.IsFloat() ? guid_MEDIASUBTYPE_IEEE_FLOAT : guid_MEDIASUBTYPE_PCM; + WaveFormat.SubFormat = m_Settings.sampleFormat.IsFloat() ? guid_MEDIASUBTYPE_IEEE_FLOAT : guid_MEDIASUBTYPE_PCM; } return true; } -#endif // MPT_OS_WINDOWS +#endif // MPT_OS_WINDOWS #if MPT_OS_WINDOWS @@ -91,19 +95,19 @@ : m_SoundDevice(SoundDevice) { MPT_TRACE_SCOPE(); - m_MMCSSClass = mpt::ToWin(m_SoundDevice.m_AppInfo.BoostedThreadMMCSSClassVista); - m_WakeupInterval = 0.0; - m_hPlayThread = NULL; - m_dwPlayThreadId = 0; - m_hAudioWakeUp = NULL; + m_MMCSSClass = mpt::ToWin(m_SoundDevice.m_AppInfo.BoostedThreadMMCSSClassVista); + m_WakeupInterval = 0.0; + m_hPlayThread = NULL; + m_dwPlayThreadId = 0; + m_hAudioWakeUp = NULL; m_hAudioThreadTerminateRequest = NULL; - m_hAudioThreadGoneIdle = NULL; - m_hHardwareWakeupEvent = INVALID_HANDLE_VALUE; - m_AudioThreadActive = 0; - m_hAudioWakeUp = CreateEvent(NULL, FALSE, FALSE, NULL); + m_hAudioThreadGoneIdle = NULL; + m_hHardwareWakeupEvent = INVALID_HANDLE_VALUE; + m_AudioThreadActive = 0; + m_hAudioWakeUp = CreateEvent(NULL, FALSE, FALSE, NULL); m_hAudioThreadTerminateRequest = CreateEvent(NULL, FALSE, FALSE, NULL); - m_hAudioThreadGoneIdle = CreateEvent(NULL, TRUE, FALSE, NULL); - m_hPlayThread = CreateThread(NULL, 0, AudioThreadWrapper, (LPVOID)this, 0, &m_dwPlayThreadId); + m_hAudioThreadGoneIdle = CreateEvent(NULL, TRUE, FALSE, NULL); + m_hPlayThread = CreateThread(NULL, 0, AudioThreadWrapper, (LPVOID)this, 0, &m_dwPlayThreadId); } @@ -115,7 +119,7 @@ SetEvent(m_hAudioThreadTerminateRequest); WaitForSingleObject(m_hPlayThread, INFINITE); m_dwPlayThreadId = 0; - m_hPlayThread = NULL; + m_hPlayThread = NULL; } if(m_hAudioThreadTerminateRequest) { @@ -135,7 +139,7 @@ } -CPriorityBooster::CPriorityBooster(SoundDevice::SysInfo sysInfo, bool boostPriority, const mpt::winstring & priorityClass) +CPriorityBooster::CPriorityBooster(SoundDevice::SysInfo sysInfo, bool boostPriority, const mpt::winstring &priorityClass) : m_SysInfo(sysInfo) , m_BoostPriority(boostPriority) , task_idx(0) @@ -142,9 +146,9 @@ , hTask(NULL) { MPT_TRACE_SCOPE(); - #ifdef MPT_BUILD_DEBUG - m_BoostPriority = false; - #endif +#ifdef MPT_BUILD_DEBUG + m_BoostPriority = false; +#endif if(m_BoostPriority) { if(!priorityClass.empty()) @@ -164,7 +168,7 @@ { AvRevertMmThreadCharacteristics(hTask); } - hTask = NULL; + hTask = NULL; task_idx = 0; } } @@ -173,7 +177,6 @@ class CPeriodicWaker { private: - double sleepSeconds; long sleepMilliseconds; int64 sleep100Nanoseconds; @@ -183,7 +186,6 @@ HANDLE sleepEvent; public: - explicit CPeriodicWaker(double sleepSeconds_) : sleepSeconds(sleepSeconds_) { @@ -190,12 +192,12 @@ MPT_TRACE_SCOPE(); - sleepMilliseconds = static_cast(sleepSeconds * 1000.0); + sleepMilliseconds = static_cast(sleepSeconds * 1000.0); sleep100Nanoseconds = static_cast(sleepSeconds * 10000000.0); if(sleepMilliseconds < 1) sleepMilliseconds = 1; if(sleep100Nanoseconds < 1) sleep100Nanoseconds = 1; - periodic_nt_timer = (sleep100Nanoseconds >= 10000); // can be represented as a millisecond period, otherwise use non-periodic timers which allow higher precision but might me slower because we have to set them again in each period + periodic_nt_timer = (sleep100Nanoseconds >= 10000); // can be represented as a millisecond period, otherwise use non-periodic timers which allow higher precision but might me slower because we have to set them again in each period sleepEvent = NULL; @@ -207,7 +209,7 @@ mpt::throw_out_of_memory(); } LARGE_INTEGER dueTime; - dueTime.QuadPart = 0 - sleep100Nanoseconds; // negative time means relative + dueTime.QuadPart = 0 - sleep100Nanoseconds; // negative time means relative SetWaitableTimer(sleepEvent, &dueTime, sleepMilliseconds, NULL, NULL, FALSE); } else { @@ -217,11 +219,10 @@ mpt::throw_out_of_memory(); } } - } CPeriodicWaker(const CPeriodicWaker &) = delete; - CPeriodicWaker & operator=(const CPeriodicWaker &) = delete; + CPeriodicWaker &operator=(const CPeriodicWaker &) = delete; long GetSleepMilliseconds() const { @@ -239,7 +240,7 @@ if(!periodic_nt_timer) { LARGE_INTEGER dueTime; - dueTime.QuadPart = 0 - sleep100Nanoseconds; // negative time means relative + dueTime.QuadPart = 0 - sleep100Nanoseconds; // negative time means relative SetWaitableTimer(sleepEvent, &dueTime, 0, NULL, NULL, FALSE); } } @@ -254,13 +255,12 @@ CloseHandle(sleepEvent); sleepEvent = NULL; } - }; DWORD WINAPI CAudioThread::AudioThreadWrapper(LPVOID user) { - return ((CAudioThread*)user)->AudioThread(); + return ((CAudioThread *)user)->AudioThread(); } DWORD CAudioThread::AudioThread() { @@ -277,12 +277,12 @@ SetEvent(m_hAudioThreadGoneIdle); switch(WaitForMultipleObjects(2, waithandles, FALSE, INFINITE)) { - case WAIT_OBJECT_0: - terminate = true; - break; - case WAIT_OBJECT_0+1: - idle = false; - break; + case WAIT_OBJECT_0: + terminate = true; + break; + case WAIT_OBJECT_0 + 1: + idle = false; + break; } } @@ -306,9 +306,9 @@ HANDLE waithandles[4] = {m_hAudioThreadTerminateRequest, m_hAudioWakeUp, m_hHardwareWakeupEvent, periodicWaker.GetWakeupEvent()}; switch(WaitForMultipleObjects(4, waithandles, FALSE, periodicWaker.GetSleepMilliseconds())) { - case WAIT_OBJECT_0: - terminate = true; - break; + case WAIT_OBJECT_0: + terminate = true; + break; } } else { @@ -315,24 +315,20 @@ HANDLE waithandles[3] = {m_hAudioThreadTerminateRequest, m_hAudioWakeUp, periodicWaker.GetWakeupEvent()}; switch(WaitForMultipleObjects(3, waithandles, FALSE, periodicWaker.GetSleepMilliseconds())) { - case WAIT_OBJECT_0: - terminate = true; - break; + case WAIT_OBJECT_0: + terminate = true; + break; } } - } m_SoundDevice.StopFromSoundThread(); - } - } SetEvent(m_hAudioThreadGoneIdle); return 0; - } @@ -431,7 +427,7 @@ m_AudioThread.Deactivate(); } -#endif // MPT_OS_WINDOWS +#endif // MPT_OS_WINDOWS #if defined(MODPLUG_TRACKER) && defined(MPT_BUILD_WINESUPPORT) && !MPT_OS_WINDOWS @@ -441,7 +437,6 @@ { private: - bool active; bool successfull; bool realtime; @@ -448,11 +443,10 @@ int niceness; int rt_priority; #if defined(MPT_WITH_DBUS) && defined(MPT_WITH_RTKIT) - DBusConnection * bus; -#endif // MPT_WITH_DBUS && MPT_WITH_RTKIT + DBusConnection *bus; +#endif // MPT_WITH_DBUS && MPT_WITH_RTKIT public: - ThreadPriorityGuardImpl(bool active, bool realtime, int niceness, int rt_priority) : active(active) , successfull(false) @@ -461,42 +455,42 @@ , rt_priority(rt_priority) #if defined(MPT_WITH_DBUS) && defined(MPT_WITH_RTKIT) , bus(NULL) -#endif // MPT_WITH_DBUS && MPT_WITH_RTKIT +#endif // MPT_WITH_DBUS && MPT_WITH_RTKIT { if(active) { if(realtime) { - #ifdef _POSIX_PRIORITY_SCHEDULING - sched_param p; - MemsetZero(p); - p.sched_priority = rt_priority; - #if MPT_OS_LINUX - if(sched_setscheduler(0, SCHED_RR|SCHED_RESET_ON_FORK, &p) == 0) - { - successfull = true; - } else - { - #if defined(MPT_WITH_DBUS) && defined(MPT_WITH_RTKIT) - MPT_LOG(LogNotification, "sounddev", MPT_UFORMAT("sched_setscheduler: {}")(errno)); - #else - MPT_LOG(LogError, "sounddev", MPT_UFORMAT("sched_setscheduler: {}")(errno)); - #endif - } - #else - if(sched_setscheduler(0, SCHED_RR, &p) == 0) - { - successfull = true; - } else - { - #if defined(MPT_WITH_DBUS) && defined(MPT_WITH_RTKIT) - MPT_LOG(LogNotification, "sounddev", MPT_UFORMAT("sched_setscheduler: {}")(errno)); - #else - MPT_LOG(LogError, "sounddev", MPT_UFORMAT("sched_setscheduler: {}")(errno)); - #endif - } - #endif - #endif +#ifdef _POSIX_PRIORITY_SCHEDULING + sched_param p; + MemsetZero(p); + p.sched_priority = rt_priority; +#if MPT_OS_LINUX + if(sched_setscheduler(0, SCHED_RR | SCHED_RESET_ON_FORK, &p) == 0) + { + successfull = true; + } else + { +#if defined(MPT_WITH_DBUS) && defined(MPT_WITH_RTKIT) + MPT_LOG(LogNotification, "sounddev", MPT_UFORMAT("sched_setscheduler: {}")(errno)); +#else + MPT_LOG(LogError, "sounddev", MPT_UFORMAT("sched_setscheduler: {}")(errno)); +#endif + } +#else + if(sched_setscheduler(0, SCHED_RR, &p) == 0) + { + successfull = true; + } else + { +#if defined(MPT_WITH_DBUS) && defined(MPT_WITH_RTKIT) + MPT_LOG(LogNotification, "sounddev", MPT_UFORMAT("sched_setscheduler: {}")(errno)); +#else + MPT_LOG(LogError, "sounddev", MPT_UFORMAT("sched_setscheduler: {}")(errno)); +#endif + } +#endif +#endif } else { if(setpriority(PRIO_PROCESS, 0, niceness) == 0) @@ -504,47 +498,49 @@ successfull = true; } else { - #if defined(MPT_WITH_DBUS) && defined(MPT_WITH_RTKIT) - MPT_LOG(LogNotification, "sounddev", MPT_UFORMAT("setpriority: {}")(errno)); - #else - MPT_LOG(LogError, "sounddev", MPT_UFORMAT("setpriority: {}")(errno)); - #endif +#if defined(MPT_WITH_DBUS) && defined(MPT_WITH_RTKIT) + MPT_LOG(LogNotification, "sounddev", MPT_UFORMAT("setpriority: {}")(errno)); +#else + MPT_LOG(LogError, "sounddev", MPT_UFORMAT("setpriority: {}")(errno)); +#endif } } if(!successfull) { - #if defined(MPT_WITH_DBUS) && defined(MPT_WITH_RTKIT) - DBusError error; - dbus_error_init(&error); - bus = dbus_bus_get(DBUS_BUS_SYSTEM, &error); - if(!bus) +#if defined(MPT_WITH_DBUS) && defined(MPT_WITH_RTKIT) + DBusError error; + dbus_error_init(&error); + bus = dbus_bus_get(DBUS_BUS_SYSTEM, &error); + if(!bus) + { + MPT_LOG(LogError, "sounddev", MPT_UFORMAT("DBus: dbus_bus_get: {}")(mpt::ToUnicode(mpt::Charset::UTF8, error.message))); + } + dbus_error_free(&error); + if(bus) + { + if(realtime) { - MPT_LOG(LogError, "sounddev", MPT_UFORMAT("DBus: dbus_bus_get: {}")(mpt::ToUnicode(mpt::Charset::UTF8, error.message))); - } - dbus_error_free(&error); - if(bus) + int e = rtkit_make_realtime(bus, 0, rt_priority); + if(e != 0) + { + MPT_LOG(LogError, "sounddev", MPT_UFORMAT("RtKit: rtkit_make_realtime: {}")(e)); + } else + { + successfull = true; + } + } else { - if(realtime) + int e = rtkit_make_high_priority(bus, 0, niceness); + if(e != 0) { - int e = rtkit_make_realtime(bus, 0, rt_priority); - if(e != 0) { - MPT_LOG(LogError, "sounddev", MPT_UFORMAT("RtKit: rtkit_make_realtime: {}")(e)); - } else - { - successfull = true; - } + MPT_LOG(LogError, "sounddev", MPT_UFORMAT("RtKit: rtkit_make_high_priority: {}")(e)); } else { - int e = rtkit_make_high_priority(bus, 0, niceness); - if(e != 0) { - MPT_LOG(LogError, "sounddev", MPT_UFORMAT("RtKit: rtkit_make_high_priority: {}")(e)); - } else - { - successfull = true; - } + successfull = true; } } - #endif // MPT_WITH_DBUS && MPT_WITH_RTKIT + } +#endif // MPT_WITH_DBUS && MPT_WITH_RTKIT } } } @@ -553,17 +549,16 @@ { if(active) { - #if defined(MPT_WITH_DBUS) && defined(MPT_WITH_RTKIT) - if(bus) - { - // TODO: Do we want to reset priorities here? - dbus_connection_unref(bus); - bus = NULL; - } - #endif // MPT_WITH_DBUS && MPT_WITH_RTKIT +#if defined(MPT_WITH_DBUS) && defined(MPT_WITH_RTKIT) + if(bus) + { + // TODO: Do we want to reset priorities here? + dbus_connection_unref(bus); + bus = NULL; + } +#endif // MPT_WITH_DBUS && MPT_WITH_RTKIT } } - }; @@ -596,7 +591,7 @@ return true; } -void ThreadBase::ThreadProcStatic(ThreadBase * this_) +void ThreadBase::ThreadProcStatic(ThreadBase *this_) { this_->ThreadProc(); } @@ -628,10 +623,10 @@ } -#endif // MODPLUG_TRACKER && MPT_BUILD_WINESUPPORT && !MPT_OS_WINDOWS +#endif // MODPLUG_TRACKER && MPT_BUILD_WINESUPPORT && !MPT_OS_WINDOWS -} // namespace SoundDevice +} // namespace SoundDevice OPENMPT_NAMESPACE_END Index: sounddev/SoundDeviceUtilities.h =================================================================== --- sounddev/SoundDeviceUtilities.h (revision 14154) +++ sounddev/SoundDeviceUtilities.h (working copy) @@ -19,7 +19,7 @@ #if MPT_OS_WINDOWS #include -#endif // MPT_OS_WINDOWS +#endif // MPT_OS_WINDOWS #if defined(MODPLUG_TRACKER) && defined(MPT_BUILD_WINESUPPORT) && !MPT_OS_WINDOWS // we use c++11 in native support library @@ -27,18 +27,19 @@ #include #include #include -#endif // MODPLUG_TRACKER && MPT_BUILD_WINESUPPORT && !MPT_OS_WINDOWS +#endif // MODPLUG_TRACKER && MPT_BUILD_WINESUPPORT && !MPT_OS_WINDOWS OPENMPT_NAMESPACE_BEGIN -namespace SoundDevice { +namespace SoundDevice +{ #if MPT_OS_WINDOWS bool FillWaveFormatExtensible(WAVEFORMATEXTENSIBLE &WaveFormat, const SoundDevice::Settings &m_Settings); -#endif // MPT_OS_WINDOWS +#endif // MPT_OS_WINDOWS #if MPT_OS_WINDOWS @@ -54,8 +55,9 @@ bool m_BoostPriority; DWORD task_idx; HANDLE hTask; + public: - CPriorityBooster(SoundDevice::SysInfo sysInfo, bool boostPriority, const mpt::winstring & priorityClass); + CPriorityBooster(SoundDevice::SysInfo sysInfo, bool boostPriority, const mpt::winstring &priorityClass); ~CPriorityBooster(); }; @@ -63,8 +65,9 @@ class CAudioThread { friend class CPeriodicWaker; + private: - CSoundDeviceWithThread & m_SoundDevice; + CSoundDeviceWithThread &m_SoundDevice; mpt::winstring m_MMCSSClass; double m_WakeupInterval; HANDLE m_hAudioWakeUp; @@ -77,10 +80,11 @@ static DWORD WINAPI AudioThreadWrapper(LPVOID user); DWORD AudioThread(); bool IsActive(); + public: CAudioThread(CSoundDeviceWithThread &SoundDevice); CAudioThread(const CAudioThread &) = delete; - CAudioThread& operator=(const CAudioThread &) = delete; + CAudioThread &operator=(const CAudioThread &) = delete; ~CAudioThread(); void Activate(); void Deactivate(); @@ -93,13 +97,17 @@ : public SoundDevice::Base { friend class CAudioThread; + protected: CAudioThread m_AudioThread; + private: void FillAudioBufferLocked(); + protected: void SetWakeupEvent(HANDLE ev); void SetWakeupInterval(double seconds); + public: CSoundDeviceWithThread(SoundDevice::Info info, SoundDevice::SysInfo sysInfo); virtual ~CSoundDeviceWithThread(); @@ -106,52 +114,61 @@ bool InternalStart(); void InternalStop(); virtual void StartFromSoundThread() = 0; - virtual void StopFromSoundThread() = 0; + virtual void StopFromSoundThread() = 0; }; -#endif // MPT_OS_WINDOWS +#endif // MPT_OS_WINDOWS #if defined(MODPLUG_TRACKER) && defined(MPT_BUILD_WINESUPPORT) && !MPT_OS_WINDOWS -class semaphore { +class semaphore +{ private: unsigned int count; unsigned int waiters_count; std::mutex mutex; std::condition_variable count_nonzero; + public: - semaphore( unsigned int initial_count = 0 ) + semaphore(unsigned int initial_count = 0) : count(initial_count) , waiters_count(0) { return; } - ~semaphore() { + ~semaphore() + { return; } - void wait() { + void wait() + { std::unique_lock l(mutex); waiters_count++; - while ( count == 0 ) { - count_nonzero.wait( l ); + while(count == 0) + { + count_nonzero.wait(l); } waiters_count--; count--; } - void post() { + void post() + { std::unique_lock l(mutex); - if ( waiters_count > 0 ) { + if(waiters_count > 0) + { count_nonzero.notify_one(); } count++; } - void lock() { + void lock() + { wait(); } - void unlock() { + void unlock() + { post(); } }; @@ -163,6 +180,7 @@ { private: std::unique_ptr impl; + public: ThreadPriorityGuard(bool active, bool realtime, int niceness, int rt_priority); ~ThreadPriorityGuard(); @@ -176,9 +194,11 @@ semaphore m_ThreadStarted; std::atomic m_ThreadStopRequest; std::thread m_Thread; + private: - static void ThreadProcStatic(ThreadBase * this_); + static void ThreadProcStatic(ThreadBase *this_); void ThreadProc(); + public: ThreadBase(SoundDevice::Info info, SoundDevice::SysInfo sysInfo); virtual ~ThreadBase(); @@ -185,15 +205,15 @@ bool InternalStart(); void InternalStop(); virtual void InternalStartFromSoundThread() = 0; - virtual void InternalWaitFromSoundThread() = 0; - virtual void InternalStopFromSoundThread() = 0; + virtual void InternalWaitFromSoundThread() = 0; + virtual void InternalStopFromSoundThread() = 0; }; -#endif // MODPLUG_TRACKER && MPT_BUILD_WINESUPPORT && !MPT_OS_WINDOWS +#endif // MODPLUG_TRACKER && MPT_BUILD_WINESUPPORT && !MPT_OS_WINDOWS -} // namespace SoundDevice +} // namespace SoundDevice OPENMPT_NAMESPACE_END Index: sounddev/SoundDeviceWaveout.cpp =================================================================== --- sounddev/SoundDeviceWaveout.cpp (revision 14154) +++ sounddev/SoundDeviceWaveout.cpp (working copy) @@ -23,7 +23,8 @@ OPENMPT_NAMESPACE_BEGIN -namespace SoundDevice { +namespace SoundDevice +{ #if MPT_OS_WINDOWS @@ -31,16 +32,16 @@ MPT_REGISTERED_COMPONENT(ComponentWaveOut, "WaveOut") -static constexpr std::size_t WAVEOUT_MINBUFFERS = 3; -static constexpr std::size_t WAVEOUT_MAXBUFFERS = 4096; +static constexpr std::size_t WAVEOUT_MINBUFFERS = 3; +static constexpr std::size_t WAVEOUT_MAXBUFFERS = 4096; static constexpr std::size_t WAVEOUT_MINBUFFERFRAMECOUNT = 8; -static constexpr std::size_t WAVEOUT_MAXBUFFERSIZE = 16384; // fits in int16 +static constexpr std::size_t WAVEOUT_MAXBUFFERSIZE = 16384; // fits in int16 -static inline LONG* interlocked_access(DWORD* p) +static inline LONG *interlocked_access(DWORD *p) { static_assert(sizeof(LONG) == sizeof(DWORD)); - return reinterpret_cast(p); + return reinterpret_cast(p); } @@ -50,14 +51,14 @@ { MPT_TRACE_SCOPE(); m_ThreadWakeupEvent = NULL; - m_Failed = false; - m_hWaveOut = NULL; - m_nWaveBufferSize = 0; - m_JustStarted = false; - m_nPreparedHeaders = 0; - m_nWriteBuffer = 0; - m_nDoneBuffer = 0; - m_nBuffersPending = 0; + m_Failed = false; + m_hWaveOut = NULL; + m_nWaveBufferSize = 0; + m_JustStarted = false; + m_nPreparedHeaders = 0; + m_nWriteBuffer = 0; + m_nDoneBuffer = 0; + m_nBuffersPending = 0; MemsetZero(m_PositionLast); m_PositionWrappedCount = 0; } @@ -80,18 +81,18 @@ { MPT_TRACE_SCOPE(); SoundDevice::Caps caps; - caps.Available = true; - caps.CanUpdateInterval = true; - caps.CanSampleFormat = true; - caps.CanExclusiveMode = (GetDeviceIndex() > 0); // no direct mode for WAVE_MAPPER, makes no sense there - caps.CanBoostThreadPriority = true; - caps.CanKeepDeviceRunning = false; - caps.CanUseHardwareTiming = false; - caps.CanChannelMapping = false; - caps.CanInput = false; - caps.HasNamedInputSources = false; - caps.CanDriverPanel = false; - caps.HasInternalDither = false; + caps.Available = true; + caps.CanUpdateInterval = true; + caps.CanSampleFormat = true; + caps.CanExclusiveMode = (GetDeviceIndex() > 0); // no direct mode for WAVE_MAPPER, makes no sense there + caps.CanBoostThreadPriority = true; + caps.CanKeepDeviceRunning = false; + caps.CanUseHardwareTiming = false; + caps.CanChannelMapping = false; + caps.CanInput = false; + caps.HasNamedInputSources = false; + caps.CanDriverPanel = false; + caps.HasInternalDither = false; caps.ExclusiveModeDescription = U_("Use direct mode"); if(GetSysInfo().IsOriginal()) { @@ -104,18 +105,18 @@ } -SoundDevice::DynamicCaps CWaveDevice::GetDeviceDynamicCaps(const std::vector & /*baseSampleRates*/ ) +SoundDevice::DynamicCaps CWaveDevice::GetDeviceDynamicCaps(const std::vector & /*baseSampleRates*/) { MPT_TRACE_SCOPE(); SoundDevice::DynamicCaps caps; if(GetSysInfo().IsOriginal()) { - caps.supportedSampleFormats = { SampleFormatFloat32 }; - caps.supportedExclusiveModeSampleFormats = { SampleFormatFloat32 }; + caps.supportedSampleFormats = {SampleFormatFloat32}; + caps.supportedExclusiveModeSampleFormats = {SampleFormatFloat32}; } else { - caps.supportedSampleFormats = { SampleFormatFloat32, SampleFormatInt32, SampleFormatInt24, SampleFormatInt16, SampleFormatUnsigned8 }; - caps.supportedExclusiveModeSampleFormats = { SampleFormatFloat32, SampleFormatInt32, SampleFormatInt24, SampleFormatInt16, SampleFormatUnsigned8 }; + caps.supportedSampleFormats = {SampleFormatFloat32, SampleFormatInt32, SampleFormatInt24, SampleFormatInt16, SampleFormatUnsigned8}; + caps.supportedExclusiveModeSampleFormats = {SampleFormatFloat32, SampleFormatInt32, SampleFormatInt24, SampleFormatInt16, SampleFormatUnsigned8}; } WAVEOUTCAPS woc; MemsetZero(woc); @@ -124,23 +125,23 @@ caps.supportedExclusiveModeSampleFormats.clear(); if(waveOutGetDevCaps(GetDeviceIndex() - 1, &woc, sizeof(woc)) == MMSYSERR_NOERROR) { - if(woc.dwFormats & (WAVE_FORMAT_96M08 | WAVE_FORMAT_96M16 | WAVE_FORMAT_96S08 | WAVE_FORMAT_96S16)) + if(woc.dwFormats & (WAVE_FORMAT_96M08 | WAVE_FORMAT_96M16 | WAVE_FORMAT_96S08 | WAVE_FORMAT_96S16)) { caps.supportedExclusiveSampleRates.push_back(96000); } - if(woc.dwFormats & (WAVE_FORMAT_48M08 | WAVE_FORMAT_48M16 | WAVE_FORMAT_48S08 | WAVE_FORMAT_48S16)) + if(woc.dwFormats & (WAVE_FORMAT_48M08 | WAVE_FORMAT_48M16 | WAVE_FORMAT_48S08 | WAVE_FORMAT_48S16)) { caps.supportedExclusiveSampleRates.push_back(48000); } - if(woc.dwFormats & (WAVE_FORMAT_4M08 | WAVE_FORMAT_4M16 | WAVE_FORMAT_4S08 | WAVE_FORMAT_4S16)) + if(woc.dwFormats & (WAVE_FORMAT_4M08 | WAVE_FORMAT_4M16 | WAVE_FORMAT_4S08 | WAVE_FORMAT_4S16)) { caps.supportedExclusiveSampleRates.push_back(44100); } - if(woc.dwFormats & (WAVE_FORMAT_2M08 | WAVE_FORMAT_2M16 | WAVE_FORMAT_2S08 | WAVE_FORMAT_2S16)) + if(woc.dwFormats & (WAVE_FORMAT_2M08 | WAVE_FORMAT_2M16 | WAVE_FORMAT_2S08 | WAVE_FORMAT_2S16)) { caps.supportedExclusiveSampleRates.push_back(22050); } - if(woc.dwFormats & (WAVE_FORMAT_1M08 | WAVE_FORMAT_1M16 | WAVE_FORMAT_1S08 | WAVE_FORMAT_1S16)) + if(woc.dwFormats & (WAVE_FORMAT_1M08 | WAVE_FORMAT_1M16 | WAVE_FORMAT_1S08 | WAVE_FORMAT_1S16)) { caps.supportedExclusiveSampleRates.push_back(11025); } @@ -170,9 +171,9 @@ { return false; } - WAVEFORMATEX *pwfx = &wfext.Format; - UINT nWaveDev = GetDeviceIndex(); - nWaveDev = (nWaveDev > 0) ? nWaveDev - 1 : WAVE_MAPPER; + WAVEFORMATEX *pwfx = &wfext.Format; + UINT nWaveDev = GetDeviceIndex(); + nWaveDev = (nWaveDev > 0) ? nWaveDev - 1 : WAVE_MAPPER; m_ThreadWakeupEvent = CreateEvent(NULL, FALSE, FALSE, NULL); if(m_ThreadWakeupEvent == INVALID_HANDLE_VALUE) { @@ -179,9 +180,9 @@ InternalClose(); return false; } - m_Failed = false; + m_Failed = false; m_DriverBugs = 0; - m_hWaveOut = NULL; + m_hWaveOut = NULL; if(waveOutOpen(&m_hWaveOut, nWaveDev, pwfx, (DWORD_PTR)WaveOutCallBack, (DWORD_PTR)this, CALLBACK_FUNCTION | (m_Settings.ExclusiveMode ? WAVE_FORMAT_DIRECT : 0)) != MMSYSERR_NOERROR) { InternalClose(); @@ -192,12 +193,12 @@ InternalClose(); return false; } - m_nWaveBufferSize = mpt::saturate_round(m_Settings.UpdateInterval * pwfx->nAvgBytesPerSec); - m_nWaveBufferSize = Util::AlignUp(m_nWaveBufferSize, pwfx->nBlockAlign); - m_nWaveBufferSize = std::clamp(m_nWaveBufferSize, static_cast(WAVEOUT_MINBUFFERFRAMECOUNT * pwfx->nBlockAlign), static_cast(Util::AlignDown(WAVEOUT_MAXBUFFERSIZE, pwfx->nBlockAlign))); + m_nWaveBufferSize = mpt::saturate_round(m_Settings.UpdateInterval * pwfx->nAvgBytesPerSec); + m_nWaveBufferSize = Util::AlignUp(m_nWaveBufferSize, pwfx->nBlockAlign); + m_nWaveBufferSize = std::clamp(m_nWaveBufferSize, static_cast(WAVEOUT_MINBUFFERFRAMECOUNT * pwfx->nBlockAlign), static_cast(Util::AlignDown(WAVEOUT_MAXBUFFERSIZE, pwfx->nBlockAlign))); std::size_t numBuffers = mpt::saturate_round(m_Settings.Latency * pwfx->nAvgBytesPerSec / m_nWaveBufferSize); - numBuffers = std::clamp(numBuffers, WAVEOUT_MINBUFFERS, WAVEOUT_MAXBUFFERS); - m_nPreparedHeaders = 0; + numBuffers = std::clamp(numBuffers, WAVEOUT_MINBUFFERS, WAVEOUT_MAXBUFFERS); + m_nPreparedHeaders = 0; m_WaveBuffers.resize(numBuffers); m_WaveBuffersData.resize(numBuffers); for(std::size_t buf = 0; buf < numBuffers; ++buf) @@ -204,8 +205,8 @@ { MemsetZero(m_WaveBuffers[buf]); m_WaveBuffersData[buf].resize(m_nWaveBufferSize); - m_WaveBuffers[buf].dwFlags = 0; - m_WaveBuffers[buf].lpData = &m_WaveBuffersData[buf][0]; + m_WaveBuffers[buf].dwFlags = 0; + m_WaveBuffers[buf].lpData = &m_WaveBuffersData[buf][0]; m_WaveBuffers[buf].dwBufferLength = m_nWaveBufferSize; if(waveOutPrepareHeader(m_hWaveOut, &m_WaveBuffers[buf], sizeof(WAVEHDR)) != MMSYSERR_NOERROR) { @@ -221,11 +222,11 @@ } if(m_Settings.sampleFormat == SampleFormatInt8) { - m_Settings.sampleFormat = SampleFormatUnsigned8; + m_Settings.sampleFormat = SampleFormatUnsigned8; } m_nBuffersPending = 0; - m_nWriteBuffer = 0; - m_nDoneBuffer = 0; + m_nWriteBuffer = 0; + m_nDoneBuffer = 0; { mpt::lock_guard guard(m_PositionWraparoundMutex); MemsetZero(m_PositionLast); @@ -247,7 +248,7 @@ m_JustStarted = false; InterlockedExchange(&m_nBuffersPending, 0); m_nWriteBuffer = 0; - m_nDoneBuffer = 0; + m_nDoneBuffer = 0; while(m_nPreparedHeaders > 0) { m_nPreparedHeaders--; @@ -256,14 +257,14 @@ waveOutClose(m_hWaveOut); m_hWaveOut = NULL; } - #ifdef MPT_BUILD_DEBUG - if(m_DriverBugs.load()) - { - SendDeviceMessage(LogError, U_("Errors were detected while playing sound:\n") + GetStatistics().text); - } - #endif +#ifdef MPT_BUILD_DEBUG + if(m_DriverBugs.load()) + { + SendDeviceMessage(LogError, U_("Errors were detected while playing sound:\n") + GetStatistics().text); + } +#endif m_DriverBugs = 0; - m_Failed = false; + m_Failed = false; if(m_ThreadWakeupEvent) { CloseHandle(m_ThreadWakeupEvent); @@ -317,15 +318,12 @@ return true; } if(!m_Failed) - { // only show the first error + { // only show the first error m_Failed = true; TCHAR errortext[MAXERRORLENGTH + 1]; MemsetZero(errortext); waveOutGetErrorText(result, errortext, MAXERRORLENGTH); - SendDeviceMessage(LogError, MPT_UFORMAT("WaveOut error: 0x{}: {}") - ( mpt::ufmt::hex0<8>(result) - , mpt::ToUnicode(mpt::String::ReadWinBuf(errortext)) - )); + SendDeviceMessage(LogError, MPT_UFORMAT("WaveOut error: 0x{}: {}")(mpt::ufmt::hex0<8>(result), mpt::ToUnicode(mpt::String::ReadWinBuf(errortext)))); } RequestClose(); return false; @@ -339,16 +337,12 @@ return true; } if(!m_Failed) - { // only show the first error + { // only show the first error m_Failed = true; TCHAR errortext[MAXERRORLENGTH + 1]; MemsetZero(errortext); waveOutGetErrorText(result, errortext, MAXERRORLENGTH); - SendDeviceMessage(LogError, MPT_UFORMAT("WaveOut error: 0x{} (param 0x{}): {}") - ( mpt::ufmt::hex0<8>(result) - , mpt::ufmt::hex0<8>(param) - , mpt::ToUnicode(mpt::String::ReadWinBuf(errortext)) - )); + SendDeviceMessage(LogError, MPT_UFORMAT("WaveOut error: 0x{} (param 0x{}): {}")(mpt::ufmt::hex0<8>(result), mpt::ufmt::hex0<8>(param), mpt::ToUnicode(mpt::String::ReadWinBuf(errortext)))); } RequestClose(); return false; @@ -362,16 +356,16 @@ { return; } - + const std::size_t bytesPerFrame = m_Settings.GetBytesPerFrame(); - ULONG oldBuffersPending = InterlockedExchangeAdd(&m_nBuffersPending, 0); // read - ULONG nLatency = oldBuffersPending * m_nWaveBufferSize; + ULONG oldBuffersPending = InterlockedExchangeAdd(&m_nBuffersPending, 0); // read + ULONG nLatency = oldBuffersPending * m_nWaveBufferSize; ULONG nBytesWritten = 0; while((oldBuffersPending < m_nPreparedHeaders) && !m_Failed) { - DWORD oldFlags = InterlockedOr(interlocked_access(&m_WaveBuffers[m_nWriteBuffer].dwFlags), 0); + DWORD oldFlags = InterlockedOr(interlocked_access(&m_WaveBuffers[m_nWriteBuffer].dwFlags), 0); uint32 driverBugs = 0; if(oldFlags & WHDR_INQUEUE) { @@ -406,10 +400,10 @@ SourceLockedAudioReadPrepare(m_nWaveBufferSize / bytesPerFrame, nLatency / bytesPerFrame); SourceLockedAudioRead(m_WaveBuffers[m_nWriteBuffer].lpData, nullptr, m_nWaveBufferSize / bytesPerFrame); nBytesWritten += m_nWaveBufferSize; - InterlockedAnd(interlocked_access(&m_WaveBuffers[m_nWriteBuffer].dwFlags), ~static_cast(WHDR_INQUEUE|WHDR_DONE)); + InterlockedAnd(interlocked_access(&m_WaveBuffers[m_nWriteBuffer].dwFlags), ~static_cast(WHDR_INQUEUE | WHDR_DONE)); InterlockedExchange(interlocked_access(&m_WaveBuffers[m_nWriteBuffer].dwBufferLength), m_nWaveBufferSize); InterlockedIncrement(&m_nBuffersPending); - oldBuffersPending++; // increment separately to avoid looping without leaving at all when rendering takes more than 100% CPU + oldBuffersPending++; // increment separately to avoid looping without leaving at all when rendering takes more than 100% CPU CheckResult(waveOutWrite(m_hWaveOut, &m_WaveBuffers[m_nWriteBuffer], sizeof(WAVEHDR)), oldFlags); m_nWriteBuffer++; m_nWriteBuffer %= m_nPreparedHeaders; @@ -423,7 +417,6 @@ m_JustStarted = false; CheckResult(waveOutRestart(m_hWaveOut)); } - } @@ -436,12 +429,12 @@ // We could thereby try to avoid any potential wraparound inside the driver on older // Windows versions, which would be, once converted into other units, really // difficult to detect or handle. - static constexpr UINT timeType = TIME_SAMPLES; // should work for sane systems + static constexpr UINT timeType = TIME_SAMPLES; // should work for sane systems //static constexpr std::size_t valid_bits = 32; // should work for sane systems //static constexpr UINT timeType = TIME_BYTES; // safest - static constexpr std::size_t valid_bits = 27; // safe for WinXP TIME_SAMPLES - static constexpr uint32 valid_mask = static_cast((uint64(1) << valid_bits) - 1u); - static constexpr uint32 valid_watermark = static_cast(uint64(1) << (valid_bits - 1u)); // half the valid range in order to be able to catch backwards fluctuations + static constexpr std::size_t valid_bits = 27; // safe for WinXP TIME_SAMPLES + static constexpr uint32 valid_mask = static_cast((uint64(1) << valid_bits) - 1u); + static constexpr uint32 valid_watermark = static_cast(uint64(1) << (valid_bits - 1u)); // half the valid range in order to be able to catch backwards fluctuations MMTIME mmtime; MemsetZero(mmtime); @@ -451,7 +444,7 @@ return 0; } if(mmtime.wType != TIME_MS && mmtime.wType != TIME_BYTES && mmtime.wType != TIME_SAMPLES) - { // unsupported time format + { // unsupported time format return 0; } int64 offset = 0; @@ -472,13 +465,22 @@ DWORD curval = 0; switch(mmtime.wType) { - case TIME_MS: oldval = m_PositionLast.u.ms; curval = mmtime.u.ms; break; - case TIME_BYTES: oldval = m_PositionLast.u.cb; curval = mmtime.u.cb; break; - case TIME_SAMPLES: oldval = m_PositionLast.u.sample; curval = mmtime.u.sample; break; + case TIME_MS: + oldval = m_PositionLast.u.ms; + curval = mmtime.u.ms; + break; + case TIME_BYTES: + oldval = m_PositionLast.u.cb; + curval = mmtime.u.cb; + break; + case TIME_SAMPLES: + oldval = m_PositionLast.u.sample; + curval = mmtime.u.sample; + break; } oldval &= valid_mask; curval &= valid_mask; - if(((curval - oldval) & valid_mask) >= valid_watermark) // guard against driver problems resulting in time jumping backwards for short periods of time. BEWARE of integer wraparound when refactoring + if(((curval - oldval) & valid_mask) >= valid_watermark) // guard against driver problems resulting in time jumping backwards for short periods of time. BEWARE of integer wraparound when refactoring { curval = oldval; } @@ -488,9 +490,9 @@ case TIME_BYTES: mmtime.u.cb = curval; break; case TIME_SAMPLES: mmtime.u.sample = curval; break; } - if((curval ^ oldval) & valid_watermark) // MSB flipped + if((curval ^ oldval) & valid_watermark) // MSB flipped { - if(!(curval & valid_watermark)) // actually wrapped + if(!(curval & valid_watermark)) // actually wrapped { m_PositionWrappedCount += 1; } @@ -497,7 +499,7 @@ } } m_PositionLast = mmtime; - offset = (static_cast(m_PositionWrappedCount) << valid_bits); + offset = (static_cast(m_PositionWrappedCount) << valid_bits); } int64 result = 0; switch(mmtime.wType) @@ -513,9 +515,9 @@ void CWaveDevice::HandleWaveoutDone(WAVEHDR *hdr) { MPT_TRACE_SCOPE(); - DWORD flags = InterlockedOr(interlocked_access(&hdr->dwFlags), 0); + DWORD flags = InterlockedOr(interlocked_access(&hdr->dwFlags), 0); std::size_t hdrIndex = hdr - &(m_WaveBuffers[0]); - uint32 driverBugs = 0; + uint32 driverBugs = 0; if(hdrIndex != m_nDoneBuffer) { driverBugs |= DriverBugDoneNotificationOutOfOrder; @@ -545,7 +547,7 @@ if((uMsg == WOM_DONE) && (dwUser)) { CWaveDevice *that = (CWaveDevice *)dwUser; - that->HandleWaveoutDone((WAVEHDR*)param1); + that->HandleWaveoutDone((WAVEHDR *)param1); } } @@ -553,9 +555,9 @@ SoundDevice::BufferAttributes CWaveDevice::InternalGetEffectiveBufferAttributes() const { SoundDevice::BufferAttributes bufferAttributes; - bufferAttributes.Latency = m_nWaveBufferSize * m_nPreparedHeaders * 1.0 / m_Settings.GetBytesPerSecond(); + bufferAttributes.Latency = m_nWaveBufferSize * m_nPreparedHeaders * 1.0 / m_Settings.GetBytesPerSecond(); bufferAttributes.UpdateInterval = m_nWaveBufferSize * 1.0 / m_Settings.GetBytesPerSecond(); - bufferAttributes.NumBuffers = m_nPreparedHeaders; + bufferAttributes.NumBuffers = m_nPreparedHeaders; return bufferAttributes; } @@ -565,8 +567,8 @@ MPT_TRACE_SCOPE(); SoundDevice::Statistics result; result.InstantaneousLatency = InterlockedExchangeAdd(&m_nBuffersPending, 0) * m_nWaveBufferSize * 1.0 / m_Settings.GetBytesPerSecond(); - result.LastUpdateInterval = 1.0 * m_nWaveBufferSize / m_Settings.GetBytesPerSecond(); - uint32 bugs = m_DriverBugs.load(); + result.LastUpdateInterval = 1.0 * m_nWaveBufferSize / m_Settings.GetBytesPerSecond(); + uint32 bugs = m_DriverBugs.load(); if(bugs != 0) { result.text = MPT_UFORMAT("Problematic driver detected! Error flags: {}")(mpt::ufmt::hex0<8>(bugs)); @@ -586,17 +588,17 @@ for(UINT index = 0; index <= numDevs; ++index) { SoundDevice::Info info; - info.type = TypeWAVEOUT; - info.internalID = mpt::ufmt::dec(index); - info.apiName = U_("MME"); + info.type = TypeWAVEOUT; + info.internalID = mpt::ufmt::dec(index); + info.apiName = U_("MME"); info.useNameAsIdentifier = true; WAVEOUTCAPS woc; MemsetZero(woc); if(waveOutGetDevCaps((index == 0) ? WAVE_MAPPER : (index - 1), &woc, sizeof(woc)) == MMSYSERR_NOERROR) { - info.name = mpt::ToUnicode(mpt::String::ReadWinBuf(woc.szPname)); - info.extraData[U_("DriverID")] = MPT_UFORMAT("{}:{}")(mpt::ufmt::hex0<4>(woc.wMid), mpt::ufmt::hex0<4>(woc.wPid)); - info.extraData[U_("DriverVersion")] = MPT_UFORMAT("{}.{}")(mpt::ufmt::dec((static_cast(woc.vDriverVersion) >> 24) & 0xff), mpt::ufmt::dec((static_cast(woc.vDriverVersion) >> 0) & 0xff)); + info.name = mpt::ToUnicode(mpt::String::ReadWinBuf(woc.szPname)); + info.extraData[U_("DriverID")] = MPT_UFORMAT("{}:{}")(mpt::ufmt::hex0<4>(woc.wMid), mpt::ufmt::hex0<4>(woc.wPid)); + info.extraData[U_("DriverVersion")] = MPT_UFORMAT("{}.{}")(mpt::ufmt::dec((static_cast(woc.vDriverVersion) >> 24) & 0xff), mpt::ufmt::dec((static_cast(woc.vDriverVersion) >> 0) & 0xff)); } if(info.name.empty()) { @@ -609,24 +611,23 @@ } } info.default_ = ((index == 0) ? Info::Default::Managed : Info::Default::None); - info.flags = { - sysInfo.SystemClass == mpt::OS::Class::Windows ? Info::Usability::Deprecated : Info::Usability::NotAvailable, - Info::Level::Primary, - sysInfo.SystemClass == mpt::OS::Class::Windows && sysInfo.IsWindowsOriginal() ? Info::Compatible::Yes : Info::Compatible::No, - Info::Api::Emulated, - Info::Io::OutputOnly, - Info::Mixing::Software, - Info::Implementor::OpenMPT - }; + info.flags = { + sysInfo.SystemClass == mpt::OS::Class::Windows ? Info::Usability::Deprecated : Info::Usability::NotAvailable, + Info::Level::Primary, + sysInfo.SystemClass == mpt::OS::Class::Windows && sysInfo.IsWindowsOriginal() ? Info::Compatible::Yes : Info::Compatible::No, + Info::Api::Emulated, + Info::Io::OutputOnly, + Info::Mixing::Software, + Info::Implementor::OpenMPT}; devices.push_back(info); } return devices; } -#endif // MPT_OS_WINDOWS +#endif // MPT_OS_WINDOWS -} // namespace SoundDevice +} // namespace SoundDevice OPENMPT_NAMESPACE_END Index: sounddev/SoundDeviceWaveout.h =================================================================== --- sounddev/SoundDeviceWaveout.h (revision 14154) +++ sounddev/SoundDeviceWaveout.h (working copy) @@ -20,13 +20,14 @@ #if MPT_OS_WINDOWS #include -#endif // MPT_OS_WINDOWS +#endif // MPT_OS_WINDOWS OPENMPT_NAMESPACE_BEGIN -namespace SoundDevice { +namespace SoundDevice +{ #if MPT_OS_WINDOWS @@ -35,13 +36,13 @@ { MPT_DECLARE_COMPONENT_MEMBERS public: - ComponentWaveOut() { } - virtual ~ComponentWaveOut() { } + ComponentWaveOut() {} + virtual ~ComponentWaveOut() {} bool DoInitialize() override { return true; } }; -class CWaveDevice: public CSoundDeviceWithThread +class CWaveDevice : public CSoundDeviceWithThread { protected: HANDLE m_ThreadWakeupEvent; @@ -54,17 +55,17 @@ ULONG m_nDoneBuffer; mutable LONG m_nBuffersPending; std::vector m_WaveBuffers; - std::vector > m_WaveBuffersData; + std::vector> m_WaveBuffersData; mutable mpt::mutex m_PositionWraparoundMutex; mutable MMTIME m_PositionLast; mutable std::size_t m_PositionWrappedCount; - static constexpr uint32 DriverBugDoneNotificationAndHeaderInQueue = (1u<<0u); // 1 - static constexpr uint32 DriverBugDoneNotificationAndHeaderNotDone = (1u<<1u); // 2 - static constexpr uint32 DriverBugBufferFillAndHeaderInQueue = (1u<<2u); // 4 - static constexpr uint32 DriverBugBufferFillAndHeaderNotDone = (1u<<3u); // 8 - static constexpr uint32 DriverBugDoneNotificationOutOfOrder = (1u<<4u); // 10 + static constexpr uint32 DriverBugDoneNotificationAndHeaderInQueue = (1u << 0u); // 1 + static constexpr uint32 DriverBugDoneNotificationAndHeaderNotDone = (1u << 1u); // 2 + static constexpr uint32 DriverBugBufferFillAndHeaderInQueue = (1u << 2u); // 4 + static constexpr uint32 DriverBugBufferFillAndHeaderNotDone = (1u << 3u); // 8 + static constexpr uint32 DriverBugDoneNotificationOutOfOrder = (1u << 4u); // 10 std::atomic m_DriverBugs; public: @@ -88,7 +89,6 @@ SoundDevice::DynamicCaps GetDeviceDynamicCaps(const std::vector &baseSampleRates); private: - bool CheckResult(MMRESULT result); bool CheckResult(MMRESULT result, DWORD param); @@ -95,16 +95,16 @@ void HandleWaveoutDone(WAVEHDR *hdr); int GetDeviceIndex() const; - + public: static void CALLBACK WaveOutCallBack(HWAVEOUT, UINT uMsg, DWORD_PTR, DWORD_PTR dw1, DWORD_PTR dw2); static std::vector EnumerateDevices(SoundDevice::SysInfo sysInfo); }; -#endif // MPT_OS_WINDOWS +#endif // MPT_OS_WINDOWS -} // namespace SoundDevice +} // namespace SoundDevice OPENMPT_NAMESPACE_END