| @@ -64,7 +64,7 @@ struct AudioFilePool { | |||
| CARLA_ASSERT(startFrame == 0); | |||
| CARLA_ASSERT(size == 0); | |||
| size = srate * 8; | |||
| size = srate * 60; // buffer of 60 secs | |||
| sampleRate = srate; | |||
| buffer[0] = new float[size]; | |||
| @@ -268,21 +268,34 @@ public: | |||
| } | |||
| } | |||
| void tryPutData(AudioFilePool& pool) | |||
| bool tryPutData(AudioFilePool& pool, const uint32_t framePos, const uint32_t frames) | |||
| { | |||
| CARLA_SAFE_ASSERT_RETURN(pool.size == fPool.size,); | |||
| CARLA_SAFE_ASSERT_RETURN(pool.size == fPool.size, false); | |||
| if (! fMutex.tryLock()) | |||
| return; | |||
| return false; | |||
| //if (pool.startFrame != fPool.startFrame || pool.buffer[0] != fPool.buffer[0] || pool.buffer[1] != fPool.buffer[1]) | |||
| { | |||
| pool.startFrame = fPool.startFrame; | |||
| carla_copyFloats(pool.buffer[0], fPool.buffer[0], fPool.size); | |||
| carla_copyFloats(pool.buffer[1], fPool.buffer[1], fPool.size); | |||
| (void)frames; | |||
| if (frames == 0) | |||
| { | |||
| carla_copyFloats(pool.buffer[0], fPool.buffer[0], fPool.size); | |||
| carla_copyFloats(pool.buffer[1], fPool.buffer[1], fPool.size); | |||
| } | |||
| else | |||
| { | |||
| CARLA_SAFE_ASSERT_UINT2_RETURN(framePos + frames < fPool.size, framePos, fPool.size, false); | |||
| carla_copyFloats(pool.buffer[0] + framePos, fPool.buffer[0] + framePos, frames); | |||
| carla_copyFloats(pool.buffer[1] + framePos, fPool.buffer[1] + framePos, frames); | |||
| } | |||
| } | |||
| fMutex.unlock(); | |||
| return true; | |||
| } | |||
| void readPoll() | |||
| @@ -417,8 +430,8 @@ protected: | |||
| if (fNeedsRead || lastFrame < fPool.startFrame || (lastFrame - fPool.startFrame >= fPool.size*3/4 && loopedFrame < fMaxPlayerFrame)) | |||
| readPoll(); | |||
| else | |||
| carla_msleep(50); | |||
| carla_msleep(50); | |||
| } | |||
| } | |||
| @@ -149,8 +149,6 @@ protected: | |||
| return; | |||
| } | |||
| fThread.tryPutData(fPool); | |||
| // out of reach | |||
| if (timePos->frame + frames < fPool.startFrame || (timePos->frame >= fMaxFrame && !fLoopMode)) | |||
| { | |||
| @@ -169,26 +167,30 @@ protected: | |||
| } | |||
| const uint32_t poolSize = fPool.size; | |||
| int64_t poolFrame = static_cast<uint32_t>(timePos->frame - fPool.startFrame); | |||
| float* const bufferL = fPool.buffer[0]; | |||
| float* const bufferR = fPool.buffer[1]; | |||
| for (uint32_t i=0; i < frames; ++i, ++poolFrame) | |||
| int64_t poolFrame = static_cast<int64_t>(timePos->frame - fPool.startFrame); | |||
| if (poolFrame >= 0 && poolFrame < poolSize && fThread.tryPutData(fPool, static_cast<uint32_t>(poolFrame), frames)) | |||
| { | |||
| if (poolFrame >= 0 && poolFrame < poolSize) | |||
| { | |||
| out1[i] = bufferL[poolFrame]; | |||
| out2[i] = bufferR[poolFrame]; | |||
| const uint32_t framesToCopy = std::min(frames, static_cast<uint32_t>(poolSize - poolFrame)); | |||
| carla_copyFloats(out1, bufferL + poolFrame, framesToCopy); | |||
| carla_copyFloats(out2, bufferR + poolFrame, framesToCopy); | |||
| // reset | |||
| bufferL[poolFrame] = 0.0f; | |||
| bufferR[poolFrame] = 0.0f; | |||
| } | |||
| else | |||
| if (const uint32_t remainingFrames = frames - framesToCopy) | |||
| { | |||
| out1[i] = 0.0f; | |||
| out2[i] = 0.0f; | |||
| carla_zeroFloats(out1 + framesToCopy, remainingFrames); | |||
| carla_zeroFloats(out2 + framesToCopy, remainingFrames); | |||
| } | |||
| carla_zeroFloats(bufferL + poolFrame, framesToCopy); | |||
| carla_zeroFloats(bufferR + poolFrame, framesToCopy); | |||
| } | |||
| else | |||
| { | |||
| carla_zeroFloats(out1, frames); | |||
| carla_zeroFloats(out2, frames); | |||
| } | |||
| fLastFrame = timePos->frame; | |||