فهرست منبع

various tests, cleanup

Mark VandenBrink 12 سال پیش
والد
کامیت
a184cda006
3فایلهای تغییر یافته به همراه27 افزوده شده و 17 حذف شده
  1. 14 6
      audio-streams.lisp
  2. 4 2
      packages.lisp
  3. 9 9
      taglib-tests.lisp

+ 14 - 6
audio-streams.lisp

@@ -87,12 +87,20 @@ As a convenience, OFFSET and FROM are optional, so (STREAM-SEEK stream) returns
                finally (return-from read-n-bytes value))))))
     nil)
 
-(defmethod stream-read-u8   ((stream mem-stream) &key (bits-per-byte 8))                         (read-n-bytes stream 1  :bits-per-byte bits-per-byte))
-(defmethod stream-read-u16  ((stream mem-stream) &key (bits-per-byte 8) (endian :little-endian)) (read-n-bytes stream 2  :bits-per-byte bits-per-byte :endian endian))
-(defmethod stream-read-u24  ((stream mem-stream) &key (bits-per-byte 8) (endian :little-endian)) (read-n-bytes stream 3  :bits-per-byte bits-per-byte :endian endian))
-(defmethod stream-read-u32  ((stream mem-stream) &key (bits-per-byte 8) (endian :little-endian)) (read-n-bytes stream 4  :bits-per-byte bits-per-byte :endian endian))
-(defmethod stream-read-u64  ((stream mem-stream) &key (bits-per-byte 8) (endian :little-endian)) (read-n-bytes stream 8  :bits-per-byte bits-per-byte :endian endian))
-(defmethod stream-read-u128 ((stream mem-stream) &key (bits-per-byte 8) (endian :little-endian)) (read-n-bytes stream 16 :bits-per-byte bits-per-byte :endian endian))
+(defun stream-read-u8 (stream)
+  (declare #.utils:*standard-optimize-settings*)
+  (with-mem-stream-slots (stream)
+    (if (<= (+ index 1) stream-size)
+        (let ((val (aref vect index)))
+          (incf index)
+          val)
+        nil)))
+
+(defun stream-read-u16  (stream &key (bits-per-byte 8) (endian :little-endian)) (read-n-bytes stream 2  :bits-per-byte bits-per-byte :endian endian))
+(defun stream-read-u24  (stream &key (bits-per-byte 8) (endian :little-endian)) (read-n-bytes stream 3  :bits-per-byte bits-per-byte :endian endian))
+(defun stream-read-u32  (stream &key (bits-per-byte 8) (endian :little-endian)) (read-n-bytes stream 4  :bits-per-byte bits-per-byte :endian endian))
+(defun stream-read-u64  (stream &key (bits-per-byte 8) (endian :little-endian)) (read-n-bytes stream 8  :bits-per-byte bits-per-byte :endian endian))
+(defun stream-read-u128 (stream &key (bits-per-byte 8) (endian :little-endian)) (read-n-bytes stream 16 :bits-per-byte bits-per-byte :endian endian))
 
 (defmethod stream-read-sequence ((stream mem-stream) size &key (bits-per-byte 8))
   "Read in a sequence of octets at BITS-PER-BYTE.  If BITS-PER-BYTE == 8, then simply return

+ 4 - 2
packages.lisp

@@ -3,8 +3,10 @@
 (in-package #:cl-user)
 
 (defpackage #:utils
-  (:export #:warn-user *break-on-warn-user* #:printable-array #:upto-null #:redirect #:memoize
-           #:it #:*standard-optimize-settings* #:get-bitfield #:while #:aif #:awhen #:with-gensyms #:make-keyword #:dump-data)
+  (:export #:warn-user *break-on-warn-user* #:printable-array #:upto-null
+           #:redirect #:memoize #:it #:*standard-optimize-settings*
+           #:get-bitfield #:while #:aif #:awhen #:with-gensyms #:make-keyword
+           #:dump-data #:timings)
   (:use #:common-lisp))
 
 (defpackage #:profile

+ 9 - 9
taglib-tests.lisp

@@ -65,8 +65,8 @@
     (time (do-audio-dir dir :file-system-encoding file-system-encoding :func nil))))
 
 ;;;;;;;;;;;;;;;;;;;; multi-thread code below ;;;;;;;;;;;;;;;;;;;;
-(defparameter *END-THREAD*  #xdeadbeef)
-(defparameter *MAX-THREADS* 4)
+(defparameter *end-thread*  #xdeadbeef)
+(defparameter *max-threads* 4)
 
 ;;; Simple structure to hold a thread's results
 (defstruct chanl-results
@@ -99,7 +99,7 @@
                    (with-slots (name mp3-count mp4-count flac-count other-count) results
                      (setf f (chanl:recv channel))
                      (when (and (typep f 'integer)
-                                (= f *END-THREAD*))
+                                (= f *end-thread*))
                        (chanl:send dead-channel results) ; send structure of stats back to parent
                        (return-from thread-reader nil))
 
@@ -116,9 +116,9 @@
       ;; At this point, CHANNEL is stuffed with files.
       ;; Now, send *MAX-THREADS* "ends" (at end of CHANNEL) and
       ;; spawn *MAX-THREADS* threads
-      (dotimes (i *MAX-THREADS*)
-        (chanl:send channel *END-THREAD*))
-      (dotimes (i *MAX-THREADS*)
+      (dotimes (i *max-threads*)
+        (chanl:send channel *end-thread*))
+      (dotimes (i *max-threads*)
         (chanl:pcall #'thread-reader :initial-bindings `((*me* ,(format nil "reader-thread-~d" i)))))
 
       ;; sit in loop until we read *MAX-THREADS* results
@@ -126,7 +126,7 @@
         (let ((i 0)
               results)
 
-          (format t "Waiting on ~d threads~%" *MAX-THREADS*)
+          (format t "Waiting on ~d threads~%" *max-threads*)
           (loop
             (force-output *standard-output*)
             (setf results (chanl:recv dead-channel))
@@ -144,8 +144,8 @@
             (incf other-count (chanl-results-other-count results))
             (incf i)
 
-            (when (= i *MAX-THREADS*)
-              (return-from thread-reap *MAX-THREADS*)))))
+            (when (= i *max-threads*)
+              (return-from thread-reap *max-threads*)))))
 
       (format t "All threads done~%")
       (format t "~&~:d MP3s, ~:d MP4s, ~:d FLACS, ~:d Others, for a total of ~:d files~%"