Midi input causes audio glitches.

This commit is contained in:
Robin Davies
2024-09-14 06:46:50 -04:00
parent 2b0118472f
commit 8df23db41c
+20 -7
View File
@@ -1422,17 +1422,31 @@ namespace pipedal
} }
// snd_pcm_wait(captureHandle, 1); // snd_pcm_wait(captureHandle, 1);
ssize_t framesToRead = bufferSize;
ssize_t framesRead; ssize_t framesRead = 0;
if ((framesRead = ReadBuffer(captureHandle, this->rawCaptureBuffer, bufferSize)) < 0) bool xrun = false;
while (framesToRead != 0)
{
ssize_t thisTime = framesToRead;
ssize_t nFrames;
if ((nFrames = ReadBuffer(
captureHandle,
this->rawCaptureBuffer + this->captureFrameSize*framesRead,
bufferSize)) < 0)
{ {
this->driverHost->OnUnderrun(); this->driverHost->OnUnderrun();
auto state = snd_pcm_state(playbackHandle); auto state = snd_pcm_state(playbackHandle);
XrunRecoverInputUnderrun(captureHandle, framesRead); XrunRecoverInputUnderrun(captureHandle, nFrames);
xrun = true;
break;
}
framesRead += nFrames;
framesToRead -= nFrames;
}
if (xrun)
{
continue; continue;
} }
else
{
cpuUse.AddSample(ProfileCategory::Read); cpuUse.AddSample(ProfileCategory::Read);
if (framesRead == 0) if (framesRead == 0)
continue; continue;
@@ -1462,7 +1476,6 @@ namespace pipedal
cpuUse.AddSample(ProfileCategory::Write); cpuUse.AddSample(ProfileCategory::Write);
} }
} }
}
catch (const std::exception &e) catch (const std::exception &e)
{ {
Lv2Log::error(e.what()); Lv2Log::error(e.what());