Steve Ayerhart 2020-03-31 09:54:05 -05:00
parent c1db0336f2
commit a3e55c20c8
No known key found for this signature in database
GPG Key ID: 5BFD39C5359E967D
2 changed files with 50 additions and 9 deletions

View File

@ -140,9 +140,14 @@ ERROR: invalid-subframe-sync ;
} cond <flac-subframe-type> ;
: read-constant-subframe ( bps -- data )
8 / read ;
: read-constant-subframe ( subframe-header frame-header -- data )
>>bits-per-sample 8 / read swap drop ;
: read-fixed-subframe ( predictive-order -- subframe )
drop 9 ;
: read-lpc-subframe ( predictive-order -- subframe )
drop 9 ;
:: decode-subframe-header ( bitstream -- subframe )
1 bitstream read-bit 1 = [ invalid-subframe-sync ] when
@ -153,14 +158,16 @@ ERROR: invalid-subframe-sync ;
! TODO: actually decode based on subframe type
! TODO: handle wasted bits assuming 1 byte for now :/
: read-subframe ( frame-header -- subframe )
1 read bitstreams:<msb0-bit-reader> decode-subframe-header dup
[
1 read bitstreams:<msb0-bit-reader> decode-subframe-header dup
] dip swap
subframe-type>>
{
{ subframe-type-constant [ swap bits-per-sample>> read-constant-subframe ] }
{ subframe-type-verbatim [ drop "VERBATIM TODO" . B{ } ] }
{ subframe-type-fixed [ drop "FIXED TODO" . B{ } ] }
{ subframe-type-lpc [ drop "LPC TODO" . B{ } ] }
} case
{ subframe-type-constant [ "1" ] }
{ subframe-type-verbatim [ drop drop B{ } ] }
{ subframe-type-fixed [ drop drop B{ } ] }
{ subframe-type-lpc [ drop drop B{ } ] }
} case
flac-subframe boa ;
: read-subframes ( frame-header -- seq )
@ -178,7 +185,7 @@ ERROR: invalid-subframe-sync ;
read-frame-footer
flac-frame boa ;
: decode-file ( filename -- something )
: read-flac-file ( filename -- something )
binary
[
read-flac-magic [ not-a-flac-file ] unless

View File

@ -4,6 +4,20 @@ USING: alien.syntax math byte-arrays sequences ;
IN: flac.format
CONSTANT: MIN-BLOCK-SIZE 16
CONSTANT: MAX-BLOCK-SIZE 65535
CONSTANT: MAX-SAMPLE-SIZE: 4608
CONSTANT: MAX-CHANNELS 8
CONSTANT: MIN-BITS-PER-SAMPLE 4
CONSTANT: MAX-BITS-PER-SAMPLE 32 ! The value is ((2^16) - 1) * 10
CONSTANT: MAX-LPC-ORDER 32
CONSTANT: MAX-LPC-ORDER-48000HZ 12
CONSTANT: MIN-QLP-COEFF-PRECISION 5
CONSTANT: MAX-QLP-COEEF-PRECISION 15
CONSTANT: MAX-FIXED-ORDER 4
CONSTANT: MAX-RICE-PARTITION-ORDER 15
ENUM: flac-frame-number-type
frame-number-type-frame
frame-number-type-sample ;
@ -63,6 +77,26 @@ ENUM: flac-entropy-coding-method
entropy-coding-partioned-rice
entropy-coding-partioned-rice2 ;
TUPLE: partition
{ encoding-parameter integer }
{ partitions sequence } ;
TUPLE: residual
method
{ partition partition }
TUPLE: subframe-constant
{ value integer } ;
TUPLE: subframe-verbatim
{ data byte-array } ;
TUPLE: subframe-fixed
entropy-coding-method
{ order integer }
{ warmup integer }
residual ;
TUPLE: flac-frame-footer
{ crc integer } ;