2021-10-28 02:44:09 +03:00
package flac
import (
"github.com/wader/fq/format"
"github.com/wader/fq/pkg/decode"
2022-07-16 19:39:57 +03:00
"github.com/wader/fq/pkg/interp"
2021-12-02 00:48:25 +03:00
"github.com/wader/fq/pkg/scalar"
2021-10-28 02:44:09 +03:00
)
func init ( ) {
2022-07-16 19:39:57 +03:00
interp . RegisterFormat ( decode . Format {
2021-10-28 02:44:09 +03:00
Name : format . FLAC_STREAMINFO ,
Description : "FLAC streaminfo" ,
DecodeFn : streaminfoDecode ,
} )
}
2022-07-19 19:33:50 +03:00
func streaminfoDecode ( d * decode . D , _ any ) any {
2021-10-28 02:44:09 +03:00
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
2022-05-07 13:46:34 +03:00
d . FieldU3 ( "channels" , scalar . ActualUAdd ( 1 ) )
2021-10-28 02:44:09 +03:00
// <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.
2022-05-07 13:46:34 +03:00
bitsPerSample := d . FieldU5 ( "bits_per_sample" , scalar . ActualUAdd ( 1 ) )
2021-10-28 02:44:09 +03:00
totalSamplesInStream := d . FieldU ( "total_samples_in_stream" , 36 )
2022-01-24 23:21:48 +03:00
md5BR := d . FieldRawLen ( "md5" , 16 * 8 , scalar . RawHex )
2022-06-30 13:13:36 +03:00
md5b := d . ReadAllBits ( md5BR )
2021-10-28 02:44:09 +03:00
return format . FlacStreaminfoOut {
StreamInfo : format . FlacStreamInfo {
SampleRate : sampleRate ,
2021-12-09 19:15:21 +03:00
BitsPerSample : bitsPerSample ,
2021-10-28 02:44:09 +03:00
TotalSamplesInStream : totalSamplesInStream ,
2021-11-05 17:04:26 +03:00
MD5 : md5b ,
2021-10-28 02:44:09 +03:00
} ,
}
}