Move file-contents word to core/io/io.factor
parent
8eff6af322
commit
41fa14010d
|
@ -1,8 +1,8 @@
|
||||||
! Copyright (C) 2003, 2007 Slava Pestov.
|
! Copyright (C) 2003, 2007 Slava Pestov.
|
||||||
! See http://factorcode.org/license.txt for BSD license.
|
! See http://factorcode.org/license.txt for BSD license.
|
||||||
|
USING: hashtables generic kernel math namespaces sequences strings
|
||||||
|
continuations assocs io.files io.styles sbufs ;
|
||||||
IN: io
|
IN: io
|
||||||
USING: hashtables generic kernel math namespaces
|
|
||||||
sequences strings continuations assocs io.styles sbufs ;
|
|
||||||
|
|
||||||
GENERIC: stream-close ( stream -- )
|
GENERIC: stream-close ( stream -- )
|
||||||
GENERIC: set-timeout ( n stream -- )
|
GENERIC: set-timeout ( n stream -- )
|
||||||
|
@ -90,3 +90,6 @@ SYMBOL: stdio
|
||||||
|
|
||||||
: contents ( stream -- str )
|
: contents ( stream -- str )
|
||||||
2048 <sbuf> [ stream-copy ] keep >string ;
|
2048 <sbuf> [ stream-copy ] keep >string ;
|
||||||
|
|
||||||
|
: file-contents ( path -- str )
|
||||||
|
dup <file-reader> swap file-length <sbuf> [ stream-copy ] keep >string ;
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
! Copyright (C) 2007 Adam Wendt.
|
! Copyright (C) 2007 Adam Wendt.
|
||||||
! See http://factorcode.org/license.txt for BSD license.
|
! See http://factorcode.org/license.txt for BSD license.
|
||||||
!
|
USING: alien alien.c-types byte-arrays io io.binary io.files kernel mad
|
||||||
USING: alien alien.c-types byte-arrays io io.binary io.files kernel mad namespaces prettyprint sbufs sequences tools.interpreter vars ;
|
namespaces prettyprint sbufs sequences tools.interpreter vars ;
|
||||||
IN: mad.api
|
IN: mad.api
|
||||||
|
|
||||||
VARS: buffer-start buffer-length output-callback-var ;
|
VARS: buffer-start buffer-length output-callback-var ;
|
||||||
|
@ -16,27 +16,27 @@ VARS: buffer-start buffer-length output-callback-var ;
|
||||||
{ "void*" "mad_header*" } create-mad-callback-generic ; inline
|
{ "void*" "mad_header*" } create-mad-callback-generic ; inline
|
||||||
|
|
||||||
: create-filter-callback ( sequence -- alien )
|
: create-filter-callback ( sequence -- alien )
|
||||||
{ "void*" "mad_stream*" "mad_frame*" } create-mad-callback-generic ; inline
|
{ "void*" "mad_stream*" "mad_frame*" } create-mad-callback-generic ; inline
|
||||||
|
|
||||||
: create-output-callback ( sequence -- alien )
|
: create-output-callback ( sequence -- alien )
|
||||||
{ "void*" "mad_header*" "mad_pcm*" } create-mad-callback-generic ; inline
|
{ "void*" "mad_header*" "mad_pcm*" } create-mad-callback-generic ; inline
|
||||||
|
|
||||||
: create-error-callback ( sequence -- alien )
|
: create-error-callback ( sequence -- alien )
|
||||||
{ "void*" "mad_stream*" "mad_frame*" } create-mad-callback-generic ; inline
|
{ "void*" "mad_stream*" "mad_frame*" } create-mad-callback-generic ; inline
|
||||||
|
|
||||||
: create-message-callback ( sequence -- alien )
|
: create-message-callback ( sequence -- alien )
|
||||||
{ "void*" "void*" "uint*" } create-mad-callback-generic ; inline
|
{ "void*" "void*" "uint*" } create-mad-callback-generic ; inline
|
||||||
|
|
||||||
: input ( buffer mad_stream -- mad_flow )
|
: input ( buffer mad_stream -- mad_flow )
|
||||||
"input" print flush
|
"input" print flush
|
||||||
nip ! mad_stream
|
nip ! mad_stream
|
||||||
buffer-start get ! mad_stream start
|
buffer-start get ! mad_stream start
|
||||||
buffer-length get ! mad_stream start length
|
buffer-length get ! mad_stream start length
|
||||||
dup 0 = ! mad-stream start length bool
|
dup 0 = ! mad-stream start length bool
|
||||||
[ 3drop MAD_FLOW_STOP ] ! mad_flow
|
[ 3drop MAD_FLOW_STOP ] ! mad_flow
|
||||||
[ mad_stream_buffer !
|
[ mad_stream_buffer !
|
||||||
0 buffer-length set !
|
0 buffer-length set !
|
||||||
MAD_FLOW_CONTINUE ] if ; ! mad_flow
|
MAD_FLOW_CONTINUE ] if ; ! mad_flow
|
||||||
|
|
||||||
: input-callback ( -- callback )
|
: input-callback ( -- callback )
|
||||||
[ input ] create-input-callback ;
|
[ input ] create-input-callback ;
|
||||||
|
@ -46,11 +46,11 @@ VARS: buffer-start buffer-length output-callback-var ;
|
||||||
|
|
||||||
: filter-callback ( -- callback )
|
: filter-callback ( -- callback )
|
||||||
[ "filter" print flush 3drop MAD_FLOW_CONTINUE ] create-filter-callback ;
|
[ "filter" print flush 3drop MAD_FLOW_CONTINUE ] create-filter-callback ;
|
||||||
|
|
||||||
: write-sample ( sample -- )
|
|
||||||
4 >le write ;
|
|
||||||
|
|
||||||
: output ( data header pcm -- mad_flow )
|
: write-sample ( sample -- )
|
||||||
|
4 >le write ;
|
||||||
|
|
||||||
|
: output ( data header pcm -- mad_flow )
|
||||||
"output" . flush
|
"output" . flush
|
||||||
-rot 2drop output-callback-var> call
|
-rot 2drop output-callback-var> call
|
||||||
[ MAD_FLOW_CONTINUE ] [ MAD_FLOW_STOP ] if ;
|
[ MAD_FLOW_CONTINUE ] [ MAD_FLOW_STOP ] if ;
|
||||||
|
@ -80,11 +80,8 @@ VARS: buffer-start buffer-length output-callback-var ;
|
||||||
: make-decoder ( -- decoder )
|
: make-decoder ( -- decoder )
|
||||||
"mad_decoder" malloc-object ;
|
"mad_decoder" malloc-object ;
|
||||||
|
|
||||||
: file-contents ( path -- string )
|
|
||||||
dup <file-reader> swap file-length <sbuf> [ stream-copy ] keep >byte-array ;
|
|
||||||
|
|
||||||
: malloc-file-contents ( path -- alien )
|
: malloc-file-contents ( path -- alien )
|
||||||
file-contents malloc-byte-array ;
|
file-contents >byte-array malloc-byte-array ;
|
||||||
|
|
||||||
: mad-run ( -- int )
|
: mad-run ( -- int )
|
||||||
make-decoder [ mad-init ] keep MAD_DECODER_MODE_SYNC mad_decoder_run ;
|
make-decoder [ mad-init ] keep MAD_DECODER_MODE_SYNC mad_decoder_run ;
|
||||||
|
@ -98,4 +95,3 @@ VARS: buffer-start buffer-length output-callback-var ;
|
||||||
: mad-test ( -- results )
|
: mad-test ( -- results )
|
||||||
[ output-stdout ] >output-callback-var
|
[ output-stdout ] >output-callback-var
|
||||||
"/home/adam/download/mp3/Misc/wutbf.mp3" decode-mp3 ;
|
"/home/adam/download/mp3/Misc/wutbf.mp3" decode-mp3 ;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue