[CM] [sdif] Re: SDIF/lisp question
Matt Wright
matt at cnmat.berkeley.edu
Wed Apr 2 09:23:39 PDT 2008
Keep in mind that Lisp's use of the word "stream" doesn't mean the
same thing as an "SDIF stream" (which is also not the same as
"streaming an SDIF file over the Internet").
-Matt
On Apr 2, 2008, at 8:45 AM, Ralf Mattes wrote:
> On Wed, 2008-04-02 at 12:15 -0300, padovani wrote:
>> Hi...
>> I'm trying to deal with sdif files with common lisp functions and, as
>> composer who tries to deal with code, I have a question that migth be
>> stupid...
>>
>> The file that I want to deal begins with these HEX (SDIF header),
>> that
>> I could read with a standard Hex editor:
>>
>> 53 44 49 46 00 00 00 08 00 00 00 03 00 00 00 01
>> 31 4e 56 54 00 00 00 78 ff ef ff ff ff ff ff ff
>> 00 00 00 00 00 00 00 01 31 4e 56 54 00 00 03 01
>> 00 00 00 57 00 00 00 01 .....
>>
>> So, I tried to open it on a stream
>>
>> (setq in-stream (open "mongombi.trc.sdif" :direction :input))
>>
>> worked.
>> Then I tried to spell the bytes...
>>
>> (read-byte in-stream)
>>
>> and read the bytes... And got:
>>
>>>>> Error: #<SB-SYS:FD-STREAM for "file
>> /Users/ze/Documents/documentos/meus/codigos/grace/sdifnovo/
>> mongombi.trc.sdif"
>> {12B08011}> is not a binary input stream.
>>
>> so I tried with (read-char ...) as the first bytes represent "SDIF"
>> chars and then I could spell the first 24 bytes:
>>
>> (read-char in-stream)
>> #\S
>> #\D
>> #\I
>> #\F
>> #\Nul
>> #\Nul
>> #\Nul
>> #\Backspace
>> #\Nul
>> #\Nul
>> #\Nul
>> #\Etx
>> #\Nul
>> #\Nul
>> #\Nul
>> #\Soh
>> #\1
>> #\N
>> #\V
>> #\T
>> #\Nul
>> #\Nul
>> #\Nul
>> #\x
>>
>> But when I try to spell the 25th byte, I get:
>>>>> Error: decoding error on stream
>> #<SB-SYS:FD-STREAM for "file
>> /Users/ze/Documents/documentos/meus/codigos/grace/sdifnovo/
>> mongombi.trc.sdif"
>> {116A67B1}>
>> (:EXTERNAL-FORMAT :UTF-8):
>> the octet sequence (255 239 255 255) cannot be decoded.
>>
>> This is the "ff ef ff ff ff ff ff ff" part of the HEX
>> transcription of
>> the file...
>> It seems I'm not getting something related to streams, but really
>> can't
>> understand...
>>
>> If anyone can give some ligth sbout how to deal with this on
>> common-lisp
>> or how to use the sdif library in common lisp it wold be really
>> nice...
>> Thanks,
>
> You need to fresh up your LISP: streams have an associated element-
> type.
> If you want/need to read bytes you need to open the file as follows:
>
> (setq in-stream (open "mongombi.trc.sdif"
> :direction :input
> :element-type 'unsigned-byte))
>
> Then 'read-byte' should work. If you don't specify the element type it
> will default to character or base-character. As a result your Lisp of
> choice will try to read characters in the default external format
> (another possible keyword parameter to open), which in your case seems
> to be utf-8 (which is _not_ a single byte encoding!). This will
> fail as
> soon as the file contains an invalid utf-8 byte sequence.
>
> HTH Ralf Mattes
>
> P.S.: I strongly suggest using 'with-open-file' instead of direct
> 'open/close' calls.
>
>>
>> José H. Padovani
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>> _______________________________________________
>> Cmdist mailing list
>> Cmdist at ccrma.stanford.edu
>> http://ccrma-mail.stanford.edu/mailman/listinfo/cmdist
>
More information about the Cmdist
mailing list