Skip to content

Commit

Permalink
moschatels (ints)
Browse files Browse the repository at this point in the history
  • Loading branch information
zzkt committed Jan 2, 2024
1 parent 5c7ed79 commit f647738
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 17 deletions.
33 changes: 20 additions & 13 deletions osc-tests.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,18 @@
(is (equalp
(osc::encode-int32 16843009) #(1 1 1 1)))
(is (equalp
(osc::decode-int32 #(1 1 11 111)) 16845679))
(osc::decode-int32 #(127 255 255 255))
(osc::decode-uint32 #(127 255 255 255))))
(is (equalp
(osc::encode-int32 -16843010) #(254 254 254 254)))
(is (equalp
(osc::decode-int32 #(255 255 255 255)) -1)))
(osc::decode-int32 #(127 255 255 255)) #x7FFFFFFF))
(is (equalp
(osc::encode-int32 #xFFFFFFFF) #(255 255 255 255)))
(is (equalp
(osc::decode-int32 #(255 255 255 255)) -1))
(is (equalp
(osc::decode-uint32 #(255 255 255 255)) #xFFFFFFFF)))

(test osc-string
"OSC string encoding tests."
Expand Down Expand Up @@ -113,9 +120,9 @@
(is (equalp
(osc::decode-float64 #(64 55 25 153 153 153 153 154)) 23.1d0))
(is (equalp
(osc::decode-float64 #(1 1 1 1 1 1 1 1)) 7.748604185489348d-304))
(osc::decode-float64 #(1 1 1 1 1 1 1 1)) 7.748604185489348d-304))
(is (equalp
(osc::decode-float64 #(128 0 0 0 0 0 0 0)) -0.0d0))
(osc::decode-float64 #(128 0 0 0 0 0 0 0)) -0.0d0))
(is (equalp
(osc::decode-float64 #(255 240 0 0 0 0 0 0))
:NEGATIVE-INFINITY))
Expand Down Expand Up @@ -327,15 +334,15 @@
(test v1.1-required-data-types
"OSC data encoding test. All required types for v1.1"
(is (equalp
#(44 105 104 115 102 100 98 0)
(osc::encode-typetags '(3
4294967297
"test"
2.1e2
2.1d23
#(1 2 3 4)
;; (osc::encode-timetag :now)
)))))
#(44 105 104 115 102 100 98 0)
(osc::encode-typetags '(3
4294967297
"test"
2.1e2
2.1d23
#(1 2 3 4)
;; (osc::encode-timetag :now)
)))))

(test v1.1-keyword-typetags
"OSC typetag encoding test."
Expand Down
8 changes: 4 additions & 4 deletions osc.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -325,15 +325,15 @@
(defun decode-int32 (s)
"4 byte -> 32 bit int -> two's complement (in network byte order)"
(let ((i (decode-uint32 s)))
(if (>= i #.(1- (expt 2 31)))
(- (- #.(expt 2 32) i))
(if (>= i (expt 2 31))
(- (- (expt 2 32) i))
i)))

(defun decode-int64 (s)
"8 byte -> 64 bit int -> two's complement (in network byte order)"
(let ((i (decode-uint64 s)))
(if (>= i #.(1- (expt 2 63)))
(- (- #.(expt 2 64) i))
(if (>= i (expt 2 63))
(- (- (expt 2 64) i))
i)))

;; floats are encoded using ieee-floats library for brevity and compatibility
Expand Down

0 comments on commit f647738

Please sign in to comment.