diff --git a/include/boo/audiodev/IAudioVoiceEngine.hpp b/include/boo/audiodev/IAudioVoiceEngine.hpp index 736b43d..e38b922 100644 --- a/include/boo/audiodev/IAudioVoiceEngine.hpp +++ b/include/boo/audiodev/IAudioVoiceEngine.hpp @@ -64,6 +64,9 @@ struct IAudioVoiceEngine /** Open named MIDI in/out port, name format depends on OS */ virtual std::unique_ptr newRealMIDIInOut(const char* name, ReceiveFunctor&& receiver)=0; + + /** If this returns true, MIDI callbacks are assumed to be *not* thread-safe; need protection via mutex */ + virtual bool useMIDILock() const=0; }; /** Construct host platform's voice engine */ diff --git a/include/boo/audiodev/IMIDIPort.hpp b/include/boo/audiodev/IMIDIPort.hpp index 3c78c54..aae09ea 100644 --- a/include/boo/audiodev/IMIDIPort.hpp +++ b/include/boo/audiodev/IMIDIPort.hpp @@ -9,7 +9,7 @@ namespace boo { -using ReceiveFunctor = std::function&&)>; +using ReceiveFunctor = std::function&&, double time)>; class IMIDIPort { diff --git a/lib/audiodev/AQS.cpp b/lib/audiodev/AQS.cpp index 38c1676..7ee881b 100644 --- a/lib/audiodev/AQS.cpp +++ b/lib/audiodev/AQS.cpp @@ -231,7 +231,8 @@ struct AQSAudioVoiceEngine : BaseAudioVoiceEngine for (int i=0 ; inumPackets ; ++i) { std::vector bytes(std::cbegin(packet->data), std::cbegin(packet->data) + packet->length); - readProcRefCon->m_receiver(std::move(bytes)); + ; + readProcRefCon->m_receiver(std::move(bytes), AudioConvertHostTimeToNanos(packet->timeStamp) / 1.0e9); packet = MIDIPacketNext(packet); } } @@ -533,6 +534,8 @@ struct AQSAudioVoiceEngine : BaseAudioVoiceEngine return ret; } + + bool useMIDILock() const {return true;} AQSAudioVoiceEngine() { diff --git a/lib/audiodev/AudioSubmix.hpp b/lib/audiodev/AudioSubmix.hpp index a9215d7..7bec528 100644 --- a/lib/audiodev/AudioSubmix.hpp +++ b/lib/audiodev/AudioSubmix.hpp @@ -6,6 +6,8 @@ #include #include +struct AudioUnitVoiceEngine; + namespace boo { class BaseAudioVoiceEngine; @@ -15,6 +17,7 @@ class AudioSubmix : public IAudioSubmix, public IAudioMix { friend class BaseAudioVoiceEngine; friend struct WASAPIAudioVoiceEngine; + friend struct ::AudioUnitVoiceEngine; /* Mixer-engine relationships */ BaseAudioVoiceEngine& m_root; diff --git a/lib/audiodev/AudioVoice.hpp b/lib/audiodev/AudioVoice.hpp index 2b75dcd..d4e0ef7 100644 --- a/lib/audiodev/AudioVoice.hpp +++ b/lib/audiodev/AudioVoice.hpp @@ -6,6 +6,8 @@ #include "boo/audiodev/IAudioVoice.hpp" #include "AudioMatrix.hpp" +struct AudioUnitVoiceEngine; + namespace boo { class BaseAudioVoiceEngine; @@ -17,6 +19,7 @@ class AudioVoice : public IAudioVoice friend class BaseAudioVoiceEngine; friend class AudioSubmix; friend struct WASAPIAudioVoiceEngine; + friend struct ::AudioUnitVoiceEngine; protected: /* Mixer-engine relationships */ @@ -68,6 +71,8 @@ public: void start(); void stop(); void unbindVoice(); + double getSampleRateIn() const {return m_sampleRateIn;} + double getSampleRateOut() const {return m_sampleRateOut;} }; class AudioVoiceMono : public AudioVoice