audio.loader vocab that reads audio file with reader appropriate to file extension
parent
0d57d0deb2
commit
303efda053
|
@ -1,7 +1,9 @@
|
|||
! (c)2009 Joe Groff bsd license
|
||||
USING: accessors alien alien.c-types alien.data audio
|
||||
audio.chunked-file classes.struct combinators
|
||||
combinators.short-circuit endian io io.binary
|
||||
io.encodings.binary io.files kernel locals math sequences ;
|
||||
io.encodings.binary io.files kernel locals math sequences
|
||||
audio.loader ;
|
||||
IN: audio.aiff
|
||||
|
||||
CONSTANT: FORM-MAGIC "FORM"
|
||||
|
@ -79,3 +81,6 @@ STRUCT: sound-data-chunk
|
|||
read-form-chunk verify-aiff (read-aiff)
|
||||
] with-file-reader
|
||||
] with-endianness ;
|
||||
|
||||
"aif" [ read-aiff ] register-audio-extension
|
||||
"aiff" [ read-aiff ] register-audio-extension
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
! (c)2009 Joe Groff bsd license
|
||||
USING: accessors alien.c-types combinators endian io kernel
|
||||
math sequences ;
|
||||
IN: audio.chunked-file
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
! (c)2009 Joe Groff bsd license
|
||||
USING: accessors alien audio classes.struct fry calendar alarms
|
||||
combinators combinators.short-circuit destructors generalizations
|
||||
kernel literals locals math openal sequences specialized-arrays strings ;
|
||||
|
|
Binary file not shown.
Binary file not shown.
|
@ -1,14 +1,14 @@
|
|||
USING: accessors alarms audio audio.engine audio.wav calendar
|
||||
! (c)2009 Joe Groff bsd license
|
||||
USING: accessors alarms audio audio.engine audio.loader calendar
|
||||
destructors io kernel locals math math.functions ;
|
||||
IN: audio.engine.test
|
||||
|
||||
USE: prettyprint
|
||||
:: audio-engine-test ( -- )
|
||||
"vocab:audio/engine/test/loop.wav" read-wav :> loop-sound
|
||||
"vocab:audio/engine/test/once.wav" read-wav :> once-sound
|
||||
"vocab:audio/engine/test/loop.aiff" read-audio :> loop-sound
|
||||
"vocab:audio/engine/test/once.wav" read-audio :> once-sound
|
||||
0 :> i!
|
||||
<standard-audio-engine> :> engine
|
||||
engine dup . start-audio*
|
||||
engine start-audio*
|
||||
engine loop-sound T{ audio-source f { 1.0 0.0 0.0 } 1.0 { 0.0 0.0 0.0 } f } t <audio-clip>
|
||||
:> loop-clip
|
||||
|
||||
|
|
|
@ -0,0 +1,20 @@
|
|||
! (c)2009 Joe Groff bsd license
|
||||
USING: ascii assocs io.pathnames kernel namespaces
|
||||
vocabs.loader ;
|
||||
IN: audio.loader
|
||||
|
||||
ERROR: unknown-audio-extension extension ;
|
||||
|
||||
SYMBOL: audio-types
|
||||
audio-types [ H{ } clone ] initialize
|
||||
|
||||
: register-audio-extension ( extension quot -- )
|
||||
swap audio-types get set-at ;
|
||||
|
||||
: read-audio ( path -- audio )
|
||||
dup file-extension >lower audio-types get ?at
|
||||
[ call( path -- audio ) ]
|
||||
[ unknown-audio-extension ] if ;
|
||||
|
||||
"audio.wav" require
|
||||
"audio.aiff" require
|
|
@ -1,8 +1,9 @@
|
|||
! (c)2009 Joe Groff bsd license
|
||||
USING: alien.c-types alien.syntax audio combinators endian
|
||||
combinators.short-circuit io io.binary io.encodings.binary
|
||||
io.files io.streams.byte-array kernel locals math
|
||||
sequences alien alien.data classes.struct accessors
|
||||
audio.chunked-file ;
|
||||
audio.chunked-file audio.loader ;
|
||||
IN: audio.wav
|
||||
|
||||
CONSTANT: RIFF-MAGIC "RIFF"
|
||||
|
@ -40,6 +41,7 @@ STRUCT: wav-data-chunk
|
|||
[ {
|
||||
{ [ dup FMT-MAGIC wav-fmt-chunk check-chunk ] [ wav-fmt-chunk memory>struct fmt! ] }
|
||||
{ [ dup DATA-MAGIC wav-data-chunk check-chunk ] [ wav-data-chunk memory>struct data! ] }
|
||||
[ drop ]
|
||||
} cond ] while drop
|
||||
fmt data 2dup and [ invalid-audio-file ] unless ;
|
||||
|
||||
|
@ -68,3 +70,5 @@ STRUCT: wav-data-chunk
|
|||
read-riff-chunk verify-wav (read-wav)
|
||||
] with-file-reader
|
||||
] with-endianness ;
|
||||
|
||||
"wav" [ read-wav ] register-audio-extension
|
||||
|
|
Loading…
Reference in New Issue