package audio import ( "testing" "time" ) // A silent second source must not silence the recording. // // From a real session: a Flex with "From Radio" on DAX RX and "Recording mic" // on DAX Mic. In CW the mic path does not run, so DAX Mic delivered nothing — // and because the mixer took min(len(A), len(B)) samples, nothing at all was // recorded. The whole QSO ended in "recording was empty". func TestMixerSurvivesASilentSource(t *testing.T) { r := &Recorder{twoSrc: true, gainA: 1, gainB: 1, running: true, active: true, prerollSamples: sampleRate} // The radio has been talking; the mic has not spoken for well over the // grace period. r.bufA = make([]int16, 800) for i := range r.bufA { r.bufA[i] = 1000 } r.lastA = time.Now() r.lastB = time.Now().Add(-5 * time.Second) r.mixTick() if len(r.acc) == 0 { t.Fatal("nothing was recorded — a silent mic must not stop the radio being captured") } if r.acc[0] != 1000 { t.Errorf("sample = %d, want 1000 — the live source must pass through unchanged", r.acc[0]) } } // While BOTH sources are alive the two are mixed, as before. func TestMixerStillMixesBothSources(t *testing.T) { r := &Recorder{twoSrc: true, gainA: 1, gainB: 1, running: true, active: true, prerollSamples: sampleRate} r.bufA = []int16{100, 100, 100} r.bufB = []int16{50, 50, 50} now := time.Now() r.lastA, r.lastB = now, now r.mixTick() if len(r.acc) != 3 { t.Fatalf("recorded %d samples, want 3", len(r.acc)) } if r.acc[0] != 150 { t.Errorf("sample = %d, want 150 — both sources should be summed", r.acc[0]) } } // Before either source has EVER delivered, neither may be written off: at // startup both timestamps are zero, and declaring one dead then would drop the // first moments of every recording. func TestMixerWaitsForBothAtStartup(t *testing.T) { r := &Recorder{twoSrc: true, gainA: 1, gainB: 1, running: true, active: true, prerollSamples: sampleRate} r.bufA = []int16{100, 100} // lastA/lastB both zero — nothing has been heard from either yet. r.mixTick() if len(r.acc) != 0 { t.Errorf("recorded %d samples before the second source was known to be silent", len(r.acc)) } }