write synchsafe numbers to sequences

db4
Doug Coleman 2009-04-09 18:23:05 -05:00
parent 47369e927c
commit d44c08bf68
2 changed files with 13 additions and 5 deletions

View File

@ -1,6 +1,7 @@
! Copyright (C) 2009 Tim Wawrzynczak
! See http://factorcode.org/license.txt for BSD license.
USING: tools.test id3 combinators ;
USING: tools.test id3 combinators grouping id3.private
sequences math ;
IN: id3.tests
: id3-params ( id3 -- title artist album year comment genre )
@ -40,3 +41,6 @@ IN: id3.tests
"Big Band"
] [ "vocab:id3/tests/blah3.mp3" mp3>id3 id3-params ] unit-test
[ t ]
[ 10000 [ synchsafe>seq seq>synchsafe ] map [ < ] monotonic? ] unit-test

View File

@ -6,7 +6,7 @@ combinators math.ranges unicode.categories byte-arrays
io.encodings.string io.encodings.utf16 assocs math.parser
combinators.short-circuit fry namespaces combinators.smart
splitting io.encodings.ascii arrays io.files.info unicode.case
io.directories.search literals ;
io.directories.search literals math.functions ;
IN: id3
<PRIVATE
@ -100,9 +100,13 @@ CONSTANT: id3v1+-offset $[ 128 227 + ]
} cleave
] output>array sift ;
: >28bitword ( seq -- int )
: seq>synchsafe ( seq -- n )
0 [ [ 7 shift ] dip bitor ] reduce ; inline
: synchsafe>seq ( n -- seq )
dup 1+ log2 1+ 7 / ceiling
[ [ -7 shift ] keep HEX: 7f bitand ] replicate nip reverse ; inline
: filter-text-data ( data -- filtered )
[ printable? ] filter ; inline
@ -121,7 +125,7 @@ CONSTANT: id3v1+-offset $[ 128 227 + ]
[ <frame> ] dip
{
[ 4 head-slice decode-text >>tag ]
[ [ 4 8 ] dip subseq >28bitword >>size ]
[ [ 4 8 ] dip subseq seq>synchsafe >>size ]
[ [ 8 10 ] dip subseq >byte-array >>flags ]
[ read-frame-data decode-text >>data ]
} cleave ; inline
@ -144,7 +148,7 @@ CONSTANT: id3v1+-offset $[ 128 227 + ]
{
[ [ 3 5 ] dip <slice> >array >>version ]
[ [ 5 ] dip nth >>flags ]
[ [ 6 10 ] dip <slice> >28bitword >>size ]
[ [ 6 10 ] dip <slice> seq>synchsafe >>size ]
} cleave ; inline
: merge-frames ( id3 assoc -- id3 )