ws-apifix: one bitrate unit: every encoder's bitrate option is bit/s (MP3 now too), values below 1000 are kbit/s (the old MP3 values keep working; Opus accepts them too); the MP3 Decoder's bitrate field is bit/s as the Decoder contract says (was kbit/s)

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
4DBugandClaude Opus 5.5 committed 2026-10-31 14:06:51 -05:00
1 parent c4168d751f
commit 51630729f6
10 files changed
+35 -14

No files matched your search

+5 -1
View File
@@ -15,7 +15,8 @@ local CeltEncoder = require("@formats/codecs/audio/Opus/CeltEncoder")
local Encode = {}
export type Options = {
bitrate: number?, -- bits per second (default 64000 per channel; 6000 .. 510000, constant)
bitrate: number?, -- bits per second (default 64000 per channel; 6000 .. 510000, constant); values below 1000
-- are kbit/s (96 = 96000), as for every encoder's bitrate option
tags: { [string]: string }?, -- default: the audio's tags
vendor: string?, -- OpusTags vendor (default "formats-luau")
serial: number?, -- Ogg stream serial (default 0x4f707573)
@@ -39,6 +40,9 @@ function Encode.encode(value: any, opts: Options?): (buffer?, Err.Err?)
return nil, Err.new(Err.ARG, "bad sample rate " .. tostring(rate))
end
local bitrate = o.bitrate or 64000 * ch
if type(bitrate) == "number" and bitrate > 0 and bitrate < 1000 then
bitrate *= 1000 -- kbit/s
end
if type(bitrate) ~= "number" or bitrate < 6000 or bitrate > 510000 then
return nil, Err.new(Err.ARG, "bitrate 6000 .. 510000")
end