audio: master-clock playback timing, output clock compensation, buffer config, interpolated speed

- playback timer uses the audio output device as its master clock: the
  PortAudio callback counts consumed frames (including underrun
  zero-fill) so video cannot drift away from what is heard; wall clock
  remains as fallback when no clocked output is running
- output clock compensates for device output latency; new Preferences >
  Audio buffer size setting (0 = auto)
- SampleBuffer::speed() now uses linear interpolation instead of
  nearest-neighbor sampling
- regression tests: audio-clock driven timer (fwd/rev/speed), wall
  clock fallback, interpolation correctness
This commit is contained in:
2026-07-19 21:44:34 +08:00
parent 0c02ff0d77
commit a7ddc0f114
16 changed files with 266 additions and 8 deletions
+23
View File
@@ -251,6 +251,29 @@ TEST(CoreSampleBuffer, Speed)
EXPECT_FLOAT_EQ(b.data(0)[1], 0.3f);
}
TEST(CoreSampleBuffer, SpeedInterpolatesBetweenSamples)
{
AudioParams params = make_params();
SampleBuffer b(params, 4);
b.data(0)[0] = 0.0f;
b.data(0)[1] = 1.0f;
b.data(0)[2] = 0.0f;
b.data(0)[3] = -1.0f;
// 0.5x doubles the length; odd output samples sit exactly between two
// input samples and must be interpolated, not nearest-neighbor picked
b.speed(0.5);
ASSERT_EQ(b.sample_count(), 8u);
EXPECT_FLOAT_EQ(b.data(0)[0], 0.0f);
EXPECT_FLOAT_EQ(b.data(0)[1], 0.5f);
EXPECT_FLOAT_EQ(b.data(0)[2], 1.0f);
EXPECT_FLOAT_EQ(b.data(0)[3], 0.5f);
EXPECT_FLOAT_EQ(b.data(0)[4], 0.0f);
EXPECT_FLOAT_EQ(b.data(0)[5], -0.5f);
EXPECT_FLOAT_EQ(b.data(0)[6], -1.0f);
EXPECT_FLOAT_EQ(b.data(0)[7], -1.0f); // clamped at the last sample
}
TEST(CoreSampleBuffer, UnallocatedOperationsNoCrash)
{
SampleBuffer b;