fix: keep the audio captured while waiting for a silent source
The operator asked the right question: why wait 1.5 s at all, when the mode is known from CAT? Because the wait is not the problem — what happened during it was. The drift guard, meant for two sound cards running on their own clocks, saw a starved source as a one-second skew and trimmed the radio audio to match. So the opening of every CW recording was thrown away although it had been captured. The guard now applies only while BOTH sources are actually delivering. Waiting then costs nothing: everything buffered is written whole the moment the silent source is written off, which a test now pins with three seconds of audio. Using the CAT mode to skip the wait would have been a second mechanism for a case this one already covers — and it would not cover the others: a device switched off, unplugged, or held by another program.
This commit is contained in:
@@ -88,3 +88,36 @@ func TestMixerWritesOffASourceThatNeverSpoke(t *testing.T) {
|
||||
t.Errorf("sample = %d, want 700", r.acc[0])
|
||||
}
|
||||
}
|
||||
|
||||
// Nothing captured during the grace period is thrown away.
|
||||
//
|
||||
// The drift guard exists for two sound cards running on their own clocks. A
|
||||
// STARVED source is not drift, and treating it as such discarded the radio
|
||||
// audio a second at a time while the mixer was still waiting for the mic — so
|
||||
// the opening of every CW recording was lost although it had been captured.
|
||||
func TestGracePeriodKeepsWhatWasCaptured(t *testing.T) {
|
||||
r := &Recorder{twoSrc: true, gainA: 1, gainB: 1, running: true, active: true, prerollSamples: sampleRate}
|
||||
r.startedAt = time.Now()
|
||||
|
||||
// Three seconds of radio audio arrive while the mic says nothing at all.
|
||||
r.bufA = make([]int16, 3*sampleRate)
|
||||
for i := range r.bufA {
|
||||
r.bufA[i] = 500
|
||||
}
|
||||
r.lastA = time.Now()
|
||||
r.mixTick() // still inside the grace period: nothing is written yet…
|
||||
|
||||
if len(r.acc) != 0 {
|
||||
t.Fatalf("wrote %d samples before the mic was written off", len(r.acc))
|
||||
}
|
||||
if len(r.bufA) != 3*sampleRate {
|
||||
t.Fatalf("buffered audio was trimmed to %d samples — it must be kept, not dropped", len(r.bufA))
|
||||
}
|
||||
|
||||
// …and once the mic is written off, everything captured comes through.
|
||||
r.startedAt = time.Now().Add(-5 * time.Second)
|
||||
r.mixTick()
|
||||
if len(r.acc) != 3*sampleRate {
|
||||
t.Errorf("recorded %d samples, want the full %d captured during the wait", len(r.acc), 3*sampleRate)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user