wip
							parent
							
								
									c1db0336f2
								
							
						
					
					
						commit
						a3e55c20c8
					
				| 
						 | 
					@ -140,9 +140,14 @@ ERROR: invalid-subframe-sync ;
 | 
				
			||||||
    } cond <flac-subframe-type> ;
 | 
					    } cond <flac-subframe-type> ;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
: read-constant-subframe ( bps -- data )
 | 
					: read-constant-subframe ( subframe-header frame-header -- data )
 | 
				
			||||||
    8 / read ;
 | 
					    >>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 )
 | 
					:: decode-subframe-header ( bitstream -- subframe )
 | 
				
			||||||
    1 bitstream read-bit 1 = [ invalid-subframe-sync ] when
 | 
					    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: actually decode based on subframe type
 | 
				
			||||||
! TODO: handle wasted bits assuming 1 byte for now :/
 | 
					! TODO: handle wasted bits assuming 1 byte for now :/
 | 
				
			||||||
: read-subframe ( frame-header -- subframe )
 | 
					: 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>>
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        { subframe-type-constant [ swap bits-per-sample>> read-constant-subframe ] }
 | 
					        { subframe-type-constant [ "1" ] }
 | 
				
			||||||
        { subframe-type-verbatim [ drop "VERBATIM TODO" . B{ } ] }
 | 
					        { subframe-type-verbatim [ drop drop B{ } ] }
 | 
				
			||||||
        { subframe-type-fixed [ drop "FIXED TODO" . B{ } ] }
 | 
					        { subframe-type-fixed [ drop drop B{ } ] }
 | 
				
			||||||
        { subframe-type-lpc [ drop "LPC TODO" . B{ } ] }
 | 
					        { subframe-type-lpc [ drop drop B{ } ] }
 | 
				
			||||||
    } case 
 | 
					    } case
 | 
				
			||||||
    flac-subframe boa ;
 | 
					    flac-subframe boa ;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
: read-subframes ( frame-header -- seq )
 | 
					: read-subframes ( frame-header -- seq )
 | 
				
			||||||
| 
						 | 
					@ -178,7 +185,7 @@ ERROR: invalid-subframe-sync ;
 | 
				
			||||||
    read-frame-footer
 | 
					    read-frame-footer
 | 
				
			||||||
    flac-frame boa ;
 | 
					    flac-frame boa ;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
: decode-file ( filename -- something )
 | 
					: read-flac-file ( filename -- something )
 | 
				
			||||||
    binary
 | 
					    binary
 | 
				
			||||||
    [
 | 
					    [
 | 
				
			||||||
        read-flac-magic [ not-a-flac-file ] unless
 | 
					        read-flac-magic [ not-a-flac-file ] unless
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -4,6 +4,20 @@ USING: alien.syntax math byte-arrays sequences ;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
IN: flac.format
 | 
					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
 | 
					ENUM: flac-frame-number-type
 | 
				
			||||||
    frame-number-type-frame
 | 
					    frame-number-type-frame
 | 
				
			||||||
    frame-number-type-sample ;
 | 
					    frame-number-type-sample ;
 | 
				
			||||||
| 
						 | 
					@ -63,6 +77,26 @@ ENUM: flac-entropy-coding-method
 | 
				
			||||||
    entropy-coding-partioned-rice
 | 
					    entropy-coding-partioned-rice
 | 
				
			||||||
    entropy-coding-partioned-rice2 ;
 | 
					    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
 | 
					TUPLE: flac-frame-footer
 | 
				
			||||||
    { crc integer } ;
 | 
					    { crc integer } ;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue