Skip to content

Conversation

@alexlivekit
Copy link
Contributor

@alexlivekit alexlivekit commented Jan 7, 2026

If we ever want a fancier version (used mostly for VAD, or Voice Activity Detection), where our noise floor is dynamically calculated (this helps indicate speech even in noisier environments), we can look at the implementation in signal-logger-adaptive.

For now, the purpose of this feature is to output whether there's any signal, voice or noise, for sanity and debugging.

@alexlivekit alexlivekit force-pushed the signal-logger branch 8 times, most recently from 2df31f9 to 0464494 Compare January 13, 2026 04:40
@alexlivekit alexlivekit marked this pull request as ready for review January 26, 2026 19:44
@alexlivekit alexlivekit requested a review from a team as a code owner January 26, 2026 19:44
disp.RingingTimeout = defaultRingingTimeout
}
disp.Room.JitterBuf = c.jitterBuf
if disp.FeatureFlags != nil {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is okay to omit this change, map lookup will still work on nil value.

}

logSignalChanges := false
if featureFlags != nil {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here, no need for a check

if p.logSignalChanges {
audioOut, err = NewSignalLogger(p.log, "mixed", audioOut)
if err != nil {
return err
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to close original audioOut here.

codec, err := opus.Decode(mTrack, channels, log)
var out msdk.PCM16Writer = mTrack
if rconf.LogSignalChanges {
out, _ = NewSignalLogger(log, track.ID(), out)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not even logging an error? This could silenty write nil to out.

// Keeps an internal state of whether we're currently transmitting signal (voice or noise), or silence.
// This implements msdk.PCM16Writer to inspect decoded packet content.
// Used to log changes betweem those states.
type SignalLogger struct {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should consider moving it to media-sdk, since it's not SIP-specific.


s.framesProcessed++
if s.framesProcessed > 10 { // Don't log any changes at first
if isSignal && isSignal != s.lastIsSignal { // silence -> signal: Immediate transition
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could potentially hit each frame, wouldn't it be too spammy?

}

func (s *SignalLogger) WriteSample(sample msdk.PCM16Sample) error {
currentEnergy := s.MeanAbsoluteDeviation(sample)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably doesn't matter here, but energy is usually computed as a square of amplitude. Maybe rename to ampMean?

totalAbs += int64(v)
}
}
return float64(totalAbs) / float64(len(sample))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could also consider calculating a median, it will be less affected by sudden spikes.

hangoverDuration: DefaultHangoverDuration,
signalMultiplier: DefaultSignalMultiplier,
noiseFloor: DefaultNoiseFloor,
lastSignalTime: time.Time{},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to initialize explicitly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants