also looking at this
feat(audio): add verified AAC-LC encoding and reject invalid prototype output
#918
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.
| @@ -16,7 +16,14 @@ pub const AacProfile = enum(u5) { | ||
| 16 | 16 | aac_scalable = 6, |
| 17 | 17 | |
| 18 | 18 | 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 | }; | |
| 20 | 27 | } |
| 21 | 28 | }; |
| 22 | 29 | |
| @@ -271,8 +278,27 @@ pub const AudioSpecificConfig = struct { | ||
| 271 | 278 | var config: [2]u8 = undefined; |
| 272 | 279 | |
| 273 | 280 | 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 | }; | |
| 276 | 302 | |
| 277 | 303 | // audioObjectType (5 bits) + samplingFrequencyIndex (4 bits) |
| 278 | 304 | config[0] = @as(u8, aot) << 3; |