2021-10-28 02:44:09 +03:00
package flac
import (
"github.com/wader/fq/format"
"github.com/wader/fq/format/registry"
"github.com/wader/fq/pkg/decode"
)
func init ( ) {
2021-11-17 18:46:10 +03:00
registry . MustRegister ( decode . Format {
2021-10-28 02:44:09 +03:00
Name : format . FLAC_STREAMINFO ,
Description : "FLAC streaminfo" ,
DecodeFn : streaminfoDecode ,
} )
}
func streaminfoDecode ( d * decode . D , in interface { } ) interface { } {
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
2021-11-05 17:04:26 +03:00
d . FieldU3 ( "channels" , d . UAdd ( 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.
2021-11-05 17:04:26 +03:00
bitPerSample := d . FieldU5 ( "bits_per_sample" , d . UAdd ( 1 ) )
2021-10-28 02:44:09 +03:00
totalSamplesInStream := d . FieldU ( "total_samples_in_stream" , 36 )
2021-11-05 17:04:26 +03:00
md5BB := d . FieldRawLen ( "md5" , 16 * 8 , d . RawHex )
md5b , err := md5BB . Bytes ( )
if err != nil {
2021-11-24 23:20:46 +03:00
d . IOPanic ( err , "md5BB.Bytes" )
2021-11-05 17:04:26 +03:00
}
2021-10-28 02:44:09 +03:00
return format . FlacStreaminfoOut {
StreamInfo : format . FlacStreamInfo {
SampleRate : sampleRate ,
BitPerSample : bitPerSample ,
TotalSamplesInStream : totalSamplesInStream ,
2021-11-05 17:04:26 +03:00
MD5 : md5b ,
2021-10-28 02:44:09 +03:00
} ,
}
}