From 70429ade14ff73bcb6fa3a8a01ae202757da8c7d Mon Sep 17 00:00:00 2001 From: Cesare Ferrari Date: Thu, 25 Jul 2019 12:24:29 +0100 Subject: [PATCH] Improve bela performance --- .../native/juce_linux_Bela.cpp | 24 +++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) mode change 100644 => 100755 modules/juce_audio_devices/native/juce_linux_Bela.cpp diff --git a/modules/juce_audio_devices/native/juce_linux_Bela.cpp b/modules/juce_audio_devices/native/juce_linux_Bela.cpp old mode 100644 new mode 100755 index ce479f004e..363e3c571d --- a/modules/juce_audio_devices/native/juce_linux_Bela.cpp +++ b/modules/juce_audio_devices/native/juce_linux_Bela.cpp @@ -34,6 +34,8 @@ public: { jassert (midiCallback != nullptr); midiInputs.add (this); + + buffer.resize (32); } ~BelaMidiInput() @@ -54,6 +56,8 @@ public: void poll() { + int receivedBytes = 0; + for (;;) { auto data = midi.getInput(); @@ -61,9 +65,18 @@ public: if (data < 0) break; - auto byte = (uint8) data; - concatenator.pushMidiData (&byte, 1, Time::getMillisecondCounter() * 0.001, midiInput, *midiCallback); + buffer[receivedBytes] = (uint8) data; + receivedBytes++; + + if (receivedBytes == buffer.size()) + { + pushMidiData (receivedBytes); + receivedBytes = 0; + } } + + if (receivedBytes > 0) + pushMidiData (receivedBytes); } static Array getDevices (bool input) @@ -77,6 +90,13 @@ public: } private: + void pushMidiData (int length) + { + concatenator.pushMidiData (buffer.data(), length, Time::getMillisecondCounter() * 0.001, midiInput, *midiCallback); + } + + std::vector buffer; + static Array findAllALSACardIDs() { Array cards;