-
Notifications
You must be signed in to change notification settings - Fork 227
/
flac_streaminfo.go
41 lines (37 loc) · 1.24 KB
/
flac_streaminfo.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package flac
import (
"github.com/wader/fq/format"
"github.com/wader/fq/pkg/decode"
"github.com/wader/fq/pkg/interp"
"github.com/wader/fq/pkg/scalar"
)
func init() {
interp.RegisterFormat(
format.FLAC_Streaminfo,
&decode.Format{
Description: "FLAC streaminfo",
DecodeFn: streaminfoDecode,
})
}
func streaminfoDecode(d *decode.D) any {
d.FieldU16("minimum_block_size")
d.FieldU16("maximum_block_size")
d.FieldU24("minimum_frame_size")
d.FieldU24("maximum_frame_size")
sampleRate := d.FieldU("sample_rate", 20)
// <3> (number of channels)-1. FLAC supports from 1 to 8 channels
d.FieldU3("channels", scalar.UintActualAdd(1))
// <5> (bits per sample)-1. FLAC supports from 4 to 32 bits per sample. Currently the reference encoder and decoders only support up to 24 bits per sample.
bitsPerSample := d.FieldU5("bits_per_sample", scalar.UintActualAdd(1))
totalSamplesInStream := d.FieldU("total_samples_in_stream", 36)
md5BR := d.FieldRawLen("md5", 16*8, scalar.RawHex)
md5b := d.ReadAllBits(md5BR)
return format.FLAC_Streaminfo_Out{
StreamInfo: format.FLAC_Stream_Info{
SampleRate: sampleRate,
BitsPerSample: bitsPerSample,
TotalSamplesInStream: totalSamplesInStream,
MD5: md5b,
},
}
}