A Couple of Recording Questions

An alternative script that provides statistics about the selected audio samples:

;type analyze
;debugflags trace

;control size "Number of samples to test" int "" 1000 1 1000000

(setf size (round (min size len)))

(defun bitcheck (s bits)
  ;;; Return T if "s" format is "bit" bits.
  (when (> (abs s) 1)
    (return-from bitcheck nil)) ;can only be float.
  ;; Round to ensure exact (integer) quantization steps.
  (setf s (* s (round (power 2 bits))))
  (if (= (- s (round s)) 0) t nil))

(defmacro norm (val)
  ;;; Normalize val to range 0 to 1.
  `(setf ,val (/ ,val (float size))))

(defun bitformat (8b 16b 24b)
  ;;; Returns the bit format as a string, based
  ;;; on the number of 8, 16 and 24-bit samples.
  (let ((8bit 8b)
        (16bit (+ 8b 16b))
        (24bit (+ 8b 16b 24b)))
    (norm 8bit)
    (norm 16bit)
    (norm 24bit)
    (cond ((= 8bit 1) "8-bit")
          ((= 16bit 1) "16-bit")
          ((= 24bit 1) "24-bit")
          (t "32-bit float"))))


(let ((8bit 0)
      (16bit 0)
      (24bit 0))
  (dotimes (i size)
    (setf samp (snd-fetch *track*))
    (if (bitcheck samp 8)
        (incf 8bit)
        (if (bitcheck samp 16)
            (incf 16bit)
            (if (bitcheck samp 24)
                (incf 24bit)))))
    (format nil "Results from ~a samples tested:~%~
                 Number of 8-bit samples: ~a~%~
                 Number of 16-bit samples: ~a~%~
                 Number of 24-bit samples: ~a~%~
                 Number of 32-bit float samples: ~a~%~%~
                 The selected audio is ~a format."
            size
            8bit
            16bit
            24bit
            (- size 8bit 16bit 24bit)
            (bitformat 8bit 16bit 24bit)))