From c5e9ca56d446819bfd42615d2398e3817a286ef9 Mon Sep 17 00:00:00 2001 From: Wohlstand Date: Tue, 3 Dec 2019 15:34:39 +0300 Subject: MidiSequencer: Added PCM streaming code This code piece should simplify a dealing with MIDI libraries TODO: Modify some content of adl_playFormat() to use this feature --- src/midi_sequencer.hpp | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) (limited to 'src/midi_sequencer.hpp') diff --git a/src/midi_sequencer.hpp b/src/midi_sequencer.hpp index 1eb5873..6832492 100644 --- a/src/midi_sequencer.hpp +++ b/src/midi_sequencer.hpp @@ -511,6 +511,34 @@ private: //! Common error string std::string m_errorString; + struct SequencerTime + { + //! Time buffer + double timeRest; + //! Sample rate + uint32_t sampleRate; + //! Size of one frame in bytes + uint32_t frameSize; + //! Minimum possible delay, granuality + double minDelay; + //! Last delay + double delay; + + void init() + { + sampleRate = 44100; + frameSize = 2; + reset(); + } + + void reset() + { + timeRest = 0.0; + minDelay = 1.0 / static_cast(sampleRate); + delay = 0.0; + } + } m_time; + public: BW_MidiSequencer(); virtual ~BW_MidiSequencer(); @@ -521,6 +549,14 @@ public: */ void setInterface(const BW_MidiRtInterface *intrf); + /** + * @brief Runs ticking in a sync with audio streaming. Use this together with onPcmRender hook to easily play MIDI. + * @param stream pointer to the output PCM stream + * @param length length of the buffer in bytes + * @return Count of recorded data in bytes + */ + int playStream(uint8_t *stream, size_t length); + /** * @brief Returns file format type of currently loaded file * @return File format type enumeration -- cgit v1.2.3