Skip to content

[mod_voicemail] Fix message length when recording at another sample rate - #3231

Open
andreinknv wants to merge 1 commit into
signalwire:masterfrom
andreinknv:voicemail-message-len-rate
Open

andreinknv wants to merge 1 commit into
signalwire:masterfrom
andreinknv:voicemail-message-len-rate

Conversation

@andreinknv

Copy link
Copy Markdown

Fixes #3229

create_file() computed the message length, and with it the min-record-len check, as fh.samples_out / fh.samplerate. samples_out counts channel-rate samples, taken before the core resamples to the file rate. So when record-sample-rate (or the record_sample_rate channel variable) differs from the call's rate, the length is divided by the rate ratio. An 8 kHz caller recorded at 16 kHz gets half the real message_len, and messages shorter than 6 s are discarded. At 48 kHz the length is a sixth, and messages shorter than 18 s are discarded.

The fix divides by fh.native_rate, the channel rate that switch_ivr_record_file() already uses for record_seconds. When that is not set it falls back to the previous divisor. Nothing changes when the file and call rates are the same.

Prepared with the help of an AI coding assistant; the reproduction and results below were run locally.

Testing: FreeSWITCH master 12ac48a on Debian 13 arm64. An 8 kHz loopback leg plays a continuous 440 Hz tone into voicemail (greeting and instructions skipped) and hangs up. min-record-len is 3. Stored message_len compared with the length of the recorded WAV:

record-sample-rate tone build reps outcome stored message_len (s) real file length (s)
0 (channel rate) 5 s master 5 stored x5 5 5.22-5.24
0 (channel rate) 5 s fix 5 stored x5 5 5.22-5.24
0 (channel rate) 12 s master 5 stored x5 12 12.56-12.58
0 (channel rate) 12 s fix 5 stored x5 12 12.54-12.56
0 (channel rate) 30 s master 5 stored x5 30 30.54-30.58
0 (channel rate) 30 s fix 5 stored x5 30 30.54-30.58
16000 5 s master 5 discarded x5 - - (file deleted)
16000 5 s fix 5 stored x5 5 5.22-5.24
16000 12 s master 5 stored x5 6 12.54-12.58
16000 12 s fix 5 stored x5 12 12.54-12.58
16000 30 s master 5 stored x5 15 30.48-30.58
16000 30 s fix 5 stored x5 30 30.50-30.56
48000 5 s master 5 discarded x5 - - (file deleted)
48000 5 s fix 5 stored x5 5 5.22-5.24
48000 12 s master 5 discarded x5 - - (file deleted)
48000 12 s fix 5 stored x5 12 12.54-12.56
48000 30 s master 5 stored x5 5 30.56-30.58
48000 30 s fix 5 stored x5 30 30.54-30.58

The module builds with the project flags (-Wall -Werror -pedantic -std=c99). A build with -Wextra shows the same 41 warnings before and after the change.

🤖 Generated with Claude Code

`create_file()` computed the message length, and with it the
`min-record-len` check, as `fh.samples_out / fh.samplerate`.
`samples_out` is counted in channel-rate samples, before the core
resamples to the file rate (`fh.native_rate`), so whenever the file rate
differs from the call's rate the length is divided by the rate ratio.
With `record-sample-rate` set to 16000 an 8 kHz caller's 12 second
message is stored as 6 seconds and a 5 second one is discarded as too
short; at 48000 messages under 18 seconds are discarded.

Divide by `fh.native_rate`, as `switch_ivr_record_file()` does for
`record_seconds`, and fall back to the previous divisor when it is not
set.
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.

[mod_voicemail] Wrong message length and valid messages discarded when record-sample-rate differs from the call rate

1 participant