ReviewOS

also looking at this

home-lang/home

feat(audio): add verified AAC-LC encoding and reject invalid prototype output

#918
Merged chris wants to merge feat/aac-mp4-recording into main
10 files +318 -471

Review threads live on the whole diff, not on one commit, so none are shown here - a thread's line means something in the branch's final form, and painting it into an intermediate step would put it on code it is not about.

packages/audio/src/encoding/aac_encoder.zigmodified+29-3
Changes to packages/audio/src/encoding/aac_encoder.zig
@@ -16,7 +16,14 @@ pub const AacProfile = enum(u5) {
1616 aac_scalable = 6,
1717
1818 pub fn getAudioObjectType(self: AacProfile) u5 {
19 return @as(u5, @bitCast(self));
19 return switch (self) {
20 .aac_main => 1,
21 .aac_lc => 2,
22 .aac_ssr => 3,
23 .aac_ltp => 4,
24 .sbr => 5,
25 .aac_scalable => 6,
26 };
2027 }
2128};
2229
@@ -271,8 +278,27 @@ pub const AudioSpecificConfig = struct {
271278 var config: [2]u8 = undefined;
272279
273280 const aot = self.audio_object_type.getAudioObjectType();
274 const sri = @as(u4, @bitCast(SampleRateIndex.fromRate(self.sample_rate)));
275 const cc = @backingInt(ChannelConfig.fromChannels(self.channels));
281 const sri: u4 = switch (self.sample_rate) {
282 96000 => 0,
283 88200 => 1,
284 64000 => 2,
285 48000 => 3,
286 44100 => 4,
287 32000 => 5,
288 24000 => 6,
289 22050 => 7,
290 16000 => 8,
291 12000 => 9,
292 11025 => 10,
293 8000 => 11,
294 7350 => 12,
295 else => 4,
296 };
297 const cc: u4 = switch (self.channels) {
298 1...6 => @intCast(self.channels),
299 8 => 7,
300 else => 2,
301 };
276302
277303 // audioObjectType (5 bits) + samplingFrequencyIndex (4 bits)
278304 config[0] = @as(u8, aot) << 3;