2020-06-08 03:29:51 +03:00
|
|
|
package mpeg
|
|
|
|
|
|
|
|
// https://wiki.multimedia.cx/index.php/MPEG-4_Audio
|
|
|
|
|
|
|
|
import (
|
2021-08-17 13:06:32 +03:00
|
|
|
"github.com/wader/fq/format"
|
|
|
|
"github.com/wader/fq/format/registry"
|
|
|
|
"github.com/wader/fq/pkg/decode"
|
2020-06-08 03:29:51 +03:00
|
|
|
)
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
registry.MustRegister(&decode.Format{
|
|
|
|
Name: format.MPEG_ASC,
|
|
|
|
Description: "MPEG-4 Audio Specific Config",
|
|
|
|
DecodeFn: ascDecoder,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
var frequencyIndexHz = map[uint64]int{
|
|
|
|
0x0: 96000,
|
|
|
|
0x1: 88200,
|
|
|
|
0x2: 64000,
|
|
|
|
0x3: 48000,
|
|
|
|
0x4: 44100,
|
|
|
|
0x5: 32000,
|
|
|
|
0x6: 24000,
|
|
|
|
0x7: 22050,
|
|
|
|
0x8: 16000,
|
|
|
|
0x9: 12000,
|
|
|
|
0xa: 11025,
|
|
|
|
0xb: 8000,
|
|
|
|
0xc: 7350,
|
|
|
|
0xd: -1,
|
|
|
|
0xe: -1,
|
|
|
|
0xf: -1,
|
|
|
|
}
|
|
|
|
|
2021-11-05 17:04:26 +03:00
|
|
|
var channelConfigurationNames = decode.UToStr{
|
|
|
|
0: "defined in AOT Specifc Config",
|
|
|
|
1: "front-center",
|
|
|
|
2: "front-left, front-right",
|
|
|
|
3: "front-center, front-left, front-right",
|
|
|
|
4: "front-center, front-left, front-right, back-center",
|
|
|
|
5: "front-center, front-left, front-right, back-left, back-right",
|
|
|
|
6: "front-center, front-left, front-right, back-left, back-right, LFE-channel",
|
|
|
|
7: "front-center, front-left, front-right, side-left, side-right, back-left, back-right, LFE-channel",
|
2020-06-08 03:29:51 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
func ascDecoder(d *decode.D, in interface{}) interface{} {
|
2021-11-05 17:04:26 +03:00
|
|
|
objectType := d.FieldUFn("object_type", func(d *decode.D) uint64 {
|
2020-06-08 03:29:51 +03:00
|
|
|
n := d.U5()
|
|
|
|
if n == 31 {
|
|
|
|
n = 32 + d.U6()
|
|
|
|
}
|
|
|
|
return n
|
2021-11-17 18:13:10 +03:00
|
|
|
}, d.MapUToStrSym(format.MPEGAudioObjectTypeNames))
|
2021-11-05 17:04:26 +03:00
|
|
|
d.FieldUScalarFn("sampling_frequency", func(d *decode.D) decode.Scalar {
|
2020-06-08 03:29:51 +03:00
|
|
|
v := d.U4()
|
|
|
|
if v == 15 {
|
2021-11-05 17:04:26 +03:00
|
|
|
return decode.Scalar{Actual: d.U24()}
|
2020-06-08 03:29:51 +03:00
|
|
|
}
|
|
|
|
if f, ok := frequencyIndexHz[v]; ok {
|
2021-11-05 17:04:26 +03:00
|
|
|
return decode.Scalar{Actual: v, Sym: f}
|
2020-06-08 03:29:51 +03:00
|
|
|
}
|
2021-11-05 17:04:26 +03:00
|
|
|
return decode.Scalar{Description: "invalid"}
|
2020-06-08 03:29:51 +03:00
|
|
|
})
|
2021-11-17 18:13:10 +03:00
|
|
|
d.FieldU4("channel_configuration", d.MapUToStrSym(channelConfigurationNames))
|
2020-06-08 03:29:51 +03:00
|
|
|
// TODO: GASpecificConfig etc
|
2021-11-05 17:04:26 +03:00
|
|
|
d.FieldRawLen("var_aot_or_byte_align", d.BitsLeft())
|
2020-06-08 03:29:51 +03:00
|
|
|
|
|
|
|
return format.MPEGASCOut{ObjectType: int(objectType)}
|
|
|
|
}
|