Browse Source

Fix for ALSA CPU use when using an input device without an output device.

tags/2021-05-28
jules 10 years ago
parent
commit
45c620a996
1 changed files with 20 additions and 6 deletions
  1. +20
    -6
      modules/juce_audio_devices/native/juce_linux_ALSA.cpp

+ 20
- 6
modules/juce_audio_devices/native/juce_linux_ALSA.cpp View File

@@ -149,7 +149,7 @@ class ALSADevice
{ {
public: public:
ALSADevice (const String& devID, bool forInput) ALSADevice (const String& devID, bool forInput)
: handle (0),
: handle (nullptr),
bitDepth (16), bitDepth (16),
numChannelsRunning (0), numChannelsRunning (0),
latency (0), latency (0),
@@ -183,16 +183,16 @@ public:
void closeNow() void closeNow()
{ {
if (handle != 0)
if (handle != nullptr)
{ {
snd_pcm_close (handle); snd_pcm_close (handle);
handle = 0;
handle = nullptr;
} }
} }
bool setParameters (unsigned int sampleRate, int numChannels, int bufferSize) bool setParameters (unsigned int sampleRate, int numChannels, int bufferSize)
{ {
if (handle == 0)
if (handle == nullptr)
return false; return false;
JUCE_ALSA_LOG ("ALSADevice::setParameters(" << deviceID << ", " JUCE_ALSA_LOG ("ALSADevice::setParameters(" << deviceID << ", "
@@ -644,8 +644,21 @@ public:
{ {
while (! threadShouldExit()) while (! threadShouldExit())
{ {
if (inputDevice != nullptr && inputDevice->handle)
if (inputDevice != nullptr && inputDevice->handle != nullptr)
{ {
if (outputDevice == nullptr || outputDevice->handle == nullptr)
{
JUCE_ALSA_FAILED (snd_pcm_wait (inputDevice->handle, 2000));
if (threadShouldExit())
break;
snd_pcm_sframes_t avail = snd_pcm_avail_update (inputDevice->handle);
if (avail < 0)
JUCE_ALSA_FAILED (snd_pcm_recover (inputDevice->handle, avail, 0));
}
audioIoInProgress = true; audioIoInProgress = true;
if (! inputDevice->readFromInputDevice (inputChannelBuffer, bufferSize)) if (! inputDevice->readFromInputDevice (inputChannelBuffer, bufferSize))
@@ -679,7 +692,7 @@ public:
} }
} }
if (outputDevice != nullptr && outputDevice->handle)
if (outputDevice != nullptr && outputDevice->handle != nullptr)
{ {
JUCE_ALSA_FAILED (snd_pcm_wait (outputDevice->handle, 2000)); JUCE_ALSA_FAILED (snd_pcm_wait (outputDevice->handle, 2000));
@@ -702,6 +715,7 @@ public:
audioIoInProgress = false; audioIoInProgress = false;
} }
} }
audioIoInProgress = false; audioIoInProgress = false;
} }


Loading…
Cancel
Save